diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f129e60 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,9 @@ +# Contribution Guidelines + +Thank you for considering helping out with the source code! We are extremely grateful for any consideration of +contributions to this repository. However, at this time, we generally do not accept external contributions. This policy +will change in the future, so please check back regularly for updates. + +For security issues, please contact us at [security@matterlabs.dev](mailto:security@matterlabs.dev). + +Thank you for your support in accelerating the mass adoption of crypto for personal sovereignty! diff --git a/Cargo.toml b/Cargo.toml index 3f3ce0b..2881b76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sync_vm" -version = "1.3.2" +version = "1.3.3" authors = ["Alex Vlasov ", "Konstantin Panarin "] edition = "2021" @@ -25,7 +25,7 @@ rescue_poseidon = {git = "https://github.com/matter-labs/rescue-poseidon.git"} arrayvec = "0.7" num-derive = "0.3" zkevm_opcode_defs = {git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "v1.3.2"} -zk_evm = {git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.3.2"} +zk_evm = {git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.3.3"} serde = {version = "1", features = ["derive"]} smallvec = {version = "*", features = ["const_generics"]} @@ -34,3 +34,6 @@ split-debuginfo = "unpacked" [features] external_testing = [] + + + diff --git a/README.md b/README.md index 7009b8c..b68722f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ at your option. - [GitHub](https://github.com/matter-labs) - [Twitter](https://twitter.com/zksync) - [Twitter for Devs](https://twitter.com/zkSyncDevs) -- [Discord](https://join.zksync.dev) +- [Discord](https://discord.gg/nMaPGrDDwk) ## Disclaimer diff --git a/cs_derive/src/alloc.rs b/cs_derive/src/alloc.rs index 105a1a3..20392fb 100644 --- a/cs_derive/src/alloc.rs +++ b/cs_derive/src/alloc.rs @@ -43,7 +43,7 @@ fn derive_from_path(ident: &Ident, ty: &TypePath) -> (TokenStream, TokenStream) let mut #ident = #elem_ident::zero(); }; let alloc = quote! { - let mut #ident = #elem_ident::#fn_ident(cs, witness.as_ref().map(|w| w.#ident.clone()))?; + let mut #ident = #elem_ident::#fn_ident(cs, witness.as_ref().map(|w| w.#ident.clone()))?; // TODO w.#ident.clone() need for BigUint }; (empty, alloc) diff --git a/cs_derive/src/eq.rs b/cs_derive/src/eq.rs index 3b2f21e..69a41ad 100644 --- a/cs_derive/src/eq.rs +++ b/cs_derive/src/eq.rs @@ -81,6 +81,7 @@ pub(crate) fn derive_eq(input: proc_macro::TokenStream) -> proc_macro::TokenStre get_type_params_from_generics(&generics, &comma, has_engine_param == false); let expanded = quote! { + // TODO: check generics has Engine param impl#generics CircuitEq for #ident<#type_params_of_allocated_struct>{ fn eq(&self, other: &Self) -> bool { #array_equality_check diff --git a/cs_derive/src/new_alloc.rs b/cs_derive/src/new_alloc.rs index a8e9cd1..da37d85 100644 --- a/cs_derive/src/new_alloc.rs +++ b/cs_derive/src/new_alloc.rs @@ -172,7 +172,7 @@ fn derive_from_path(ident: &Ident, ty: &TypePath) -> (TokenStream, TokenStream) let mut #ident = #empty; }; let alloc = quote! { - let mut #ident = #elem_ident::#fn_ident(cs, witness.as_ref().map(|w| w.#ident.clone()))?; + let mut #ident = #elem_ident::#fn_ident(cs, witness.as_ref().map(|w| w.#ident.clone()))?; // TODO w.#ident.clone() need for BigUint }; (empty, alloc) diff --git a/cs_derive/src/new_select.rs b/cs_derive/src/new_select.rs index 8c4e425..f10ff3d 100644 --- a/cs_derive/src/new_select.rs +++ b/cs_derive/src/new_select.rs @@ -103,6 +103,7 @@ pub(crate) fn derive_select(input: proc_macro::TokenStream) -> proc_macro::Token }; let expanded = quote! { + // TODO: generics may not have Engine, impl#generics CircuitSelectable for #ident<#type_params_of_allocated_struct>{ fn conditionally_select#function_generics(cs: &mut CS, flag: &Boolean, a: &Self, b: &Self) -> Result { if CircuitEq::eq(a, b) { diff --git a/cs_derive/src/new_witness.rs b/cs_derive/src/new_witness.rs index d9700ff..1b3546c 100644 --- a/cs_derive/src/new_witness.rs +++ b/cs_derive/src/new_witness.rs @@ -89,7 +89,7 @@ pub(crate) fn derive_witness_struct(derived_input: DeriveInput) -> DeriveInput { let witness_ident = get_witness_ident(&ident); DeriveInput { - attrs: Vec::new(), + attrs: Vec::new(), // TODO: do we need to inherit original attributes or empty attrs is fine? vis: vis, ident: witness_ident, generics: new_generics, diff --git a/cs_derive/src/ord.rs b/cs_derive/src/ord.rs index 83f13cc..59aaafd 100644 --- a/cs_derive/src/ord.rs +++ b/cs_derive/src/ord.rs @@ -66,6 +66,7 @@ pub(crate) fn derive_ord(input: proc_macro::TokenStream) -> proc_macro::TokenStr get_type_params_from_generics(&generics, &comma, has_engine_param == false); let expanded = quote! { + // TODO: check generics has Engine param impl#generics CircuitOrd for #ident<#type_params_of_allocated_struct>{ fn cmp(&self, other: &Self) -> ::std::cmp::Ordering { // #array_equality_check diff --git a/cs_derive/src/orth_select.rs b/cs_derive/src/orth_select.rs index b587c28..b11d360 100644 --- a/cs_derive/src/orth_select.rs +++ b/cs_derive/src/orth_select.rs @@ -87,6 +87,7 @@ pub(crate) fn derive_orthogonal_select(input: proc_macro::TokenStream) -> proc_m }; let expanded = quote! { + // TODO: generics may not have Engine, impl#generics CircuitOrthogonalSelectable for #ident<#type_params_of_allocated_struct>{ fn select_update_assuming_orthogonality#function_generics(cs: &mut CS, reference: Self, candidates: &[(Boolean, Self)]) -> Result { // #array_selections diff --git a/cs_derive/src/select.rs b/cs_derive/src/select.rs index 6eab390..dc4d185 100644 --- a/cs_derive/src/select.rs +++ b/cs_derive/src/select.rs @@ -87,6 +87,7 @@ pub(crate) fn derive_select(input: proc_macro::TokenStream) -> proc_macro::Token }; let expanded = quote! { + // TODO: generics may not have Engine, impl#generics CircuitSelectable for #ident<#type_params_of_allocated_struct>{ fn conditionally_select#function_generics(cs: &mut CS, flag: &Boolean, a: &Self, b: &Self) -> Result { #array_selections diff --git a/cs_derive/src/utils.rs b/cs_derive/src/utils.rs index 5e3cd40..bfa7577 100644 --- a/cs_derive/src/utils.rs +++ b/cs_derive/src/utils.rs @@ -58,7 +58,7 @@ pub(crate) fn get_equivalent_type(original_ty: &Type) -> (Type, Option { let (new_ty, type_param) = find_in_equivalent_types(ty); diff --git a/cs_derive/src/witness.rs b/cs_derive/src/witness.rs index b1ea51d..e7d88d4 100644 --- a/cs_derive/src/witness.rs +++ b/cs_derive/src/witness.rs @@ -164,7 +164,7 @@ pub(crate) fn derive_witness_struct(derived_input: DeriveInput) -> DeriveInput { let witness_ident = get_witness_ident(&ident); DeriveInput { - attrs: Vec::new(), + attrs: Vec::new(), // TODO: do we need to inherit original attributes or empty attrs is fine? vis: vis, ident: witness_ident, generics: new_generics, diff --git a/src/circuit_structures/mod.rs b/src/circuit_structures/mod.rs index b4e0cd1..0ba2445 100644 --- a/src/circuit_structures/mod.rs +++ b/src/circuit_structures/mod.rs @@ -260,6 +260,7 @@ impl SmallFixedWidthInteger { self.value.clone() } + // TODO: does it contain a vulnerability? pub fn speculative_add>( &self, cs: &mut CS, diff --git a/src/circuit_structures/utils.rs b/src/circuit_structures/utils.rs index 86c6db2..4d6d9ae 100644 --- a/src/circuit_structures/utils.rs +++ b/src/circuit_structures/utils.rs @@ -28,6 +28,7 @@ pub fn can_not_be_false_if_flagged>( _ => {} } + // TODO: we can trivially optimize here let invalid = Boolean::and(cs, &condition.not(), &condition_must_be_valid)?; Boolean::enforce_equal(cs, &invalid, &Boolean::constant(false))?; diff --git a/src/glue/ecdsa/recover.rs b/src/glue/ecdsa/recover.rs index d1fcd49..baedec1 100644 --- a/src/glue/ecdsa/recover.rs +++ b/src/glue/ecdsa/recover.rs @@ -213,6 +213,7 @@ impl<'a, E: Engine, G: GenericCurveAffine, const N: usize> ECRecoverContext<'a, Ok(valid) } + // TODO: we mix generics here a little, move to another implementation block pub fn verify_for_ethereum_address>( &mut self, cs: &mut CS, diff --git a/src/glue/keccak256_round_function_circuit/mod.rs b/src/glue/keccak256_round_function_circuit/mod.rs index bb888c6..0fc6e94 100644 --- a/src/glue/keccak256_round_function_circuit/mod.rs +++ b/src/glue/keccak256_round_function_circuit/mod.rs @@ -2,7 +2,6 @@ use super::*; use crate::precompiles::keccak256::*; use crate::precompiles::*; use cs_derive::*; -use zk_evm::precompiles::keccak256::BUFFER_SIZE; pub mod input; diff --git a/src/glue/optimizable_queue/witness_queue.rs b/src/glue/optimizable_queue/witness_queue.rs index d2fd222..31b75e6 100644 --- a/src/glue/optimizable_queue/witness_queue.rs +++ b/src/glue/optimizable_queue/witness_queue.rs @@ -85,6 +85,8 @@ impl + FixedLengthDecodable, cons _round_function: &R, ) -> E::Fr { unimplemented!(); + // TODO + // round_function.simulate_absorb_multiple_rounds_into_empty_with_specialization(&input).last().expect("intermediate state")[0] } pub fn get_tail_state(&self) -> E::Fr { diff --git a/src/glue/sponge_like_optimizable_queue/mod.rs b/src/glue/sponge_like_optimizable_queue/mod.rs index f2a3470..b53bff4 100644 --- a/src/glue/sponge_like_optimizable_queue/mod.rs +++ b/src/glue/sponge_like_optimizable_queue/mod.rs @@ -119,6 +119,8 @@ impl, const N: usize, const S // state = hash(state, item) // but as state = absorb(state, item) +// TODO: check later on the replacement mode of the sponge + #[derive(Derivative)] #[derivative(Clone, Debug)] pub struct FixedWidthEncodingSpongeLikeQueue< diff --git a/src/precompiles/keccak256.rs b/src/precompiles/keccak256.rs index c09883d..7593948 100644 --- a/src/precompiles/keccak256.rs +++ b/src/precompiles/keccak256.rs @@ -116,14 +116,14 @@ fn transmute_state(reference_state: sha3::Keccak256) -> Keccak256InnerState { pub struct KeccakSelfVerifier { internal_state: sha3::Keccak256, - buffer: zk_evm::precompiles::keccak256::Buffer, + buffer: zk_evm::zk_evm_abstractions::precompiles::keccak256::Buffer, } impl KeccakSelfVerifier { pub fn new() -> Self { Self { internal_state: sha3::Keccak256::new(), - buffer: zk_evm::precompiles::keccak256::Buffer::new(), + buffer: zk_evm::zk_evm_abstractions::precompiles::keccak256::Buffer::new(), } } pub fn reset(&mut self) { @@ -168,7 +168,7 @@ impl KeccakSelfVerifier { } self.internal_state.update(&tmp); let internal_state_raw = - zk_evm::precompiles::keccak256::transmute_state(self.internal_state.clone()); + zk_evm::zk_evm_abstractions::precompiles::keccak256::transmute_state(self.internal_state.clone()); internal_state_raw } diff --git a/src/scheduler/data_access_functions/mod.rs b/src/scheduler/data_access_functions/mod.rs index 5a1b720..7a93be5 100644 --- a/src/scheduler/data_access_functions/mod.rs +++ b/src/scheduler/data_access_functions/mod.rs @@ -351,6 +351,8 @@ impl StorageWitnessHelper { // let address_as_u256 = address_to_u256(cs, &deployer)?; // let shifts = compute_shifts::(); +// // TODO: cleanup into high and low + // let mut lc = LinearCombination::zero(); // lc.add_assign_number_with_coeff(&address_as_u256.inner[0].inner, shifts[0]); // lc.add_assign_number_with_coeff(&address_as_u256.inner[1].inner, shifts[64]); diff --git a/src/vm/structural_eq.rs b/src/vm/structural_eq.rs index e0c0c9f..0641174 100644 --- a/src/vm/structural_eq.rs +++ b/src/vm/structural_eq.rs @@ -502,6 +502,7 @@ impl CircuitOrthogonalSelectable for Boolean { }; for (flags, value) in it { let flag = smart_or(cs, &flags)?; + // TODO: implement accumulation for booleans new = Boolean::conditionally_select(cs, &flag, &value, &new)?; } diff --git a/src/vm/vm_cycle/opcode_execution/uma.rs b/src/vm/vm_cycle/opcode_execution/uma.rs index 86efbff..55d3290 100644 --- a/src/vm/vm_cycle/opcode_execution/uma.rs +++ b/src/vm/vm_cycle/opcode_execution/uma.rs @@ -64,8 +64,6 @@ impl QuasiFatPtrInUMA { let (incremented_offset, incremented_offset_of) = offset.add_using_delayed_bool_allocation(cs, &UInt32::from_uint(32), optimizer)?; - // let ignore_reg_updates_due_to_invalid_increment = - // smart_and(cs, &[incremented_offset_of, should_increment])?; let ignore_reg_updates_due_to_invalid_increment = incremented_offset_of; let should_set_panic = smart_or( @@ -816,6 +814,8 @@ pub(crate) fn apply< } } + // TODO: we can make aligned writes to be 1 cycle too + let mut all_sponge_requests = vec![]; all_sponge_requests.extend(sponge_requests_for_read); all_sponge_requests.extend(sponge_requests_for_write);