From c39987c595a5521b68693557107d07575f5dffff Mon Sep 17 00:00:00 2001 From: sirasistant Date: Thu, 1 Jun 2023 09:39:55 +0000 Subject: [PATCH] feat: update acvm pointer --- Cargo.lock | 15 ++++++----- Cargo.toml | 4 +-- src/acvm_interop/proof_system.rs | 2 -- src/acvm_interop/pwg.rs | 14 ++-------- src/barretenberg_structures.rs | 44 +++++++++++++++++++++++++++++--- src/lib.rs | 3 --- 6 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5650c3da..667f7aa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ version = 3 [[package]] name = "acir" version = "0.12.0" -source = "git+https://github.com/noir-lang/acvm?rev=3c6740af75125afc8ebb4379f781f8274015e2e2#3c6740af75125afc8ebb4379f781f8274015e2e2" +source = "git+https://github.com/noir-lang/acvm?rev=1bd8b981a865a8eea6460721c2526857d7241641#1bd8b981a865a8eea6460721c2526857d7241641" dependencies = [ "acir_field", "brillig_vm", @@ -18,7 +18,7 @@ dependencies = [ [[package]] name = "acir_field" version = "0.12.0" -source = "git+https://github.com/noir-lang/acvm?rev=3c6740af75125afc8ebb4379f781f8274015e2e2#3c6740af75125afc8ebb4379f781f8274015e2e2" +source = "git+https://github.com/noir-lang/acvm?rev=1bd8b981a865a8eea6460721c2526857d7241641#1bd8b981a865a8eea6460721c2526857d7241641" dependencies = [ "ark-bn254", "ark-ff", @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "acvm" version = "0.12.0" -source = "git+https://github.com/noir-lang/acvm?rev=3c6740af75125afc8ebb4379f781f8274015e2e2#3c6740af75125afc8ebb4379f781f8274015e2e2" +source = "git+https://github.com/noir-lang/acvm?rev=1bd8b981a865a8eea6460721c2526857d7241641#1bd8b981a865a8eea6460721c2526857d7241641" dependencies = [ "acir", "acvm_stdlib", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "acvm_stdlib" version = "0.12.0" -source = "git+https://github.com/noir-lang/acvm?rev=3c6740af75125afc8ebb4379f781f8274015e2e2#3c6740af75125afc8ebb4379f781f8274015e2e2" +source = "git+https://github.com/noir-lang/acvm?rev=1bd8b981a865a8eea6460721c2526857d7241641#1bd8b981a865a8eea6460721c2526857d7241641" dependencies = [ "acir", ] @@ -270,8 +270,9 @@ dependencies = [ [[package]] name = "barretenberg-sys" -version = "0.1.3" -source = "git+https://github.com/noir-lang/barretenberg-sys#c04e3f46e87c95a364c476bf8f0d310e994c5597" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f8fd58d1ca43e920a1a3b55d52c65ac25cd29f2820d4b2b1c24adafa2c403c" dependencies = [ "bindgen", "cc", @@ -365,7 +366,7 @@ dependencies = [ [[package]] name = "brillig_vm" version = "0.1.0" -source = "git+https://github.com/noir-lang/acvm?rev=3c6740af75125afc8ebb4379f781f8274015e2e2#3c6740af75125afc8ebb4379f781f8274015e2e2" +source = "git+https://github.com/noir-lang/acvm?rev=1bd8b981a865a8eea6460721c2526857d7241641#1bd8b981a865a8eea6460721c2526857d7241641" dependencies = [ "acir_field", "num-bigint", diff --git a/Cargo.toml b/Cargo.toml index 10e5ba00..c76b30a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ thiserror = "1.0.21" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] # Native -barretenberg-sys = { git = "https://github.com/noir-lang/barretenberg-sys", optional = true } +barretenberg-sys = { version = "0.2.0", optional = true } # Wasm getrandom = { version = "0.2", optional = true } @@ -67,4 +67,4 @@ wasm = [ ] [patch.crates-io] -acvm = { git = "https://github.com/noir-lang/acvm", rev = "3c6740af75125afc8ebb4379f781f8274015e2e2" } +acvm = { git = "https://github.com/noir-lang/acvm", rev = "1bd8b981a865a8eea6460721c2526857d7241641" } diff --git a/src/acvm_interop/proof_system.rs b/src/acvm_interop/proof_system.rs index ecef812f..b7f7d365 100644 --- a/src/acvm_interop/proof_system.rs +++ b/src/acvm_interop/proof_system.rs @@ -40,8 +40,6 @@ impl ProofSystemCompiler for Barretenberg { | BlackBoxFunc::HashToField128Security | BlackBoxFunc::EcdsaSecp256k1 | BlackBoxFunc::FixedBaseScalarMul => true, - - BlackBoxFunc::AES => false, }, } } diff --git a/src/acvm_interop/pwg.rs b/src/acvm_interop/pwg.rs index 3d820039..599d3dbe 100644 --- a/src/acvm_interop/pwg.rs +++ b/src/acvm_interop/pwg.rs @@ -10,17 +10,6 @@ use crate::schnorr::SchnorrSig; use crate::Barretenberg; impl PartialWitnessGenerator for Barretenberg { - fn aes( - &self, - _initial_witness: &mut WitnessMap, - _inputs: &[FunctionInput], - _outputs: &[Witness], - ) -> Result { - Err(OpcodeResolutionError::UnsupportedBlackBoxFunc( - BlackBoxFunc::AES, - )) - } - fn schnorr_verify( &self, initial_witness: &mut WitnessMap, @@ -113,6 +102,7 @@ impl PartialWitnessGenerator for Barretenberg { &self, initial_witness: &mut WitnessMap, inputs: &[FunctionInput], + domain_separator: u32, outputs: &[Witness], ) -> Result { let scalars: Result, _> = inputs @@ -121,7 +111,7 @@ impl PartialWitnessGenerator for Barretenberg { .collect(); let scalars: Vec<_> = scalars?.into_iter().cloned().collect(); - let (res_x, res_y) = self.encrypt(scalars, 0).map_err(|err| { + let (res_x, res_y) = self.encrypt(scalars, domain_separator).map_err(|err| { OpcodeResolutionError::BlackBoxFunctionFailed(BlackBoxFunc::Pedersen, err.to_string()) })?; initial_witness.insert(outputs[0], res_x); diff --git a/src/barretenberg_structures.rs b/src/barretenberg_structures.rs index 35bbf88a..f78cd598 100644 --- a/src/barretenberg_structures.rs +++ b/src/barretenberg_structures.rs @@ -748,7 +748,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { let mut blake2s_constraints: Vec = Vec::new(); let mut block_constraints: Vec = Vec::new(); let mut keccak_constraints: Vec = Vec::new(); - let keccak_var_constraints: Vec = Vec::new(); + let mut keccak_var_constraints: Vec = Vec::new(); let mut pedersen_constraints: Vec = Vec::new(); let mut schnorr_constraints: Vec = Vec::new(); let mut ecdsa_secp256k1_constraints: Vec = Vec::new(); @@ -910,6 +910,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { } BlackBoxFuncCall::Pedersen { inputs: gadget_call_inputs, + domain_separator, outputs, } => { let mut inputs = Vec::new(); @@ -924,7 +925,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { let constraint = PedersenConstraint { inputs, - hash_index: 0, + hash_index: *domain_separator, result_x, result_y, }; @@ -1062,8 +1063,43 @@ impl TryFrom<&Circuit> for ConstraintSystem { keccak_constraints.push(keccak_constraint); } - BlackBoxFuncCall::AES { .. } => { - return Err(Error::UnsupportedBlackBoxFunc(BlackBoxFunc::AES)) + BlackBoxFuncCall::Keccak256VariableLength { + inputs, + var_message_size, + outputs, + } => { + let mut keccak_inputs: Vec<(i32, i32)> = Vec::new(); + for input in inputs.iter() { + let witness_index = input.witness.witness_index() as i32; + let num_bits = input.num_bits as i32; + keccak_inputs.push((witness_index, num_bits)); + } + + let var_message_size = var_message_size.witness.witness_index() as i32; + + assert_eq!(outputs.len(), 32); + + let mut outputs_iter = outputs.iter(); + let mut result = [0i32; 32]; + for (i, res) in result.iter_mut().enumerate() { + let out_byte = + outputs_iter.next().ok_or_else(|| { + Error::MalformedBlackBoxFunc( + BlackBoxFunc::Keccak256, + format!("Missing rest of output. Tried to get byte {i} but failed"), + ) + })?; + + let out_byte_index = out_byte.witness_index() as i32; + *res = out_byte_index + } + let keccak_var_constraint = Keccak256VarConstraint { + inputs: keccak_inputs, + var_message_size, + result, + }; + + keccak_var_constraints.push(keccak_var_constraint); } }; } diff --git a/src/lib.rs b/src/lib.rs index 561da2df..96f9f8d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,9 +93,6 @@ enum Error { #[error("Malformed Black Box Function: {0} - {1}")] MalformedBlackBoxFunc(BlackBoxFunc, String), - #[error("Unsupported Black Box Function: {0}")] - UnsupportedBlackBoxFunc(BlackBoxFunc), - #[error(transparent)] FromFeature(#[from] FeatureError),