Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Add new bls operators and an operator compatibility mode #180

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ad2e7d
Add new bls operators and an operator compatibility mode that ensures…
prozacchiwawa Jun 6, 2023
2accda3
fmt
prozacchiwawa Jun 6, 2023
2f68498
Clippy
prozacchiwawa Jun 6, 2023
bc3a2a2
upgrade specification of clvmr in wasm
prozacchiwawa Jun 6, 2023
c3a007d
Add first bls test
prozacchiwawa Jun 6, 2023
a23b30e
Test bls operator in modern
prozacchiwawa Jun 6, 2023
80497f2
fmt
prozacchiwawa Jun 6, 2023
1e0a14f
bls tests
prozacchiwawa Jun 7, 2023
8a31679
fmt
prozacchiwawa Jun 7, 2023
e35d2f4
opps, pull in the right test programs
prozacchiwawa Jun 7, 2023
9eeceb3
Add a repl test that uses the operator literal syntax and softfork
prozacchiwawa Jun 7, 2023
ffe2884
remove some unused stuff
prozacchiwawa Jun 8, 2023
5c753ff
Fix up
prozacchiwawa Jun 8, 2023
cda115b
Add some more smoke tests of things that changed during the clvmr api…
prozacchiwawa Jun 27, 2023
c24da07
fmt + clippy
prozacchiwawa Jun 27, 2023
c28a5da
secp requires a rust upgrade, try specifying 1.65
prozacchiwawa Jun 27, 2023
6c67b72
It appears manylinux2010 is not used anymore and rust requires a newe…
prozacchiwawa Jun 27, 2023
3502781
Pull in wasm-pack update
prozacchiwawa Jun 27, 2023
68822dd
Merge up clvmr upgrade
prozacchiwawa Jul 28, 2023
c46a8ed
use operators_latest_version, improve wording
prozacchiwawa Jul 28, 2023
cb3ebe3
inc_node -> include_keyword_node
prozacchiwawa Jul 28, 2023
a4281fd
fmt + clippy
prozacchiwawa Jul 28, 2023
552edfa
Document OPERATORS_LATEST_VERSION
prozacchiwawa Jul 28, 2023
cfeddb1
Merge base
prozacchiwawa Aug 2, 2023
dd7c885
Route in the user's choice for operators extension when compiling code
prozacchiwawa Aug 2, 2023
4f920b7
fmt + clippy
prozacchiwawa Aug 2, 2023
d87b380
merge up + fmt + clippy
prozacchiwawa Aug 3, 2023
99b4ead
Add tests that exercise operator choice in classic run
prozacchiwawa Aug 4, 2023
5b69310
fmt
prozacchiwawa Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions resources/tests/bls/classic-bls-op-test-1.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(mod ()
(defconstant msg 0x9790635de8740e9a6a6b15fb6b72f3a16afa0973d971979b6ba54761d6e2502c50db76f4d26143f05459a42cfd520d44)

(g1_map msg)
)
8 changes: 8 additions & 0 deletions resources/tests/bls/classic-bls-verify-signature.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(mod (message)
(defconstant pk_bytes 0x86243290bbcbfd9ae75bdece7981965350208eb5e99b04d5cd24e955ada961f8c0a162dee740be7bdc6c3c0613ba2eb1)
(defconstant signature_bytes 0xb00ab9a8af54804b43067531d96c176710c05980fccf8eee1ae12a4fd543df929cce860273af931fe4fdbc407d495f73114ab7d17ef08922e56625daada0497582340ecde841a9e997f2f557653c21c070119662dd2efa47e2d6c5e2de00eefa)

;; Seems like bls_verify should do it
;; G2 G1 msg
(bls_verify signature_bytes pk_bytes message)
)
5 changes: 5 additions & 0 deletions resources/tests/bls/coinid-fail.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(mod ()
(include *standard-cl-21*)

(softfork (q . 1432) (q . 0) (q a (i (= (#coinid (q . 0x1234500000000000000000000000000000000000000000000000000000000000) (q . 0x6789abcdef000000000000000000000000000000000000000000000000000000) (q . 123456789)) (q . 0x69bfe81b052bfc6bd7f3fb9167fec61793175b897c16a35827f947d5cc98e4bc)) (q x) (q . 0)) (q . ())) (q . ()))
)
5 changes: 5 additions & 0 deletions resources/tests/bls/coinid-good.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(mod ()
(include *standard-cl-21*)

(softfork (q . 1432) (q . 0) (q a (i (= (#coinid (q . 0x1234500000000000000000000000000000000000000000000000000000000000) (q . 0x6789abcdef000000000000000000000000000000000000000000000000000000) (q . 123456789)) (q . 0x69bfe81b052bfc6bd7f3fb9167fec61793175b897c16a35827f947d5cc98e4bc)) (q . 0) (q x)) (q . ())) (q . ()))
)
6 changes: 6 additions & 0 deletions resources/tests/bls/modern-bls-op-test-1.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(mod ()
(include *standard-cl-21*)
(defconstant msg 0x9790635de8740e9a6a6b15fb6b72f3a16afa0973d971979b6ba54761d6e2502c50db76f4d26143f05459a42cfd520d44)

(g1_map msg)
)
9 changes: 9 additions & 0 deletions resources/tests/bls/modern-bls-verify-signature.clsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(mod (message)
(include *standard-cl-21*)
(defconstant pk_bytes 0x86243290bbcbfd9ae75bdece7981965350208eb5e99b04d5cd24e955ada961f8c0a162dee740be7bdc6c3c0613ba2eb1)
(defconstant signature_bytes 0xb00ab9a8af54804b43067531d96c176710c05980fccf8eee1ae12a4fd543df929cce860273af931fe4fdbc407d495f73114ab7d17ef08922e56625daada0497582340ecde841a9e997f2f557653c21c070119662dd2efa47e2d6c5e2de00eefa)

;; Seems like bls_verify should do it
;; G2 G1 msg
(bls_verify signature_bytes pk_bytes message)
)
2 changes: 1 addition & 1 deletion src/classic/clvm/casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct TConvertOption {
}

pub fn int_from_bytes(
allocator: &mut Allocator,
allocator: &Allocator,
b: Bytes,
option: Option<TConvertOption>,
) -> Result<u64, EvalErr> {
Expand Down
281 changes: 236 additions & 45 deletions src/classic/clvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,103 +8,294 @@ pub mod serialize;
pub mod sexp;
pub mod syntax_error;

/// This specifies the latest "version" of the operator set. This will increase
/// each time a new set of operators is included in the primitive set in clvm.
/// We keep track of what was added when so users can specify what version of the
/// tools' output they're expecting when it matters.
pub const OPERATORS_LATEST_VERSION: usize = 1;

struct KwAtomPair {
v: u8,
v: &'static [u8],
n: &'static str,
version: usize,
}

const KW_PAIRS: [KwAtomPair; 32] = [
KwAtomPair { v: 0x01, n: "q" },
KwAtomPair { v: 0x02, n: "a" },
KwAtomPair { v: 0x03, n: "i" },
KwAtomPair { v: 0x04, n: "c" },
KwAtomPair { v: 0x05, n: "f" },
KwAtomPair { v: 0x06, n: "r" },
KwAtomPair { v: 0x07, n: "l" },
KwAtomPair { v: 0x08, n: "x" },
KwAtomPair { v: 0x09, n: "=" },
KwAtomPair { v: 0x0a, n: ">s" },
KwAtomPair {
v: 0x0b,
const KW_PAIRS: [KwAtomPair; 46] = [
KwAtomPair {
v: &[0x01],
n: "q",
version: 0,
},
KwAtomPair {
v: &[0x02],
n: "a",
version: 0,
},
KwAtomPair {
v: &[0x03],
n: "i",
version: 0,
},
KwAtomPair {
v: &[0x04],
n: "c",
version: 0,
},
KwAtomPair {
v: &[0x05],
n: "f",
version: 0,
},
KwAtomPair {
v: &[0x06],
n: "r",
version: 0,
},
KwAtomPair {
v: &[0x07],
n: "l",
version: 0,
},
KwAtomPair {
v: &[0x08],
n: "x",
version: 0,
},
KwAtomPair {
v: &[0x09],
n: "=",
version: 0,
},
KwAtomPair {
v: &[0x0a],
n: ">s",
version: 0,
},
KwAtomPair {
v: &[0x0b],
n: "sha256",
version: 0,
},
KwAtomPair {
v: 0x0c,
v: &[0x0c],
n: "substr",
version: 0,
},
KwAtomPair {
v: 0x0d,
v: &[0x0d],
n: "strlen",
version: 0,
},
KwAtomPair {
v: 0x0e,
v: &[0x0e],
n: "concat",
version: 0,
},
KwAtomPair {
v: &[0x10],
n: "+",
version: 0,
},
KwAtomPair {
v: &[0x11],
n: "-",
version: 0,
},
KwAtomPair {
v: &[0x12],
n: "*",
version: 0,
},
KwAtomPair {
v: &[0x13],
n: "/",
version: 0,
},
KwAtomPair { v: 0x10, n: "+" },
KwAtomPair { v: 0x11, n: "-" },
KwAtomPair { v: 0x12, n: "*" },
KwAtomPair { v: 0x13, n: "/" },
KwAtomPair {
v: 0x14,
v: &[0x14],
n: "divmod",
version: 0,
},
KwAtomPair { v: 0x15, n: ">" },
KwAtomPair { v: 0x16, n: "ash" },
KwAtomPair { v: 0x17, n: "lsh" },
KwAtomPair {
v: 0x18,
v: &[0x15],
n: ">",
version: 0,
},
KwAtomPair {
v: &[0x16],
n: "ash",
version: 0,
},
KwAtomPair {
v: &[0x17],
n: "lsh",
version: 0,
},
KwAtomPair {
v: &[0x18],
n: "logand",
version: 0,
},
KwAtomPair {
v: 0x19,
v: &[0x19],
n: "logior",
version: 0,
},
KwAtomPair {
v: 0x1a,
v: &[0x1a],
n: "logxor",
version: 0,
},
KwAtomPair {
v: 0x1b,
v: &[0x1b],
n: "lognot",
version: 0,
},
KwAtomPair {
v: 0x1d,
v: &[0x1d],
n: "point_add",
version: 0,
},
KwAtomPair {
v: 0x1e,
v: &[0x1e],
n: "pubkey_for_exp",
version: 0,
},
KwAtomPair {
v: &[0x20],
n: "not",
version: 0,
},
KwAtomPair {
v: &[0x21],
n: "any",
version: 0,
},
KwAtomPair {
v: &[0x22],
n: "all",
version: 0,
},
KwAtomPair { v: 0x20, n: "not" },
KwAtomPair { v: 0x21, n: "any" },
KwAtomPair { v: 0x22, n: "all" },
KwAtomPair {
v: 0x24,
v: &[0x24],
n: "softfork",
version: 0,
},
KwAtomPair {
v: &[0x30],
n: "coinid",
version: 1,
},
KwAtomPair {
v: &[0x31],
n: "g1_subtract",
version: 1,
},
KwAtomPair {
v: &[0x32],
n: "g1_multiply",
version: 1,
},
KwAtomPair {
v: &[0x33],
n: "g1_negate",
version: 1,
},
KwAtomPair {
v: &[0x34],
n: "g2_add",
version: 1,
},
KwAtomPair {
v: &[0x35],
n: "g2_subtract",
version: 1,
},
KwAtomPair {
v: &[0x36],
n: "g2_multiply",
version: 1,
},
KwAtomPair {
v: &[0x37],
n: "g2_negate",
version: 1,
},
KwAtomPair {
v: &[0x38],
n: "g1_map",
version: 1,
},
KwAtomPair {
v: &[0x39],
n: "g2_map",
version: 1,
},
KwAtomPair {
v: &[0x3a],
n: "bls_pairing_identity",
version: 1,
},
KwAtomPair {
v: &[0x3b],
n: "bls_verify",
version: 1,
},
KwAtomPair {
v: &[0x13, 0xd6, 0x1f, 0x00],
n: "secp256k1_verify",
version: 1,
},
KwAtomPair {
v: &[0x1c, 0x3a, 0x8f, 0x00],
n: "secp256r1_verify",
version: 1,
},
];

lazy_static! {
pub static ref KEYWORD_FROM_ATOM_: HashMap<Vec<u8>, String> = {
pub static ref KEYWORD_FROM_ATOM_0: HashMap<Vec<u8>, String> = {
let mut result = HashMap::new();
for pair in KW_PAIRS.iter().filter(|p| p.version == 0) {
result.insert(pair.v.to_vec(), pair.n.to_string());
}
result
};
pub static ref KEYWORD_TO_ATOM_0: HashMap<String, Vec<u8>> = {
let mut result = HashMap::new();
for pair in KW_PAIRS.iter().filter(|p| p.version == 0) {
result.insert(pair.n.to_string(), pair.v.to_vec());
}
result
};
pub static ref KEYWORD_FROM_ATOM_1: HashMap<Vec<u8>, String> = {
let mut result = HashMap::new();
for pair in KW_PAIRS {
result.insert(vec![pair.v], pair.n.to_string());
for pair in KW_PAIRS.iter().filter(|p| p.version <= 1) {
result.insert(pair.v.to_vec(), pair.n.to_string());
}
result
};
pub static ref KEYWORD_TO_ATOM_: HashMap<String, Vec<u8>> = {
pub static ref KEYWORD_TO_ATOM_1: HashMap<String, Vec<u8>> = {
let mut result = HashMap::new();
for pair in KW_PAIRS {
result.insert(pair.n.to_string(), vec![pair.v]);
for pair in KW_PAIRS.iter().filter(|p| p.version <= 1) {
result.insert(pair.n.to_string(), pair.v.to_vec());
}
result
};
}

pub fn keyword_from_atom() -> &'static HashMap<Vec<u8>, String> {
&KEYWORD_FROM_ATOM_
pub fn keyword_from_atom(version: usize) -> &'static HashMap<Vec<u8>, String> {
if version == 0 {
&KEYWORD_FROM_ATOM_0
} else {
&KEYWORD_FROM_ATOM_1
}
}

pub fn keyword_to_atom() -> &'static HashMap<String, Vec<u8>> {
&KEYWORD_TO_ATOM_
pub fn keyword_to_atom(version: usize) -> &'static HashMap<String, Vec<u8>> {
if version == 0 {
&KEYWORD_TO_ATOM_0
} else {
&KEYWORD_TO_ATOM_1
}
}
Loading
Loading