diff --git a/Cargo.toml b/Cargo.toml index 02cb361..b98aeb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,10 @@ serde = { version = "1", features = ["derive"] } static_assertions = "1" num_enum = "0.6" -zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "v1.5.0" } -# zkevm_opcode_defs = { path = "../era-zkevm_opcode_defs" } +# TODO: change to use matter-labs when everything is merged: +# zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "dl-precompiles" } +# zkevm_opcode_defs = { git = "https://github.com/distributed-lab/era-zkevm_opcode_defs.git", branch = "feature/ec-and-modexp-precompiles" } +zkevm_opcode_defs = { path = "../era-zkevm_opcode_defs" } [dev-dependencies] diff --git a/src/precompiles/ecadd.rs b/src/precompiles/ecadd.rs index 34012bd..3a3cc0a 100644 --- a/src/precompiles/ecadd.rs +++ b/src/precompiles/ecadd.rs @@ -175,7 +175,8 @@ impl Precompile for ECAddPrecompile { value_is_pointer: false, rw_flag: true, }; - let x_result_query = memory.execute_partial_query(monotonic_cycle_counter, x_result_query); + let x_result_query = + memory.execute_partial_query(monotonic_cycle_counter, x_result_query); // Writing resultant y coordinate write_location.index.0 += 1; @@ -187,7 +188,8 @@ impl Precompile for ECAddPrecompile { value_is_pointer: false, rw_flag: true, }; - let y_result_query = memory.execute_partial_query(monotonic_cycle_counter, y_result_query); + let y_result_query = + memory.execute_partial_query(monotonic_cycle_counter, y_result_query); if B { round_witness.writes[0] = ok_or_err_query; @@ -224,7 +226,8 @@ impl Precompile for ECAddPrecompile { value_is_pointer: false, rw_flag: true, }; - let x_result_query = memory.execute_partial_query(monotonic_cycle_counter, x_result_query); + let x_result_query = + memory.execute_partial_query(monotonic_cycle_counter, x_result_query); let y_result_query = MemoryQuery { timestamp: timestamp_to_write, @@ -233,7 +236,8 @@ impl Precompile for ECAddPrecompile { value_is_pointer: false, rw_flag: true, }; - let y_result_query = memory.execute_partial_query(monotonic_cycle_counter, y_result_query); + let y_result_query = + memory.execute_partial_query(monotonic_cycle_counter, y_result_query); if B { round_witness.writes[0] = ok_or_err_query; diff --git a/src/precompiles/ecmul.rs b/src/precompiles/ecmul.rs index 9bb94ce..f8fbeef 100644 --- a/src/precompiles/ecmul.rs +++ b/src/precompiles/ecmul.rs @@ -158,7 +158,8 @@ impl Precompile for ECMulPrecompile { value_is_pointer: false, rw_flag: true, }; - let x_result_query = memory.execute_partial_query(monotonic_cycle_counter, x_result_query); + let x_result_query = + memory.execute_partial_query(monotonic_cycle_counter, x_result_query); // Writing resultant y coordinate write_location.index.0 += 1; @@ -170,7 +171,8 @@ impl Precompile for ECMulPrecompile { value_is_pointer: false, rw_flag: true, }; - let y_result_query = memory.execute_partial_query(monotonic_cycle_counter, y_result_query); + let y_result_query = + memory.execute_partial_query(monotonic_cycle_counter, y_result_query); if B { round_witness.writes[0] = ok_or_err_query; @@ -207,7 +209,8 @@ impl Precompile for ECMulPrecompile { value_is_pointer: false, rw_flag: true, }; - let x_result_query = memory.execute_partial_query(monotonic_cycle_counter, x_result_query); + let x_result_query = + memory.execute_partial_query(monotonic_cycle_counter, x_result_query); write_location.index.0 += 1; let empty_result = U256::zero(); @@ -218,7 +221,8 @@ impl Precompile for ECMulPrecompile { value_is_pointer: false, rw_flag: true, }; - let y_result_query = memory.execute_partial_query(monotonic_cycle_counter, y_result_query); + let y_result_query = + memory.execute_partial_query(monotonic_cycle_counter, y_result_query); if B { round_witness.writes[0] = ok_or_err_query; diff --git a/src/precompiles/ecpairing.rs b/src/precompiles/ecpairing.rs index 1cb52b7..cfe47c5 100644 --- a/src/precompiles/ecpairing.rs +++ b/src/precompiles/ecpairing.rs @@ -462,10 +462,13 @@ pub mod tests { ]) .unwrap(); - println!("{:?}", vec![ - [x1_1, y1_1, x2_1, y2_1, x3_1, y3_1], - [x1_2, y1_2, x2_2, y2_2, x3_2, y3_2], - ]); + println!( + "{:?}", + vec![ + [x1_1, y1_1, x2_1, y2_1, x3_1, y3_1], + [x1_2, y1_2, x2_2, y2_2, x3_2, y3_2], + ] + ); assert_eq!(result, true); } diff --git a/src/precompiles/mod.rs b/src/precompiles/mod.rs index 4ed2cc7..26173b9 100644 --- a/src/precompiles/mod.rs +++ b/src/precompiles/mod.rs @@ -17,9 +17,9 @@ use zkevm_opcode_defs::system_params::ECMUL_INNER_FUNCTION_PRECOMPILE_ADDRESS; use zkevm_opcode_defs::system_params::ECPAIRING_INNER_FUNCTION_PRECOMPILE_ADDRESS; use zkevm_opcode_defs::system_params::MODEXP_INNER_FUNCTION_PRECOMPILE_ADDRESS; use zkevm_opcode_defs::system_params::{ - ECRECOVER_INNER_FUNCTION_PRECOMPILE_ADDRESS, KECCAK256_ROUND_FUNCTION_PRECOMPILE_ADDRESS, - SHA256_ROUND_FUNCTION_PRECOMPILE_ADDRESS, ECADD_INNER_FUNCTION_PRECOMPILE_ADDRESS, - SECP256R1_VERIFY_PRECOMPILE_ADDRESS, + ECADD_INNER_FUNCTION_PRECOMPILE_ADDRESS, ECRECOVER_INNER_FUNCTION_PRECOMPILE_ADDRESS, + KECCAK256_ROUND_FUNCTION_PRECOMPILE_ADDRESS, SECP256R1_VERIFY_PRECOMPILE_ADDRESS, + SHA256_ROUND_FUNCTION_PRECOMPILE_ADDRESS, }; use zkevm_opcode_defs::PrecompileCallABI; diff --git a/src/vm.rs b/src/vm.rs index 98a9c1f..d6bfb04 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -6,10 +6,9 @@ use zkevm_opcode_defs::{ use crate::{ aux::{MemoryPage, PubdataCost, Timestamp}, precompiles::{ - ecrecover::ECRecoverPrecompile, keccak256::Keccak256Precompile, - secp256r1_verify::Secp256r1VerifyPrecompile, sha256::Sha256Precompile, ecadd::ECAddPrecompile, ecmul::ECMulPrecompile, ecpairing::ECPairingPrecompile, - modexp::ModexpPrecompile, + ecrecover::ECRecoverPrecompile, keccak256::Keccak256Precompile, modexp::ModexpPrecompile, + secp256r1_verify::Secp256r1VerifyPrecompile, sha256::Sha256Precompile, }, queries::{DecommittmentQuery, LogQuery, MemoryQuery}, }; @@ -65,7 +64,7 @@ pub enum PrecompileCyclesWitness { ECPairing(Vec< as Precompile>::CycleWitness>), Modexp(Vec< as Precompile>::CycleWitness>), Secp256r1Verify(Vec< as Precompile>::CycleWitness>), - } +} // ALL traits here are for execution and NOT for witness generation. They can depend on one another, but should // not have large interconnections.