Skip to content

Commit 22dee75

Browse files
TomAFrenchphatedsirasistantvezenovmkevaundray
authored
chore!: update to ACVM 0.13.0 (#1393)
* chore!: Update to ACVM 0.12.0 * feat: adapted to heterogeneous bb calls * chore: update cargo tomls * test: re enabled sort test * fix: improve variable resolution * feat: use dummy constructor for bb call * updates for latest * feat!: Move WitnessMap type into ACVM to avoid leaking BTreeMap type * feat(nargo): Consume CommonReferenceString functions & manage caching (#1348) * switch to published acvm and backend * fix compilation issue * chore: Remove usage of `acvm::default_is_opcode_supported` (#1366) Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com> Co-authored-by: Tom French <tom@tomfren.ch> * add issue numbers to TODOs * chore: update to ACVM 0.13.0 * chore: fix broken import * chore: bump commit * chore: Update Acvm 0.13.0 branch (#1465) have acvm-backend-bberg patch reference new branch with additional crate-type * Update Cargo.toml * Update Cargo.toml * update flake.lock * feat!: var message size for keccak in stdlib (#1481) * Var message size for keccak in stdlib * fix the build: remove aes blackbox add domain separator for pedersen * pedersen with domain separator * chore: update pedersen test case for domain separator (#1482) pedersen with domain separator * chore: add pedersen hash with domain separator in stdlib (#1483) * pedersen with domain separator * separator for pedersen * update to acvm 0.13.0 and new acvm-backend-bberg * update cargo lock * update MockBackend in sort test * update merkle_insert and simple_shield for updated pedersen in bberg * try ubuntu-large * remove patch and update to acvm-backend-bberg 0.3.0 * cargo.lock --------- Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com> Co-authored-by: sirasistant <sirasistant@gmail.com> Co-authored-by: Maxim Vezenov <mvezenov@gmail.com> Co-authored-by: kevaundray <kevtheappdev@gmail.com> Co-authored-by: guipublic <47281315+guipublic@users.noreply.github.com>
1 parent f19ffd0 commit 22dee75

File tree

18 files changed

+609
-541
lines changed

18 files changed

+609
-541
lines changed

Cargo.lock

+543-409
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ edition = "2021"
2424
rust-version = "1.66"
2525

2626
[workspace.dependencies]
27-
acvm = "0.12.0"
27+
acvm = "0.13.0"
2828
arena = { path = "crates/arena" }
2929
fm = { path = "crates/fm" }
3030
iter-extended = { path = "crates/iter-extended" }

crates/nargo/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use acvm::OpcodeResolutionError;
1+
use acvm::pwg::OpcodeResolutionError;
22
use thiserror::Error;
33

44
#[derive(Debug, Error)]

crates/nargo_cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ color-eyre = "0.6.2"
3939
tokio = "1.0"
4040

4141
# Backends
42-
acvm-backend-barretenberg = { version = "0.2.0", default-features = false }
42+
acvm-backend-barretenberg = { version = "0.3.0", default-features = false }
4343

4444
[dev-dependencies]
4545
tempdir = "0.3.7"

crates/nargo_cli/src/cli/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod tests {
129129
let mut driver = Driver::new(
130130
&acvm::Language::R1CS,
131131
#[allow(deprecated)]
132-
Box::new(acvm::default_is_opcode_supported(acvm::Language::R1CS)),
132+
Box::new(acvm::pwg::default_is_opcode_supported(acvm::Language::R1CS)),
133133
);
134134
driver.create_local_crate(&root_file, CrateType::Binary);
135135
crate::resolver::add_std_lib(&mut driver);

crates/nargo_cli/tests/test_data/keccak256/src/main.nr

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ use dep::std;
55
fn main(x: Field, result: [u8; 32]) {
66
// We use the `as` keyword here to denote the fact that we want to take just the first byte from the x Field
77
// The padding is taken care of by the program
8-
let digest = std::hash::keccak256([x as u8]);
8+
let digest = std::hash::keccak256([x as u8], 1);
99
assert(digest == result);
10+
11+
//#1399: variable meesage size
12+
let message_size = 4;
13+
let hash_a = std::hash::keccak256([1,2,3,4], message_size);
14+
let hash_b = std::hash::keccak256([1,2,3,4,0,0,0,0], message_size);
15+
16+
assert(hash_a == hash_b);
17+
18+
let message_size_big = 8;
19+
let hash_c = std::hash::keccak256([1,2,3,4,0,0,0,0], message_size_big);
20+
21+
assert(hash_a != hash_c);
1022
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
old_root = "0x04ccfbbb859b8605546e03dcaf41393476642859ff7f99446c054b841f0e05c8"
1+
old_root = "0x285785b10eca49cf456b935f1c9787ff571f306c1bc62549c31a9199a633f9f8"
22
old_leaf = "0x1cdcf02431ba623767fe389337d011df1048dcc24b98ed81cec97627bab454a0"
33
old_hash_path = [
44
"0x1cdcf02431ba623767fe389337d011df1048dcc24b98ed81cec97627bab454a0",
55
"0x0b5e9666e7323ce925c28201a97ddf4144ac9d148448ed6f49f9008719c1b85b",
66
"0x22ec636f8ad30ef78c42b7fe2be4a4cacf5a445cfb5948224539f59a11d70775",
77
]
8-
new_root = "0x293ee9de893904164a8f8b248b6941217d16a4c9042ec54b71896dddbbce7a3b"
8+
new_root = "0x2d05c2650e6c2ef02c6dc7fae7f517b8ac191386666c0b5a68130a8c11092f5f"
99
leaf = "0x085ca53be9c9d95b57e6e5fc91c5d531ad9e63e85dd71af7e35562991774b435"
1010
index = "0"
1111
mimc_input = [12,45,78,41]

crates/nargo_cli/tests/test_data/pedersen_check/Prover.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ x = "0"
22
y = "1"
33
salt = "42"
44

5-
out_x = "0x11831f49876c313f2a9ec6d8d521c7ce0b6311c852117e340bfe27fd1ac096ef"
6-
out_y = "0x0ecf9d98be4597a88c46a7e0fa8836b57a7dcb41ee30f8d8787b11cc259c83fa"
5+
out_x = "0x0c5e1ddecd49de44ed5e5798d3f6fb7c71fe3d37f5bee8664cf88a445b5ba0af"
6+
out_y = "0x230294a041e26fe80b827c2ef5cb8784642bbaa83842da2714d62b1f3c4f9752"

crates/nargo_cli/tests/test_data/simple_shield/Prover.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Random test key
22
priv_key = "0x000000000000000000000000000000000000000000000000000000616c696365"
3-
note_root = "0x293ee9de893904164a8f8b248b6941217d16a4c9042ec54b71896dddbbce7a3b"
3+
note_root = "0x21386402d57460963f45f32577dc3902c38a6f6fab9ec7b1b708a92e48745de7"
44
index = "0"
55
note_hash_path = [
66
"0x1cdcf02431ba623767fe389337d011df1048dcc24b98ed81cec97627bab454a0",

crates/noirc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,6 @@ impl Driver {
346346
impl Default for Driver {
347347
fn default() -> Self {
348348
#[allow(deprecated)]
349-
Self::new(&Language::R1CS, Box::new(acvm::default_is_opcode_supported(Language::R1CS)))
349+
Self::new(&Language::R1CS, Box::new(acvm::pwg::default_is_opcode_supported(Language::R1CS)))
350350
}
351351
}

crates/noirc_driver/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
let mut driver = Driver::new(
1010
&Language::R1CS,
1111
#[allow(deprecated)]
12-
Box::new(acvm::default_is_opcode_supported(Language::R1CS)),
12+
Box::new(acvm::pwg::default_is_opcode_supported(Language::R1CS)),
1313
);
1414

1515
// Add local crate to dep graph

crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ pub(crate) fn evaluate(
9292
}
9393
BlackBoxFunc::SchnorrVerify
9494
| BlackBoxFunc::EcdsaSecp256k1
95-
| BlackBoxFunc::ComputeMerkleRoot
9695
| BlackBoxFunc::HashToField128Security => {
9796
prepare_outputs(&mut acir_gen.memory, instruction_id, 1, ctx, evaluator)
9897
}
@@ -107,14 +106,29 @@ pub(crate) fn evaluate(
107106
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
108107
outputs: outputs.to_vec(),
109108
},
110-
BlackBoxFunc::Keccak256 => BlackBoxFuncCall::Keccak256 {
111-
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
112-
outputs: outputs.to_vec(),
113-
},
114-
BlackBoxFunc::Pedersen => BlackBoxFuncCall::Pedersen {
115-
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
116-
outputs: outputs.to_vec(),
117-
},
109+
BlackBoxFunc::Keccak256 => {
110+
let msg_size = acir_gen
111+
.var_cache
112+
.get_or_compute_internal_var(args[1], evaluator, ctx)
113+
.expect("ICE - could not get an expression for keccak message size");
114+
let witness =
115+
acir_gen.var_cache.get_or_compute_witness_unwrap(msg_size, evaluator, ctx);
116+
let var_message_size = FunctionInput { witness, num_bits: 32 };
117+
BlackBoxFuncCall::Keccak256VariableLength {
118+
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
119+
var_message_size,
120+
outputs: outputs.to_vec(),
121+
}
122+
}
123+
BlackBoxFunc::Pedersen => {
124+
let separator =
125+
ctx.get_as_constant(args[1]).expect("domain separator to be comptime");
126+
BlackBoxFuncCall::Pedersen {
127+
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
128+
outputs: outputs.to_vec(),
129+
domain_separator: separator.to_u128() as u32,
130+
}
131+
}
118132
BlackBoxFunc::FixedBaseScalarMul => BlackBoxFuncCall::FixedBaseScalarMul {
119133
input: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(),
120134
outputs: outputs.to_vec(),
@@ -133,12 +147,6 @@ pub(crate) fn evaluate(
133147
hashed_message: resolve_array(&args[3], acir_gen, ctx, evaluator),
134148
output: outputs[0],
135149
},
136-
BlackBoxFunc::ComputeMerkleRoot => BlackBoxFuncCall::ComputeMerkleRoot {
137-
leaf: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(),
138-
index: resolve_variable(&args[1], acir_gen, ctx, evaluator).unwrap(),
139-
hash_path: resolve_array(&args[2], acir_gen, ctx, evaluator),
140-
output: outputs[0],
141-
},
142150
BlackBoxFunc::HashToField128Security => BlackBoxFuncCall::HashToField128Security {
143151
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
144152
output: outputs[0],

crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs

+6-88
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ fn permutation_layer(
115115
mod test {
116116
use acvm::{
117117
acir::{circuit::opcodes::FunctionInput, native_types::Witness, native_types::WitnessMap},
118-
pwg::{block::Blocks, solve, OpcodeResolution, PartialWitnessGeneratorStatus},
119-
FieldElement, OpcodeResolutionError, PartialWitnessGenerator,
118+
pwg::{
119+
block::Blocks, solve, OpcodeResolution, OpcodeResolutionError,
120+
PartialWitnessGeneratorStatus,
121+
},
122+
FieldElement, PartialWitnessGenerator,
120123
};
121124

122125
use crate::{
@@ -127,65 +130,6 @@ mod test {
127130

128131
struct MockBackend {}
129132
impl PartialWitnessGenerator for MockBackend {
130-
fn aes(
131-
&self,
132-
_initial_witness: &mut WitnessMap,
133-
_inputs: &[FunctionInput],
134-
_outputs: &[Witness],
135-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
136-
panic!("Path not trodden by this test")
137-
}
138-
fn and(
139-
&self,
140-
_initial_witness: &mut WitnessMap,
141-
_lhs: &FunctionInput,
142-
_rhs: &FunctionInput,
143-
_output: &Witness,
144-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
145-
panic!("Path not trodden by this test")
146-
}
147-
fn xor(
148-
&self,
149-
_initial_witness: &mut WitnessMap,
150-
_lhs: &FunctionInput,
151-
_rhs: &FunctionInput,
152-
_output: &Witness,
153-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
154-
panic!("Path not trodden by this test")
155-
}
156-
fn range(
157-
&self,
158-
_initial_witness: &mut WitnessMap,
159-
_input: &FunctionInput,
160-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
161-
panic!("Path not trodden by this test")
162-
}
163-
fn sha256(
164-
&self,
165-
_initial_witness: &mut WitnessMap,
166-
_inputs: &[FunctionInput],
167-
_outputs: &[Witness],
168-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
169-
panic!("Path not trodden by this test")
170-
}
171-
fn blake2s(
172-
&self,
173-
_initial_witness: &mut WitnessMap,
174-
_inputs: &[FunctionInput],
175-
_outputs: &[Witness],
176-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
177-
panic!("Path not trodden by this test")
178-
}
179-
fn compute_merkle_root(
180-
&self,
181-
_initial_witness: &mut WitnessMap,
182-
_leaf: &FunctionInput,
183-
_index: &FunctionInput,
184-
_hash_path: &[FunctionInput],
185-
_output: &Witness,
186-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
187-
panic!("Path not trodden by this test")
188-
}
189133
fn schnorr_verify(
190134
&self,
191135
_initial_witness: &mut WitnessMap,
@@ -201,29 +145,11 @@ mod test {
201145
&self,
202146
_initial_witness: &mut WitnessMap,
203147
_inputs: &[FunctionInput],
148+
_domain_separator: u32,
204149
_outputs: &[Witness],
205150
) -> Result<OpcodeResolution, OpcodeResolutionError> {
206151
panic!("Path not trodden by this test")
207152
}
208-
fn hash_to_field_128_security(
209-
&self,
210-
_initial_witness: &mut WitnessMap,
211-
_inputs: &[FunctionInput],
212-
_output: &Witness,
213-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
214-
panic!("Path not trodden by this test")
215-
}
216-
fn ecdsa_secp256k1(
217-
&self,
218-
_initial_witness: &mut WitnessMap,
219-
_public_key_x: &[FunctionInput],
220-
_public_key_y: &[FunctionInput],
221-
_signature: &[FunctionInput],
222-
_message: &[FunctionInput],
223-
_output: &Witness,
224-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
225-
panic!("Path not trodden by this test")
226-
}
227153
fn fixed_base_scalar_mul(
228154
&self,
229155
_initial_witness: &mut WitnessMap,
@@ -232,14 +158,6 @@ mod test {
232158
) -> Result<OpcodeResolution, OpcodeResolutionError> {
233159
panic!("Path not trodden by this test")
234160
}
235-
fn keccak256(
236-
&self,
237-
_initial_witness: &mut WitnessMap,
238-
_inputs: &[FunctionInput],
239-
_outputs: &[Witness],
240-
) -> Result<OpcodeResolution, OpcodeResolutionError> {
241-
panic!("Path not trodden by this test")
242-
}
243161
}
244162

245163
// Check that a random network constrains its output to be a permutation of any random input

crates/noirc_evaluator/src/ssa/builtin.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ impl Opcode {
7979
| BlackBoxFunc::FixedBaseScalarMul => BigUint::zero(),
8080
// Verify returns zero or one
8181
BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => BigUint::one(),
82-
BlackBoxFunc::ComputeMerkleRoot | BlackBoxFunc::HashToField128Security => {
83-
ObjectType::native_field().max_size()
84-
}
85-
BlackBoxFunc::AES => {
86-
todo!("ICE: AES is unimplemented")
87-
}
82+
BlackBoxFunc::HashToField128Security => ObjectType::native_field().max_size(),
8883
BlackBoxFunc::RANGE | BlackBoxFunc::AND | BlackBoxFunc::XOR => {
8984
unimplemented!("ICE: these opcodes do not have Noir builtin functions")
9085
}
@@ -102,13 +97,10 @@ impl Opcode {
10297
match self {
10398
Opcode::LowLevel(op) => {
10499
match op {
105-
BlackBoxFunc::AES => todo!("ICE: AES is unimplemented"),
106100
BlackBoxFunc::SHA256 | BlackBoxFunc::Blake2s | BlackBoxFunc::Keccak256 => {
107101
(32, ObjectType::unsigned_integer(8))
108102
}
109-
BlackBoxFunc::ComputeMerkleRoot | BlackBoxFunc::HashToField128Security => {
110-
(1, ObjectType::native_field())
111-
}
103+
BlackBoxFunc::HashToField128Security => (1, ObjectType::native_field()),
112104
// See issue #775 on changing this to return a boolean
113105
BlackBoxFunc::SchnorrVerify | BlackBoxFunc::EcdsaSecp256k1 => {
114106
(1, ObjectType::native_field())

crates/wasm/src/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn compile(args: JsValue) -> JsValue {
7979
let mut driver = noirc_driver::Driver::new(
8080
&language,
8181
#[allow(deprecated)]
82-
Box::new(acvm::default_is_opcode_supported(language.clone())),
82+
Box::new(acvm::pwg::default_is_opcode_supported(language.clone())),
8383
);
8484

8585
let path = PathBuf::from(&options.entry_point);

flake.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

noir_stdlib/src/hash.nr

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ fn sha256<N>(_input : [u8; N]) -> [u8; 32] {}
66
#[foreign(blake2s)]
77
fn blake2s<N>(_input : [u8; N]) -> [u8; 32] {}
88

9+
fn pedersen<N>(input : [Field; N]) -> [Field; 2] {
10+
pedersen_with_separator(input, 0)
11+
}
12+
913
#[foreign(pedersen)]
10-
fn pedersen<N>(_input : [Field; N]) -> [Field; 2] {}
14+
fn pedersen_with_separator<N>(_input : [Field; N], _separator : comptime u32) -> [Field; 2] {}
1115

1216
#[foreign(hash_to_field_128_security)]
1317
fn hash_to_field<N>(_input : [Field; N]) -> Field {}
1418

1519
#[foreign(keccak256)]
16-
fn keccak256<N>(_input : [u8; N]) -> [u8; 32] {}
20+
fn keccak256<N>(_input : [u8; N], _message_size: u32) -> [u8; 32] {}
1721

1822
// mimc-p/p implementation
1923
// constants are (publicly generated) random numbers, for instance using keccak as a ROM.

noir_stdlib/src/merkle.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ fn compute_merkle_root(leaf: Field, index: Field, hash_path: [Field]) -> Field {
1818
current = crate::hash::pedersen([hash_left, hash_right])[0];
1919
};
2020
current
21-
}
21+
}

0 commit comments

Comments
 (0)