Skip to content

Commit

Permalink
v1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jules committed Jul 17, 2023
1 parent 4205618 commit 22d9d3a
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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 [[email protected]](mailto:[email protected]).

Thank you for your support in accelerating the mass adoption of crypto for personal sovereignty!
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sync_vm"
version = "1.3.2"
version = "1.3.3"
authors = ["Alex Vlasov <[email protected]>", "Konstantin Panarin <[email protected]>"]
edition = "2021"

Expand All @@ -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"]}

Expand All @@ -34,3 +34,6 @@ split-debuginfo = "unpacked"

[features]
external_testing = []



2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cs_derive/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cs_derive/src/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> for #ident<#type_params_of_allocated_struct>{
fn eq(&self, other: &Self) -> bool {
#array_equality_check
Expand Down
2 changes: 1 addition & 1 deletion cs_derive/src/new_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cs_derive/src/new_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> for #ident<#type_params_of_allocated_struct>{
fn conditionally_select#function_generics(cs: &mut CS, flag: &Boolean, a: &Self, b: &Self) -> Result<Self, SynthesisError> {
if CircuitEq::eq(a, b) {
Expand Down
2 changes: 1 addition & 1 deletion cs_derive/src/new_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cs_derive/src/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> for #ident<#type_params_of_allocated_struct>{
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
// #array_equality_check
Expand Down
1 change: 1 addition & 0 deletions cs_derive/src/orth_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> for #ident<#type_params_of_allocated_struct>{
fn select_update_assuming_orthogonality#function_generics(cs: &mut CS, reference: Self, candidates: &[(Boolean, Self)]) -> Result<Self, SynthesisError> {
// #array_selections
Expand Down
1 change: 1 addition & 0 deletions cs_derive/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E> for #ident<#type_params_of_allocated_struct>{
fn conditionally_select#function_generics(cs: &mut CS, flag: &Boolean, a: &Self, b: &Self) -> Result<Self, SynthesisError> {
#array_selections
Expand Down
2 changes: 1 addition & 1 deletion cs_derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn get_equivalent_type(original_ty: &Type) -> (Type, Option<GenericPa
let (new_ty, new_type_param) = get_equivalent_type(&ty.elem);
original_array_ty.elem = Box::from(new_ty);

(Type::Array(original_array_ty), new_type_param)
(Type::Array(original_array_ty), new_type_param) // TODO
}
Type::Path(ty) => {
let (new_ty, type_param) = find_in_equivalent_types(ty);
Expand Down
2 changes: 1 addition & 1 deletion cs_derive/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/circuit_structures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl<E: Engine, W: WidthMarker> SmallFixedWidthInteger<E, W> {
self.value.clone()
}

// TODO: does it contain a vulnerability?
pub fn speculative_add<CS: ConstraintSystem<E>>(
&self,
cs: &mut CS,
Expand Down
1 change: 1 addition & 0 deletions src/circuit_structures/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn can_not_be_false_if_flagged<E: Engine, CS: ConstraintSystem<E>>(
_ => {}
}

// 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))?;

Expand Down
1 change: 1 addition & 0 deletions src/glue/ecdsa/recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CS: ConstraintSystem<E>>(
&mut self,
cs: &mut CS,
Expand Down
1 change: 0 additions & 1 deletion src/glue/keccak256_round_function_circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/glue/optimizable_queue/witness_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ impl<E: Engine, I: FixedLengthEncodable<E, N> + FixedLengthDecodable<E, N>, 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 {
Expand Down
2 changes: 2 additions & 0 deletions src/glue/sponge_like_optimizable_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl<E: Engine, I: CircuitFixedLengthEncodableExt<E, N>, 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<
Expand Down
6 changes: 3 additions & 3 deletions src/precompiles/keccak256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions src/scheduler/data_access_functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ impl StorageWitnessHelper {
// let address_as_u256 = address_to_u256(cs, &deployer)?;
// let shifts = compute_shifts::<E::Fr>();

// // 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]);
Expand Down
1 change: 1 addition & 0 deletions src/vm/structural_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ impl<E: Engine> CircuitOrthogonalSelectable<E> 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)?;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vm/vm_cycle/opcode_execution/uma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ impl<E: Engine> QuasiFatPtrInUMA<E> {

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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 22d9d3a

Please sign in to comment.