diff --git a/core/lib/circuit/src/allocated_structures.rs b/core/lib/circuit/src/allocated_structures.rs index 79bc721de9..ac26a4e38b 100644 --- a/core/lib/circuit/src/allocated_structures.rs +++ b/core/lib/circuit/src/allocated_structures.rs @@ -292,25 +292,41 @@ impl AllocatedOperationData { mut cs: CS, op: &Operation, ) -> Result, SynthesisError> { + macro_rules! parse_circuit_elements { + ($element:ident, $len:expr) => { + let $element = op + .args + .$element + .iter() + .enumerate() + .map(|(idx, item)| { + CircuitElement::from_fe_with_known_length( + cs.namespace(|| { + format!("{} item with index {}", stringify!($element), idx) + }), + || item.grab(), + $len, + ) + }) + .collect::, SynthesisError>>()?; + }; + } + let eth_address = CircuitElement::from_fe_with_known_length( cs.namespace(|| "eth_address"), || op.args.eth_address.grab(), franklin_constants::ETH_ADDRESS_BIT_WIDTH, )?; - let special_content_hash = op - .args - .special_content_hash - .iter() - .enumerate() - .map(|(idx, special_content_hash_bit)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_content_hash bit with index {}", idx)), - || special_content_hash_bit.grab(), - 1, - ) - }) - .collect::, SynthesisError>>()?; + parse_circuit_elements!(special_content_hash, 1); + parse_circuit_elements!(special_tokens, franklin_constants::TOKEN_BIT_WIDTH); + parse_circuit_elements!(special_accounts, franklin_constants::ACCOUNT_ID_BIT_WIDTH); + parse_circuit_elements!(special_nonces, franklin_constants::NONCE_BIT_WIDTH); + parse_circuit_elements!(special_prices, franklin_constants::PRICE_BIT_WIDTH); + parse_circuit_elements!( + special_eth_addresses, + franklin_constants::ETH_ADDRESS_BIT_WIDTH + ); let special_serial_id = CircuitElement::from_fe_with_known_length( cs.namespace(|| "special_serial_id"), @@ -332,76 +348,6 @@ impl AllocatedOperationData { op.args.second_amount_packed, )?; - let special_tokens = op - .args - .special_tokens - .iter() - .enumerate() - .map(|(idx, special_token)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_token with index {}", idx)), - || special_token.grab(), - franklin_constants::TOKEN_BIT_WIDTH, - ) - }) - .collect::, _>>()?; - - let special_eth_addresses = op - .args - .special_eth_addresses - .iter() - .enumerate() - .map(|(idx, special_token)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_eth_address with index {}", idx)), - || special_token.grab(), - franklin_constants::ETH_ADDRESS_BIT_WIDTH, - ) - }) - .collect::, _>>()?; - - let special_accounts = op - .args - .special_accounts - .iter() - .enumerate() - .map(|(idx, special_account_id)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_account_id with index {}", idx)), - || special_account_id.grab(), - franklin_constants::ACCOUNT_ID_BIT_WIDTH, - ) - }) - .collect::, _>>()?; - - let special_nonces = op - .args - .special_nonces - .iter() - .enumerate() - .map(|(idx, special_nonce)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_nonce with index {}", idx)), - || special_nonce.grab(), - franklin_constants::NONCE_BIT_WIDTH, - ) - }) - .collect::, _>>()?; - - let special_prices = op - .args - .special_prices - .iter() - .enumerate() - .map(|(idx, special_price)| { - CircuitElement::from_fe_with_known_length( - cs.namespace(|| format!("special_price with index {}", idx)), - || special_price.grab(), - franklin_constants::PRICE_BIT_WIDTH, - ) - }) - .collect::, _>>()?; - let (special_amounts_packed, special_amounts_unpacked) = op .args .special_amounts diff --git a/core/lib/circuit/src/circuit.rs b/core/lib/circuit/src/circuit.rs index 39f6e4a0a3..0d986ca1ad 100644 --- a/core/lib/circuit/src/circuit.rs +++ b/core/lib/circuit/src/circuit.rs @@ -1179,8 +1179,6 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { self.swap( cs.namespace(|| "swap"), &mut cur, - &lhs, - &rhs, global_variables, &is_a_geq_b, &is_account_empty, @@ -2996,8 +2994,6 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { &self, mut cs: CS, cur: &mut AllocatedOperationBranch, - lhs: &AllocatedOperationBranch, - _rhs: &AllocatedOperationBranch, global_variables: &CircuitGlobalVariables, is_a_geq_b: &Boolean, is_account_empty: &Boolean, @@ -3014,6 +3010,15 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { !pubdata_holder.is_empty(), "pubdata holder has to be preallocated" ); + /* + fields specification: + + special_eth_addresses = [recipient_0_address, recipient_1_address] + special_tokens = [order_0_sell_token, order_1_sell_token, fee_token] + special_accounts = [order_0_sell_amount, order_1_sell_amount] + special_prices = [order_0_sell_price, order_0_buy_price, order_1_sell_price, order_1_buy_price] + special_nonces = [account_0_nonce, account_1_nonce, submitter_nonce] + */ // construct pubdata let mut pubdata_bits = vec![]; @@ -3191,7 +3196,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { .map(|num| { let nonce_correct = CircuitElement::equals( cs.namespace(|| format!("is_nonce_correct_in_slot {}", num)), - &lhs.account.nonce, + &cur.account.nonce, &op_data.special_nonces[num], )?; Boolean::and( @@ -3519,7 +3524,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { let is_signer_valid = CircuitElement::equals( cs.namespace(|| "signer_key_correct"), &signer_key.pubkey.get_hash(), - &lhs.account.pub_key_hash, + &cur.account.pub_key_hash, )?; let lhs_valid_flags = vec![ @@ -3559,7 +3564,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> { let sender_is_submitter = CircuitElement::equals( cs.namespace(|| "is account sender == submitter"), - &lhs.account_id, + &cur.account_id, &op_data.special_accounts[4], )?;