From 5199895bc27dbd2814798fa24bbb0c357908cab3 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 12 Jun 2024 19:26:05 -0400 Subject: [PATCH 1/7] feat: add matter labs ecAdd precompile --- crates/precompile/src/bn128.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index c9ce059d73..6df5892283 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -126,17 +126,13 @@ pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult return Err(Error::OutOfGas.into()); } - let input = right_pad::(input); + let res = EIP196Executor::add(input); + match res { + Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), + Err(e) => match e { - let p1 = read_point(&input[..64])?; - let p2 = read_point(&input[64..])?; - - let mut output = [0u8; 64]; - if let Some(sum) = AffineG1::from_jacobian(p1 + p2) { - sum.x().to_big_endian(&mut output[..32]).unwrap(); - sum.y().to_big_endian(&mut output[32..]).unwrap(); + } } - Ok(PrecompileOutput::new(gas_cost, output.into())) } pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { From 4bd4ecc1778a0f2ed3dec8b92bfe29efbd912ef3 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:32:50 -0400 Subject: [PATCH 2/7] chore: finish add impl --- Cargo.lock | 262 +++++++++++++++++++++------------ crates/precompile/Cargo.toml | 3 + crates/precompile/src/bn128.rs | 7 +- 3 files changed, 175 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce648c9552..e8324d63b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,8 +183,8 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8037e03c7f462a063f28daec9fda285a9a89da003c552f8637a80b9c8fd96241" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -270,8 +270,8 @@ dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -286,8 +286,8 @@ dependencies = [ "heck 0.5.0", "indexmap", "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", "syn-solidity", "tiny-keccak", @@ -302,8 +302,8 @@ dependencies = [ "const-hex", "dunce", "heck 0.5.0", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", "syn-solidity", ] @@ -395,7 +395,7 @@ dependencies = [ "ark-serialize 0.3.0", "ark-std 0.3.0", "derivative", - "num-bigint", + "num-bigint 0.4.5", "num-traits", "paste", "rustc_version 0.3.3", @@ -415,7 +415,7 @@ dependencies = [ "derivative", "digest 0.10.7", "itertools 0.10.5", - "num-bigint", + "num-bigint 0.4.5", "num-traits", "paste", "rustc_version 0.4.0", @@ -428,7 +428,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" dependencies = [ - "quote", + "quote 1.0.36", "syn 1.0.109", ] @@ -438,7 +438,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" dependencies = [ - "quote", + "quote 1.0.36", "syn 1.0.109", ] @@ -448,9 +448,9 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" dependencies = [ - "num-bigint", + "num-bigint 0.4.5", "num-traits", - "quote", + "quote 1.0.36", "syn 1.0.109", ] @@ -460,10 +460,10 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ - "num-bigint", + "num-bigint 0.4.5", "num-traits", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -485,7 +485,7 @@ checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ "ark-std 0.4.0", "digest 0.10.7", - "num-bigint", + "num-bigint 0.4.5", ] [[package]] @@ -531,8 +531,8 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -542,8 +542,8 @@ version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -591,8 +591,8 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -1052,8 +1052,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -1063,8 +1063,8 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -1075,8 +1075,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "rustc_version 0.4.0", "syn 1.0.109", ] @@ -1192,8 +1192,8 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -1213,6 +1213,35 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "eth_pairings" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a45a857681370c3751c3595c1dc0768fe99f9164e8dba94695445bc86ceba6b" +dependencies = [ + "byteorder", + "eth_pairings_repr_derive", + "lazy_static", + "num-bigint 0.2.6", + "num-integer", + "num-traits", +] + +[[package]] +name = "eth_pairings_repr_derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02a503bcffab874d769e2808e750b13c93faf8aac17d9f4e7e825058fd5aa162" +dependencies = [ + "byteorder", + "num-bigint 0.2.6", + "num-integer", + "num-traits", + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.14.9", +] + [[package]] name = "ethabi" version = "18.0.0" @@ -1312,7 +1341,7 @@ dependencies = [ "tempfile", "thiserror", "tiny-keccak", - "unicode-xid", + "unicode-xid 0.2.4", ] [[package]] @@ -1493,8 +1522,8 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -1943,8 +1972,8 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -2196,7 +2225,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ - "num-bigint", + "num-bigint 0.4.5", "num-complex", "num-integer", "num-iter", @@ -2204,6 +2233,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.5" @@ -2255,7 +2295,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "num-bigint", + "num-bigint 0.4.5", "num-integer", "num-traits", ] @@ -2296,8 +2336,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro-crate", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -2348,8 +2388,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" dependencies = [ "bytes", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -2374,8 +2414,8 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -2430,8 +2470,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ "proc-macro-crate", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -2518,8 +2558,8 @@ checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", "phf_shared", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -2547,8 +2587,8 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -2674,8 +2714,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", "version_check", ] @@ -2686,11 +2726,20 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "version_check", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.85" @@ -2726,8 +2775,8 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -2737,13 +2786,22 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.85", ] [[package]] @@ -2984,6 +3042,7 @@ dependencies = [ "blst", "c-kzg", "criterion", + "eth_pairings", "eyre", "k256", "once_cell", @@ -3120,8 +3179,8 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -3146,8 +3205,8 @@ dependencies = [ "cfg-if", "glob", "proc-macro-crate", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "regex", "relative-path", "rustc_version 0.4.0", @@ -3167,7 +3226,7 @@ dependencies = [ "ark-ff 0.4.2", "bytes", "fastrlp", - "num-bigint", + "num-bigint 0.4.5", "num-traits", "parity-scale-codec", "primitive-types", @@ -3328,8 +3387,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ "proc-macro-crate", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -3465,8 +3524,8 @@ version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -3552,7 +3611,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" dependencies = [ - "num-bigint", + "num-bigint 0.4.5", "num-traits", "thiserror", "time", @@ -3642,8 +3701,8 @@ checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck 0.3.3", "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 1.0.109", ] @@ -3663,8 +3722,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck 0.5.0", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "rustversion", "syn 2.0.66", ] @@ -3688,14 +3747,25 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "unicode-ident", ] @@ -3705,8 +3775,8 @@ version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "unicode-ident", ] @@ -3717,8 +3787,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6fe08d08d84f2c0a77f1e7c46518789d745c2e87a2721791ed7c3c9bc78df28" dependencies = [ "paste", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -3791,8 +3861,8 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -3893,8 +3963,8 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -4021,8 +4091,8 @@ version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -4145,6 +4215,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.4" @@ -4257,8 +4333,8 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", "wasm-bindgen-shared", ] @@ -4281,7 +4357,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ - "quote", + "quote 1.0.36", "wasm-bindgen-macro-support", ] @@ -4291,8 +4367,8 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -4562,8 +4638,8 @@ version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] @@ -4582,7 +4658,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.85", + "quote 1.0.36", "syn 2.0.66", ] diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 097985edca..37d117703f 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -43,6 +43,9 @@ aurora-engine-modexp = { version = "1.1", default-features = false } # ecAdd, ecMul, ecPairing bn = { package = "substrate-bn", version = "0.6", default-features = false } +# ecAdd (soon others) +eth_pairings = { version = "0.2.0", default-features = false } + # KZG point evaluation precompile c-kzg = { version = "1.0.2", default-features = false, optional = true } diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 6df5892283..ec2451945a 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -4,6 +4,7 @@ use crate::{ }; use bn::{AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2}; use revm_primitives::PrecompileOutput; +use eth_pairings::public_interface::{G1Api, PublicG1Api}; pub mod add { use super::*; @@ -126,12 +127,10 @@ pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult return Err(Error::OutOfGas.into()); } - let res = EIP196Executor::add(input); + let res = PublicG1Api::add_points(input); match res { Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), - Err(e) => match e { - - } + Err(e) => Err(Error::Other(e.to_string()).into()) } } From e57b414d2d9b350b4aa5a5df73fa73ff742306d5 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:40:40 -0400 Subject: [PATCH 3/7] feat: finish the rest of the precompile impls --- Cargo.lock | 255 ++++++++++++++++----------------- crates/precompile/Cargo.toml | 8 +- crates/precompile/src/bn128.rs | 124 +++------------- 3 files changed, 147 insertions(+), 240 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8324d63b5..98487111ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,8 +183,8 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8037e03c7f462a063f28daec9fda285a9a89da003c552f8637a80b9c8fd96241" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -270,8 +270,8 @@ dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "proc-macro-error", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -286,8 +286,8 @@ dependencies = [ "heck 0.5.0", "indexmap", "proc-macro-error", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", "syn-solidity", "tiny-keccak", @@ -302,8 +302,8 @@ dependencies = [ "const-hex", "dunce", "heck 0.5.0", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", "syn-solidity", ] @@ -428,7 +428,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" dependencies = [ - "quote 1.0.36", + "quote", "syn 1.0.109", ] @@ -438,7 +438,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" dependencies = [ - "quote 1.0.36", + "quote", "syn 1.0.109", ] @@ -450,7 +450,7 @@ checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" dependencies = [ "num-bigint 0.4.5", "num-traits", - "quote 1.0.36", + "quote", "syn 1.0.109", ] @@ -462,8 +462,8 @@ checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ "num-bigint 0.4.5", "num-traits", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -531,8 +531,8 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -542,8 +542,8 @@ version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -591,8 +591,8 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -1052,8 +1052,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -1063,8 +1063,8 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -1075,8 +1075,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "rustc_version 0.4.0", "syn 1.0.109", ] @@ -1192,8 +1192,8 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -1215,31 +1215,28 @@ dependencies = [ [[package]] name = "eth_pairings" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a45a857681370c3751c3595c1dc0768fe99f9164e8dba94695445bc86ceba6b" +version = "0.6.0" +source = "git+https://github.com/matter-labs/eip1962#17ba98bdbdd7bdf239c09cd88ca46a486124f5e7" dependencies = [ "byteorder", "eth_pairings_repr_derive", - "lazy_static", + "fixed_width_field", + "fixed_width_group_and_loop", "num-bigint 0.2.6", - "num-integer", "num-traits", + "once_cell", + "static_assertions", ] [[package]] name = "eth_pairings_repr_derive" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a503bcffab874d769e2808e750b13c93faf8aac17d9f4e7e825058fd5aa162" +version = "0.2.0" +source = "git+https://github.com/matter-labs/eip1962#17ba98bdbdd7bdf239c09cd88ca46a486124f5e7" dependencies = [ "byteorder", - "num-bigint 0.2.6", - "num-integer", - "num-traits", - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.14.9", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -1341,7 +1338,7 @@ dependencies = [ "tempfile", "thiserror", "tiny-keccak", - "unicode-xid 0.2.4", + "unicode-xid", ] [[package]] @@ -1432,6 +1429,22 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixed_width_field" +version = "0.1.0" +source = "git+https://github.com/matter-labs/eip1962#17ba98bdbdd7bdf239c09cd88ca46a486124f5e7" +dependencies = [ + "simple_uint", +] + +[[package]] +name = "fixed_width_group_and_loop" +version = "0.1.0" +source = "git+https://github.com/matter-labs/eip1962#17ba98bdbdd7bdf239c09cd88ca46a486124f5e7" +dependencies = [ + "simple_uint", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1522,8 +1535,8 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -1972,8 +1985,8 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -2336,8 +2349,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -2388,8 +2401,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" dependencies = [ "bytes", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -2414,8 +2427,8 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -2470,8 +2483,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -2558,8 +2571,8 @@ checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", "phf_shared", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -2587,8 +2600,8 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -2714,8 +2727,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", "version_check", ] @@ -2726,20 +2739,11 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "version_check", ] -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid 0.1.0", -] - [[package]] name = "proc-macro2" version = "1.0.85" @@ -2775,8 +2779,8 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -2786,22 +2790,13 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.85", + "proc-macro2", ] [[package]] @@ -3179,8 +3174,8 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -3205,8 +3200,8 @@ dependencies = [ "cfg-if", "glob", "proc-macro-crate", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "regex", "relative-path", "rustc_version 0.4.0", @@ -3387,8 +3382,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -3524,8 +3519,8 @@ version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -3617,6 +3612,17 @@ dependencies = [ "time", ] +[[package]] +name = "simple_uint" +version = "0.1.0" +source = "git+https://github.com/matter-labs/eip1962#17ba98bdbdd7bdf239c09cd88ca46a486124f5e7" +dependencies = [ + "byteorder", + "crunchy", + "rustc-hex", + "static_assertions", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -3701,8 +3707,8 @@ checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck 0.3.3", "proc-macro-error", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 1.0.109", ] @@ -3722,8 +3728,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck 0.5.0", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "rustversion", "syn 2.0.66", ] @@ -3747,25 +3753,14 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "syn" -version = "0.14.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid 0.1.0", -] - [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "unicode-ident", ] @@ -3775,8 +3770,8 @@ version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "unicode-ident", ] @@ -3787,8 +3782,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6fe08d08d84f2c0a77f1e7c46518789d745c2e87a2721791ed7c3c9bc78df28" dependencies = [ "paste", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -3861,8 +3856,8 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -3963,8 +3958,8 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -4091,8 +4086,8 @@ version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -4215,12 +4210,6 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - [[package]] name = "unicode-xid" version = "0.2.4" @@ -4333,8 +4322,8 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", "wasm-bindgen-shared", ] @@ -4357,7 +4346,7 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ - "quote 1.0.36", + "quote", "wasm-bindgen-macro-support", ] @@ -4367,8 +4356,8 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -4638,8 +4627,8 @@ version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] @@ -4658,7 +4647,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ - "proc-macro2 1.0.85", - "quote 1.0.36", + "proc-macro2", + "quote", "syn 2.0.66", ] diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 37d117703f..335ce62d2b 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -41,10 +41,7 @@ ripemd = { version = "0.1", default-features = false } aurora-engine-modexp = { version = "1.1", default-features = false } # ecAdd, ecMul, ecPairing -bn = { package = "substrate-bn", version = "0.6", default-features = false } - -# ecAdd (soon others) -eth_pairings = { version = "0.2.0", default-features = false } +eth_pairings = { git = "https://github.com/matter-labs/eip1962", default-features = false, features = ["eip_196"] } # KZG point evaluation precompile c-kzg = { version = "1.0.2", default-features = false, optional = true } @@ -66,6 +63,9 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" +# ecAdd, ecMul, ecPairing +bn = { package = "substrate-bn", version = "0.6", default-features = false } + [features] default = ["std", "c-kzg", "secp256k1", "portable", "blst"] std = [ diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index ec2451945a..43771760d6 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -1,10 +1,8 @@ -use crate::{ - utilities::{bool_to_bytes32, right_pad}, - Address, Error, Precompile, PrecompileResult, PrecompileWithAddress, -}; -use bn::{AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2}; +//! Precompiles for the "alt-bn128" curve. + +use crate::{Address, Error, Precompile, PrecompileResult, PrecompileWithAddress}; +use eth_pairings::public_interface::eip196::EIP196Executor; use revm_primitives::PrecompileOutput; -use eth_pairings::public_interface::{G1Api, PublicG1Api}; pub mod add { use super::*; @@ -76,61 +74,20 @@ pub mod pair { ); } -/// Input length for the add operation. -/// `ADD` takes two uncompressed G1 points (64 bytes each). -pub const ADD_INPUT_LEN: usize = 64 + 64; - -/// Input length for the multiplication operation. -/// `MUL` takes an uncompressed G1 point (64 bytes) and scalar (32 bytes). -pub const MUL_INPUT_LEN: usize = 64 + 32; - /// Pair element length. /// `PAIR` elements are composed of an uncompressed G1 point (64 bytes) and an uncompressed G2 point /// (128 bytes). pub const PAIR_ELEMENT_LEN: usize = 64 + 128; -/// Reads a single `Fq` from the input slice. -/// -/// # Panics -/// -/// Panics if the input is not at least 32 bytes long. -#[inline] -pub fn read_fq(input: &[u8]) -> Result { - Fq::from_slice(&input[..32]).map_err(|_| Error::Bn128FieldPointNotAMember) -} - -/// Reads the `x` and `y` points from the input slice. -/// -/// # Panics -/// -/// Panics if the input is not at least 64 bytes long. -#[inline] -pub fn read_point(input: &[u8]) -> Result { - let px = read_fq(&input[0..32])?; - let py = read_fq(&input[32..64])?; - new_g1_point(px, py) -} - -/// Creates a new `G1` point from the given `x` and `y` coordinates. -pub fn new_g1_point(px: Fq, py: Fq) -> Result { - if px == Fq::zero() && py == Fq::zero() { - Ok(G1::zero()) - } else { - AffineG1::new(px, py) - .map(Into::into) - .map_err(|_| Error::Bn128AffineGFailedToCreate) - } -} - pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit { return Err(Error::OutOfGas.into()); } - let res = PublicG1Api::add_points(input); + let res = EIP196Executor::add(input); match res { Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), - Err(e) => Err(Error::Other(e.to_string()).into()) + Err(e) => Err(Error::Other(e.to_string()).into()), } } @@ -139,19 +96,11 @@ pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult return Err(Error::OutOfGas.into()); } - let input = right_pad::(input); - - let p = read_point(&input[..64])?; - - // `Fr::from_slice` can only fail when the length is not 32. - let fr = bn::Fr::from_slice(&input[64..96]).unwrap(); - - let mut output = [0u8; 64]; - if let Some(mul) = AffineG1::from_jacobian(p * fr) { - mul.x().to_big_endian(&mut output[..32]).unwrap(); - mul.y().to_big_endian(&mut output[32..]).unwrap(); + let res = EIP196Executor::mul(input); + match res { + Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), + Err(e) => Err(Error::Other(e.to_string()).into()), } - Ok(PrecompileOutput::new(gas_cost, output.into())) } pub fn run_pair( @@ -169,45 +118,14 @@ pub fn run_pair( return Err(Error::Bn128PairLength.into()); } - let success = if input.is_empty() { - true - } else { - let elements = input.len() / PAIR_ELEMENT_LEN; - - let mut mul = Gt::one(); - for idx in 0..elements { - let read_fq_at = |n: usize| { - debug_assert!(n < PAIR_ELEMENT_LEN / 32); - let start = idx * PAIR_ELEMENT_LEN + n * 32; - // SAFETY: We're reading `6 * 32 == PAIR_ELEMENT_LEN` bytes from `input[idx..]` - // per iteration. This is guaranteed to be in-bounds. - let slice = unsafe { input.get_unchecked(start..start + 32) }; - Fq::from_slice(slice).map_err(|_| Error::Bn128FieldPointNotAMember) - }; - let ax = read_fq_at(0)?; - let ay = read_fq_at(1)?; - let bay = read_fq_at(2)?; - let bax = read_fq_at(3)?; - let bby = read_fq_at(4)?; - let bbx = read_fq_at(5)?; - - let a = new_g1_point(ax, ay)?; - let b = { - let ba = Fq2::new(bax, bay); - let bb = Fq2::new(bbx, bby); - if ba.is_zero() && bb.is_zero() { - G2::zero() - } else { - G2::from(AffineG2::new(ba, bb).map_err(|_| Error::Bn128AffineGFailedToCreate)?) - } - }; - - mul = mul * bn::pairing(a, b); - } - - mul == Gt::one() + let res = EIP196Executor::pair(input); + + let success = match res { + Ok(res) => res.into(), + Err(e) => return Err(Error::Other(e.to_string()).into()), }; - Ok(PrecompileOutput::new(gas_used, bool_to_bytes32(success))) + + Ok(PrecompileOutput::new(gas_used, success)) } #[cfg(test)] @@ -215,7 +133,7 @@ mod tests { use crate::bn128::add::BYZANTIUM_ADD_GAS_COST; use crate::bn128::mul::BYZANTIUM_MUL_GAS_COST; use crate::bn128::pair::{BYZANTIUM_PAIR_BASE, BYZANTIUM_PAIR_PER_POINT}; - use revm_primitives::{hex, PrecompileErrors}; + use revm_primitives::{hex, PrecompileError, PrecompileErrors}; use super::*; @@ -297,7 +215,7 @@ mod tests { let res = run_add(&input, BYZANTIUM_ADD_GAS_COST, 500); assert!(matches!( res, - Err(PrecompileErrors::Error(Error::Bn128AffineGFailedToCreate)) + Err(PrecompileErrors::Error(PrecompileError::Other(..))) )); } @@ -374,7 +292,7 @@ mod tests { let res = run_mul(&input, BYZANTIUM_MUL_GAS_COST, 40_000); assert!(matches!( res, - Err(PrecompileErrors::Error(Error::Bn128AffineGFailedToCreate)) + Err(PrecompileErrors::Error(PrecompileError::Other(..))) )); } @@ -470,7 +388,7 @@ mod tests { ); assert!(matches!( res, - Err(PrecompileErrors::Error(Error::Bn128AffineGFailedToCreate)) + Err(PrecompileErrors::Error(PrecompileError::Other(..))) )); // invalid input length From 39cf3f0b8a85a1e22cc107b84429e7999b582b12 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:44:26 -0400 Subject: [PATCH 4/7] wip: set up feature for bn impl --- crates/precompile/Cargo.toml | 9 ++- crates/precompile/src/bn128.rs | 144 +++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 4 deletions(-) diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 335ce62d2b..0fd30d5154 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -49,6 +49,9 @@ c-kzg = { version = "1.0.2", default-features = false, optional = true } # BLS12-381 precompiles blst = { version = "0.3.12", optional = true } +# ecAdd, ecMul, ecPairing +bn = { package = "substrate-bn", version = "0.6", default-features = false, optional = true } + # p256verify precompile p256 = { version = "0.13.2", optional = true, default-features = false, features = [ "ecdsa", @@ -63,11 +66,8 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -# ecAdd, ecMul, ecPairing -bn = { package = "substrate-bn", version = "0.6", default-features = false } - [features] -default = ["std", "c-kzg", "secp256k1", "portable", "blst"] +default = ["std", "c-kzg", "secp256k1", "portable", "blst", "bn"] std = [ "revm-primitives/std", "k256/std", @@ -79,6 +79,7 @@ std = [ ] hashbrown = ["revm-primitives/hashbrown"] asm-keccak = ["revm-primitives/asm-keccak"] +bn = ["dep:bn"] optimism = ["revm-primitives/optimism", "secp256r1"] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 43771760d6..6937da29db 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -128,6 +128,150 @@ pub fn run_pair( Ok(PrecompileOutput::new(gas_used, success)) } +#[cfg(feature = "bn")] +mod bn { + use crate::{utilities::{bool_to_bytes32, right_pad}, Error, PrecompileResult}; + use revm_primitives::PrecompileOutput; + use bn::{AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2}; + + use super::PAIR_ELEMENT_LEN; + + /// Input length for the add operation. + /// `ADD` takes two uncompressed G1 points (64 bytes each). + const ADD_INPUT_LEN: usize = 64 + 64; + + /// Input length for the multiplication operation. + /// `MUL` takes an uncompressed G1 point (64 bytes) and scalar (32 bytes). + const MUL_INPUT_LEN: usize = 64 + 32; + + /// Reads a single `Fq` from the input slice. + /// + /// # Panics + /// + /// Panics if the input is not at least 32 bytes long. + #[inline] + pub fn read_fq(input: &[u8]) -> Result { + Fq::from_slice(&input[..32]).map_err(|_| Error::Bn128FieldPointNotAMember) + } + + /// Reads the `x` and `y` points from the input slice. + /// + /// # Panics + /// + /// Panics if the input is not at least 64 bytes long. + #[inline] + pub fn read_point(input: &[u8]) -> Result { + let px = read_fq(&input[0..32])?; + let py = read_fq(&input[32..64])?; + new_g1_point(px, py) + } + + /// Creates a new `G1` point from the given `x` and `y` coordinates. + pub fn new_g1_point(px: Fq, py: Fq) -> Result { + if px == Fq::zero() && py == Fq::zero() { + Ok(G1::zero()) + } else { + AffineG1::new(px, py) + .map(Into::into) + .map_err(|_| Error::Bn128AffineGFailedToCreate) + } + } + + pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + if gas_cost > gas_limit { + return Err(Error::OutOfGas.into()); + } + + let input = right_pad::(input); + + let p1 = read_point(&input[..64])?; + let p2 = read_point(&input[64..])?; + + let mut output = [0u8; 64]; + if let Some(sum) = AffineG1::from_jacobian(p1 + p2) { + sum.x().to_big_endian(&mut output[..32]).unwrap(); + sum.y().to_big_endian(&mut output[32..]).unwrap(); + } + Ok(PrecompileOutput::new(gas_cost, output.into())) + } + + pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + if gas_cost > gas_limit { + return Err(Error::OutOfGas.into()); + } + + let input = right_pad::(input); + + let p = read_point(&input[..64])?; + + // `Fr::from_slice` can only fail when the length is not 32. + let fr = bn::Fr::from_slice(&input[64..96]).unwrap(); + + let mut output = [0u8; 64]; + if let Some(mul) = AffineG1::from_jacobian(p * fr) { + mul.x().to_big_endian(&mut output[..32]).unwrap(); + mul.y().to_big_endian(&mut output[32..]).unwrap(); + } + Ok(PrecompileOutput::new(gas_cost, output.into())) + } + + pub fn run_pair( + input: &[u8], + pair_per_point_cost: u64, + pair_base_cost: u64, + gas_limit: u64, + ) -> PrecompileResult { + let gas_used = (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; + if gas_used > gas_limit { + return Err(Error::OutOfGas.into()); + } + + if input.len() % PAIR_ELEMENT_LEN != 0 { + return Err(Error::Bn128PairLength.into()); + } + + let success = if input.is_empty() { + true + } else { + let elements = input.len() / PAIR_ELEMENT_LEN; + + let mut mul = Gt::one(); + for idx in 0..elements { + let read_fq_at = |n: usize| { + debug_assert!(n < PAIR_ELEMENT_LEN / 32); + let start = idx * PAIR_ELEMENT_LEN + n * 32; + // SAFETY: We're reading `6 * 32 == PAIR_ELEMENT_LEN` bytes from `input[idx..]` + // per iteration. This is guaranteed to be in-bounds. + let slice = unsafe { input.get_unchecked(start..start + 32) }; + Fq::from_slice(slice).map_err(|_| Error::Bn128FieldPointNotAMember) + }; + let ax = read_fq_at(0)?; + let ay = read_fq_at(1)?; + let bay = read_fq_at(2)?; + let bax = read_fq_at(3)?; + let bby = read_fq_at(4)?; + let bbx = read_fq_at(5)?; + + let a = new_g1_point(ax, ay)?; + let b = { + let ba = Fq2::new(bax, bay); + let bb = Fq2::new(bbx, bby); + if ba.is_zero() && bb.is_zero() { + G2::zero() + } else { + G2::from(AffineG2::new(ba, bb).map_err(|_| Error::Bn128AffineGFailedToCreate)?) + } + }; + + mul = mul * bn::pairing(a, b); + } + + mul == Gt::one() + }; + Ok(PrecompileOutput::new(gas_used, bool_to_bytes32(success))) + } +} + #[cfg(test)] mod tests { use crate::bn128::add::BYZANTIUM_ADD_GAS_COST; From 3bfa90dfb59daf0fcb8c480868bb22e13fc1e5f1 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:15:02 -0400 Subject: [PATCH 5/7] fix: make each implementation a module --- Cargo.lock | 1 + crates/precompile/Cargo.toml | 3 +- crates/precompile/src/bn128.rs | 184 +++++++++++++++++++++++---------- 3 files changed, 134 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98487111ed..499c36b825 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3036,6 +3036,7 @@ dependencies = [ "aurora-engine-modexp", "blst", "c-kzg", + "cfg-if", "criterion", "eth_pairings", "eyre", diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 0fd30d5154..7c858f56ec 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -23,6 +23,7 @@ all = "warn" [dependencies] revm-primitives = { path = "../primitives", version = "4.0.0", default-features = false } once_cell = { version = "1.19", default-features = false, features = ["alloc"] } +cfg-if = "1.0" # ecRecover k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] } @@ -67,7 +68,7 @@ serde_json = "1.0" serde_derive = "1.0" [features] -default = ["std", "c-kzg", "secp256k1", "portable", "blst", "bn"] +default = ["std", "c-kzg", "secp256k1", "portable", "blst"] std = [ "revm-primitives/std", "k256/std", diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 6937da29db..07f66d58ff 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -1,8 +1,6 @@ //! Precompiles for the "alt-bn128" curve. -use crate::{Address, Error, Precompile, PrecompileResult, PrecompileWithAddress}; -use eth_pairings::public_interface::eip196::EIP196Executor; -use revm_primitives::PrecompileOutput; +use crate::{Address, Precompile, PrecompileResult, PrecompileWithAddress}; pub mod add { use super::*; @@ -80,26 +78,22 @@ pub mod pair { pub const PAIR_ELEMENT_LEN: usize = 64 + 128; pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { - if gas_cost > gas_limit { - return Err(Error::OutOfGas.into()); - } - - let res = EIP196Executor::add(input); - match res { - Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), - Err(e) => Err(Error::Other(e.to_string()).into()), + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + bn::run_add(input, gas_cost, gas_limit) + } else { + matter_labs::run_add(input, gas_cost, gas_limit) + } } } pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { - if gas_cost > gas_limit { - return Err(Error::OutOfGas.into()); - } - - let res = EIP196Executor::mul(input); - match res { - Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), - Err(e) => Err(Error::Other(e.to_string()).into()), + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + bn::run_mul(input, gas_cost, gas_limit) + } else { + matter_labs::run_mul(input, gas_cost, gas_limit) + } } } @@ -109,32 +103,83 @@ pub fn run_pair( pair_base_cost: u64, gas_limit: u64, ) -> PrecompileResult { - let gas_used = (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; - if gas_used > gas_limit { - return Err(Error::OutOfGas.into()); + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + bn::run_pair(input, pair_per_point_cost, pair_base_cost, gas_limit) + } else { + matter_labs::run_pair(input, pair_per_point_cost, pair_base_cost, gas_limit) + } } +} + +#[cfg(not(feature = "bn"))] +mod matter_labs { + use super::PAIR_ELEMENT_LEN; + use crate::{Error, PrecompileOutput, PrecompileResult}; + use eth_pairings::public_interface::eip196::EIP196Executor; - if input.len() % PAIR_ELEMENT_LEN != 0 { - return Err(Error::Bn128PairLength.into()); + pub(crate) fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + if gas_cost > gas_limit { + return Err(Error::OutOfGas.into()); + } + + let res = EIP196Executor::add(input); + match res { + Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), + Err(e) => Err(Error::Other(e.to_string()).into()), + } } - let res = EIP196Executor::pair(input); + pub(crate) fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + if gas_cost > gas_limit { + return Err(Error::OutOfGas.into()); + } - let success = match res { - Ok(res) => res.into(), - Err(e) => return Err(Error::Other(e.to_string()).into()), - }; + let res = EIP196Executor::mul(input); + match res { + Ok(res) => Ok(PrecompileOutput::new(gas_cost, res.into())), + Err(e) => Err(Error::Other(e.to_string()).into()), + } + } - Ok(PrecompileOutput::new(gas_used, success)) + pub(crate) fn run_pair( + input: &[u8], + pair_per_point_cost: u64, + pair_base_cost: u64, + gas_limit: u64, + ) -> PrecompileResult { + let gas_used = + (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; + if gas_used > gas_limit { + return Err(Error::OutOfGas.into()); + } + + if input.len() % PAIR_ELEMENT_LEN != 0 { + return Err(Error::Bn128PairLength.into()); + } + + let res = EIP196Executor::pair(input); + + let success = match res { + Ok(res) => res.into(), + Err(e) => return Err(Error::Other(e.to_string()).into()), + }; + + Ok(PrecompileOutput::new(gas_used, success)) + } } #[cfg(feature = "bn")] mod bn { - use crate::{utilities::{bool_to_bytes32, right_pad}, Error, PrecompileResult}; - use revm_primitives::PrecompileOutput; + use super::PAIR_ELEMENT_LEN; + use crate::{ + utilities::{bool_to_bytes32, right_pad}, + Error, PrecompileOutput, PrecompileResult, + }; use bn::{AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2}; - use super::PAIR_ELEMENT_LEN; + // Silence the unused crate dependency warning. + use eth_pairings as _; /// Input length for the add operation. /// `ADD` takes two uncompressed G1 points (64 bytes each). @@ -150,7 +195,7 @@ mod bn { /// /// Panics if the input is not at least 32 bytes long. #[inline] - pub fn read_fq(input: &[u8]) -> Result { + fn read_fq(input: &[u8]) -> Result { Fq::from_slice(&input[..32]).map_err(|_| Error::Bn128FieldPointNotAMember) } @@ -160,14 +205,14 @@ mod bn { /// /// Panics if the input is not at least 64 bytes long. #[inline] - pub fn read_point(input: &[u8]) -> Result { + fn read_point(input: &[u8]) -> Result { let px = read_fq(&input[0..32])?; let py = read_fq(&input[32..64])?; new_g1_point(px, py) } /// Creates a new `G1` point from the given `x` and `y` coordinates. - pub fn new_g1_point(px: Fq, py: Fq) -> Result { + fn new_g1_point(px: Fq, py: Fq) -> Result { if px == Fq::zero() && py == Fq::zero() { Ok(G1::zero()) } else { @@ -177,7 +222,7 @@ mod bn { } } - pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + pub(crate) fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit { return Err(Error::OutOfGas.into()); } @@ -195,7 +240,7 @@ mod bn { Ok(PrecompileOutput::new(gas_cost, output.into())) } - pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { + pub(crate) fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit { return Err(Error::OutOfGas.into()); } @@ -215,13 +260,14 @@ mod bn { Ok(PrecompileOutput::new(gas_cost, output.into())) } - pub fn run_pair( + pub(crate) fn run_pair( input: &[u8], pair_per_point_cost: u64, pair_base_cost: u64, gas_limit: u64, ) -> PrecompileResult { - let gas_used = (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; + let gas_used = + (input.len() / PAIR_ELEMENT_LEN) as u64 * pair_per_point_cost + pair_base_cost; if gas_used > gas_limit { return Err(Error::OutOfGas.into()); } @@ -259,7 +305,9 @@ mod bn { if ba.is_zero() && bb.is_zero() { G2::zero() } else { - G2::from(AffineG2::new(ba, bb).map_err(|_| Error::Bn128AffineGFailedToCreate)?) + G2::from( + AffineG2::new(ba, bb).map_err(|_| Error::Bn128AffineGFailedToCreate)?, + ) } }; @@ -277,6 +325,7 @@ mod tests { use crate::bn128::add::BYZANTIUM_ADD_GAS_COST; use crate::bn128::mul::BYZANTIUM_MUL_GAS_COST; use crate::bn128::pair::{BYZANTIUM_PAIR_BASE, BYZANTIUM_PAIR_PER_POINT}; + use crate::Error; use revm_primitives::{hex, PrecompileError, PrecompileErrors}; use super::*; @@ -357,10 +406,19 @@ mod tests { .unwrap(); let res = run_add(&input, BYZANTIUM_ADD_GAS_COST, 500); - assert!(matches!( - res, - Err(PrecompileErrors::Error(PrecompileError::Other(..))) - )); + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Bn128AffineGFailedToCreate)), + )); + } else { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Other(..))), + )); + } + } } #[test] @@ -434,10 +492,19 @@ mod tests { .unwrap(); let res = run_mul(&input, BYZANTIUM_MUL_GAS_COST, 40_000); - assert!(matches!( - res, - Err(PrecompileErrors::Error(PrecompileError::Other(..))) - )); + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Bn128AffineGFailedToCreate)), + )); + } else { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Other(..))), + )); + } + } } #[test] @@ -495,6 +562,7 @@ mod tests { BYZANTIUM_PAIR_BASE, 259_999, ); + assert!(matches!(res, Err(PrecompileErrors::Error(Error::OutOfGas)))); // no input test @@ -530,10 +598,20 @@ mod tests { BYZANTIUM_PAIR_BASE, 260_000, ); - assert!(matches!( - res, - Err(PrecompileErrors::Error(PrecompileError::Other(..))) - )); + + cfg_if::cfg_if! { + if #[cfg(feature = "bn")] { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Bn128AffineGFailedToCreate)), + )); + } else { + assert!(matches!( + res, + Err(PrecompileErrors::Error(PrecompileError::Other(..))), + )); + } + } // invalid input length let input = hex::decode( From 737067d6a7ad693bc4ed8563a6c72fb75d12cbdc Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:19:28 -0400 Subject: [PATCH 6/7] fix: use tostring directly --- crates/precompile/src/bn128.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index 07f66d58ff..f71b3bd038 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -116,6 +116,7 @@ pub fn run_pair( mod matter_labs { use super::PAIR_ELEMENT_LEN; use crate::{Error, PrecompileOutput, PrecompileResult}; + use std::string::ToString; use eth_pairings::public_interface::eip196::EIP196Executor; pub(crate) fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { From 3199602ef98c9930993994280cae65bf7c021599 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:20:19 -0400 Subject: [PATCH 7/7] cargo fmt --- crates/precompile/src/bn128.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index f71b3bd038..0dbf4ec4ba 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -116,8 +116,8 @@ pub fn run_pair( mod matter_labs { use super::PAIR_ELEMENT_LEN; use crate::{Error, PrecompileOutput, PrecompileResult}; - use std::string::ToString; use eth_pairings::public_interface::eip196::EIP196Executor; + use std::string::ToString; pub(crate) fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit {