From e75b2f87bc8e5e9184a4675b40282d8993226f82 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Thu, 4 Jul 2024 13:37:39 +0000 Subject: [PATCH 1/8] Enforce min_non_revertible_counter to be set if has public functions. --- .../split_to_public.nr | 7 +++---- .../src/private_kernel_tail_to_public.nr | 1 + .../split_to_public.nr | 20 ++++--------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer/split_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer/split_to_public.nr index 424cca62483..95a11b1b631 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer/split_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer/split_to_public.nr @@ -9,6 +9,8 @@ pub fn split_to_public( data: PrivateAccumulatedDataBuilder, min_revertible_side_effect_counter: u32 ) -> (PublicAccumulatedDataBuilder, PublicAccumulatedDataBuilder) { + assert(min_revertible_side_effect_counter != 0, "min_revertible_side_effect_counter must not be 0"); + let mut non_revertible_builder = PublicAccumulatedDataBuilder::empty(); let mut revertible_builder = PublicAccumulatedDataBuilder::empty(); @@ -26,10 +28,7 @@ pub fn split_to_public( } let nullifiers = data.nullifiers; - // First nullifier is always non-revertible. - let first_nullifier = nullifiers.get_unchecked(0).expose_to_public(); - non_revertible_builder.nullifiers.push(first_nullifier); - for i in 1..nullifiers.max_len() { + for i in 0..nullifiers.max_len() { if i < nullifiers.len() { let nullifier = nullifiers.get_unchecked(i); let public_nullifier = nullifier.expose_to_public(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index fe914554ef0..3c94d6c5c2f 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -60,6 +60,7 @@ mod tests { let mut previous_kernel = FixtureBuilder::new(); previous_kernel.tx_context.gas_settings.gas_limits = Gas::new(1_000_000, 1_000_000); previous_kernel.set_first_nullifier(); + previous_kernel.end_setup(); previous_kernel.push_public_call_request(1, false); PrivateKernelTailToPublicInputsBuilder { previous_kernel } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr index 1cb4c9d081d..d87bdfb6b70 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/tail_to_public_output_composer_builder/split_to_public.nr @@ -83,26 +83,14 @@ fn split_to_public_succeeds() { ); } -#[test] -fn split_to_public_zero_counter_succeeds() { +#[test(should_fail_with="min_revertible_side_effect_counter must not be 0")] +fn split_to_public_zero_counter_fails() { let mut builder = FixtureBuilder::new(); - builder.append_note_hashes(2); - builder.set_first_nullifier(); + builder.append_note_hashes(1); - let combined_data = builder.to_exposed_public_accumulated_data(); - let (non_revertible, revertible) = split_to_public( + let _ = split_to_public( builder.to_private_accumulated_data_builder(), builder.min_revertible_side_effect_counter ); - - // note_hashes - let expected = combined_data.note_hashes; - assert_array_eq(non_revertible.note_hashes.storage, []); - assert_array_eq(revertible.note_hashes.storage, [expected[0], expected[1]]); - - // nullifiers - let expected = combined_data.nullifiers; - assert_array_eq(non_revertible.nullifiers.storage, [expected[0]]); - assert_array_eq(revertible.nullifiers.storage, []); } From 73ab8878b7bc0407f9d7ad5c4fd7f37b873aafd3 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Thu, 4 Jul 2024 14:16:57 +0000 Subject: [PATCH 2/8] Check split private calls for every call. --- .../components/private_call_data_validator.nr | 37 +++--- .../validate_as_first_call.nr | 117 ------------------ .../validate_private_call_requests.nr | 117 ++++++++++++++++++ 3 files changed, 138 insertions(+), 133 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr index affec785a95..fd3da2a697c 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr @@ -121,17 +121,6 @@ impl PrivateCallDataValidator { let call_context = public_inputs.call_context; assert(call_context.is_delegate_call == false, "Users cannot make a delegatecall"); assert(call_context.is_static_call == false, "Users cannot make a static call"); - - let min_revertible_side_effect_counter = public_inputs.min_revertible_side_effect_counter; - let first_revertible_index = find_first_revertible_private_call_request_index(public_inputs); - // No need to check that the min_revertible_side_effect_counter falls in the counter range of the private call. - // It is valid as long as it does not fall in the middle of any nested call. - validate_split_ranges( - min_revertible_side_effect_counter, - first_revertible_index, - public_inputs.private_call_requests, - self.array_lengths.private_call_requests - ); } // Confirm that the TxRequest (user's intent) matches the private call being executed. @@ -263,18 +252,34 @@ impl PrivateCallDataValidator { } fn validate_private_call_requests(self) { - let call_requests = self.data.call_stack_item.public_inputs.private_call_requests; + let public_inputs = self.data.call_stack_item.public_inputs; + let call_requests = public_inputs.private_call_requests; let num_requests = self.array_lengths.private_call_requests; let mut should_check = true; for i in 0..call_requests.len() { should_check &= i != num_requests; if should_check { - validate_caller_context( - call_requests[i].caller_context, - self.data.call_stack_item.public_inputs.call_context - ); + validate_caller_context(call_requests[i].caller_context, public_inputs.call_context); } } + + // Check that the min_revertible_side_effect_counter does not fall in the middle of any nested calls. + // If it is possible, one can create a custom account contract, set the min_revertible_side_effect_counter to a + // value that falls in a transfer function, make the tx revert which then preserves the note hashes and discards + // the nullifiers. + // + // We don't have to use the aggregated min_revertible_side_effect_counter in the output for the below check. + // If the current call's min_revertible_side_effect_counter is 0, it means the counter might be set by another + // function. This check for that function guarantees that the counter won't fall into one of its nested calls. + // In this case, we can simply use 0 and make the following check pass. + let min_revertible_side_effect_counter = public_inputs.min_revertible_side_effect_counter; + let first_revertible_index = find_first_revertible_private_call_request_index(public_inputs); + validate_split_ranges( + min_revertible_side_effect_counter, + first_revertible_index, + public_inputs.private_call_requests, + self.array_lengths.private_call_requests + ); } fn validate_public_call_requests(self) { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_as_first_call.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_as_first_call.nr index cb2bdf3b886..9d7de6e0d58 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_as_first_call.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_as_first_call.nr @@ -1,23 +1,4 @@ use crate::tests::private_call_data_validator_builder::PrivateCallDataValidatorBuilder; -use dep::types::constants::MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL; - -impl PrivateCallDataValidatorBuilder { - pub fn new_first_call() -> Self { - PrivateCallDataValidatorBuilder::new_from_counter(0) - } - - pub fn split_calls(&mut self, counter: u32) { - self.private_call.min_revertible_side_effect_counter = counter; - } - - pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) { - let index = self.private_call.private_call_requests.len(); - self.private_call.append_private_call_requests(1); - self.private_call.private_call_requests.storage[index].call_request.start_side_effect_counter = counter_start; - self.private_call.private_call_requests.storage[index].call_request.end_side_effect_counter = counter_end; - self.private_call.counter = counter_end + 1; - } -} #[test] fn validate_as_first_call_regular_call_succeeds() { @@ -36,101 +17,3 @@ fn validate_as_first_call_delegate_call_fails() { let builder = PrivateCallDataValidatorBuilder::new().is_delegate_call(); builder.validate_as_first_call(); } - -/** - * Splitting call requests. - */ - -#[test] -fn validate_as_first_call_split_private_calls_succeeds() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - builder.split_calls(60); - builder.add_private_call_request(60, 70); - - builder.validate_as_first_call(); -} - -#[test] -fn validate_as_first_call_split_private_calls_empty_revertible_succeeds() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - builder.split_calls(51); - - builder.validate_as_first_call(); -} - -#[test] -fn validate_as_first_call_split_private_calls_empty_non_revertible_succeeds() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.split_calls(20); - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - - builder.validate_as_first_call(); -} - -#[test] -fn validate_as_first_call_split_private_calls_full_non_revertible_succeeds() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.private_call.append_private_call_requests(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); - builder.split_calls(builder.private_call.counter); - - builder.validate_as_first_call(); -} - -#[test] -fn validate_as_first_call_split_private_calls_less_than_first_revertible_success() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - // Tweak the counter to be less than the start counter of the first revertible call. - builder.split_calls(59); - builder.add_private_call_request(60, 70); - - builder.validate_as_first_call(); -} - -#[test(should_fail_with="min_revertible_side_effect_counter must be greater than the end counter of the last non revertible item")] -fn validate_as_first_call_split_private_calls_less_than_last_non_revertible_fails() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - // Tweak the counter to be less than the end counter of the last non-revertible call. - builder.split_calls(49); - builder.add_private_call_request(60, 70); - - builder.validate_as_first_call(); -} - -#[test(should_fail_with="min_revertible_side_effect_counter must be greater than the end counter of the last non revertible item")] -fn validate_as_first_call_split_private_calls_equal_last_non_revertible_fails() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - // Tweak the counter to equal the end counter of the last non-revertible call. - builder.split_calls(50); - - builder.validate_as_first_call(); -} - -#[test] -fn validate_as_first_call_split_private_calls_0_succeeds() { - let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); - - // Set the counter to be 0. - builder.split_calls(0); - builder.add_private_call_request(20, 30); - builder.add_private_call_request(40, 50); - - builder.validate_as_first_call(); -} diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr index 1a6a047d0b4..0393deb1af7 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_private_call_requests.nr @@ -1,4 +1,23 @@ use crate::tests::private_call_data_validator_builder::PrivateCallDataValidatorBuilder; +use dep::types::constants::MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL; + +impl PrivateCallDataValidatorBuilder { + pub fn new_first_call() -> Self { + PrivateCallDataValidatorBuilder::new_from_counter(0) + } + + pub fn split_calls(&mut self, counter: u32) { + self.private_call.min_revertible_side_effect_counter = counter; + } + + pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) { + let index = self.private_call.private_call_requests.len(); + self.private_call.append_private_call_requests(1); + self.private_call.private_call_requests.storage[index].call_request.start_side_effect_counter = counter_start; + self.private_call.private_call_requests.storage[index].call_request.end_side_effect_counter = counter_end; + self.private_call.counter = counter_end + 1; + } +} #[test] fn validate_private_call_requests_succeeds() { @@ -84,3 +103,101 @@ fn validate_private_call_requests_static_call_is_static_false_fails() { builder.validate(); } + +/** + * Splitting call requests. + */ + +#[test] +fn validate_private_call_requests_split_private_calls_succeeds() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + builder.split_calls(60); + builder.add_private_call_request(60, 70); + + builder.validate(); +} + +#[test] +fn validate_private_call_requests_split_private_calls_empty_revertible_succeeds() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + builder.split_calls(51); + + builder.validate(); +} + +#[test] +fn validate_private_call_requests_split_private_calls_empty_non_revertible_succeeds() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.split_calls(20); + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + + builder.validate(); +} + +#[test] +fn validate_private_call_requests_split_private_calls_full_non_revertible_succeeds() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.private_call.append_private_call_requests(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL); + builder.split_calls(builder.private_call.counter); + + builder.validate(); +} + +#[test] +fn validate_private_call_requests_split_private_calls_less_than_first_revertible_success() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + // Tweak the counter to be less than the start counter of the first revertible call. + builder.split_calls(59); + builder.add_private_call_request(60, 70); + + builder.validate(); +} + +#[test(should_fail_with="min_revertible_side_effect_counter must be greater than the end counter of the last non revertible item")] +fn validate_private_call_requests_split_private_calls_less_than_last_non_revertible_fails() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + // Tweak the counter to be less than the end counter of the last non-revertible call. + builder.split_calls(49); + builder.add_private_call_request(60, 70); + + builder.validate(); +} + +#[test(should_fail_with="min_revertible_side_effect_counter must be greater than the end counter of the last non revertible item")] +fn validate_private_call_requests_split_private_calls_equal_last_non_revertible_fails() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + // Tweak the counter to equal the end counter of the last non-revertible call. + builder.split_calls(50); + + builder.validate(); +} + +#[test] +fn validate_private_call_requests_split_private_calls_0_succeeds() { + let mut builder = PrivateCallDataValidatorBuilder::new_first_call(); + + // Set the counter to be 0. + builder.split_calls(0); + builder.add_private_call_request(20, 30); + builder.add_private_call_request(40, 50); + + builder.validate(); +} From 403ce4ba479c0df686f9125bc6e8d1bf7d2a5644 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Thu, 4 Jul 2024 16:01:53 +0000 Subject: [PATCH 3/8] Remove redundant check. --- ...t_split_sorted_transformed_value_arrays.nr | 71 ++++--------------- 1 file changed, 12 insertions(+), 59 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr index e977ad2fc03..6ca1ec6186f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_split_sorted_transformed_value_arrays.nr @@ -28,7 +28,7 @@ fn assert_split_sorted_transformed_value_arrays( let original = original_array[i]; let value = transformed_value_array[i]; let sorted_index = index_hints[i]; - let is_lt = (original.counter() < split_counter) | (original.counter() == 0); // If counter is 0, the value should always be in the lt(non-revertible) set. Currently this only applies to the first nullifier. + let is_lt = original.counter() < split_counter; let mut sorted_array = sorted_transformed_value_array_gte; let mut sorted_counters = sorted_counters_gte; let mut num = num_gte; @@ -272,50 +272,6 @@ mod tests { } } - pub fn with_zero_split_counter(&mut self) -> Self { - self.split_counter = 0; - - if self.ascending { - self.sorted_transformed_value_array_gte = [ - TestValue { name: 2, total: 27 }, - TestValue { name: 4, total: 49 }, - TestValue { name: 0, total: 1 }, - TestValue { name: 1, total: 16 }, - TestValue::empty(), - TestValue::empty(), - TestValue::empty(), - TestValue::empty() - ]; - self.hints = SplitOrderHints { - sorted_counters_lt: [0; 8], - sorted_counters_gte: [11, 22, 33, 44, 0, 0, 0, 0], - sorted_indexes: [2, 3, 0, 0, 1, 0, 0, 0] - }; - } else { - self.sorted_transformed_value_array_gte = [ - TestValue { name: 1, total: 16 }, - TestValue { name: 0, total: 1 }, - TestValue { name: 4, total: 49 }, - TestValue { name: 2, total: 27 }, - TestValue::empty(), - TestValue::empty(), - TestValue::empty(), - TestValue::empty() - ]; - self.hints = SplitOrderHints { - sorted_counters_lt: [0; 8], - sorted_counters_gte: [44, 33, 22, 11, 0, 0, 0, 0], - sorted_indexes: [1, 0, 3, 0, 2, 0, 0, 0], - }; - } - - self.sorted_transformed_value_array_lt = [TestValue::empty(); 8]; - // The item with 0 counter should always be in the _lt array. - self.sorted_transformed_value_array_lt[0] = TestValue { name: 3, total: 38 }; - - *self - } - pub fn update_sorted_index(&mut self, counter: u32, new_index: u32) { let mut original_index = original_array.len(); for i in 0..original_array.len() { @@ -354,17 +310,11 @@ mod tests { */ #[test] - fn assert_split_sorted_transformed_value_array_asc_non_zero_split_counter_succeeds() { + fn assert_split_sorted_transformed_value_array_asc_succeeds() { let builder = TestDataBuilder::new(); builder.execute(); } - #[test] - fn assert_split_sorted_transformed_value_array_asc_zero_split_counter_succeeds() { - let builder = TestDataBuilder::new().with_zero_split_counter(); - builder.execute(); - } - #[test] fn assert_split_sorted_transformed_value_array_asc_empty_succeeds() { let builder = TestDataBuilder::empty(); @@ -376,21 +326,24 @@ mod tests { */ #[test] - fn assert_split_sorted_transformed_value_array_desc_non_zero_split_counter_succeeds() { + fn assert_split_sorted_transformed_value_array_desc_succeeds() { let builder = TestDataBuilder::new_desc(); builder.execute(); } - #[test] - fn assert_split_sorted_transformed_value_array_desc_zero_split_counter_succeeds() { - let builder = TestDataBuilder::new_desc().with_zero_split_counter(); - builder.execute(); - } - /** * Failed cases. */ + #[test(should_fail_with="mismatch number of values lt")] + fn assert_split_sorted_transformed_value_array_asc_empty_extra_item_fails() { + let mut builder = TestDataBuilder::empty(); + + builder.sorted_transformed_value_array_lt[0].total = 1; + + builder.execute(); + } + #[test(should_fail_with="mismatch sorted values")] fn assert_split_sorted_transformed_value_array_asc_lt_wrong_sorted_value_fails() { let mut builder = TestDataBuilder::new(); From 834202ade253b1ae60ed7219c8d310e14de6edd7 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Thu, 4 Jul 2024 18:23:49 +0000 Subject: [PATCH 4/8] Remove redundant side effect counter in call context. --- barretenberg/cpp/pil/avm/constants_gen.pil | 22 +++++----- .../vm/avm_trace/aztec_constants.hpp | 28 ++++++------- .../src/core/libraries/ConstantsGen.sol | 40 +++++++++---------- .../aztec/src/context/private_context.nr | 3 +- .../oracle/enqueue_public_function_call.nr | 2 +- .../crates/types/src/abis/call_context.nr | 33 +-------------- .../types/src/abis/private_call_stack_item.nr | 2 +- .../src/abis/private_circuit_public_inputs.nr | 2 +- .../types/src/abis/public_call_stack_item.nr | 4 +- .../src/abis/public_circuit_public_inputs.nr | 2 +- .../crates/types/src/constants.nr | 4 +- .../crates/types/src/tests/fixture_builder.nr | 3 +- .../src/tests/public_call_data_builder.nr | 1 - yarn-project/circuit-types/src/mocks.ts | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 40 +++++++++---------- .../private_call_stack_item.test.ts.snap | 4 +- ...private_circuit_public_inputs.test.ts.snap | 4 +- .../public_call_stack_item.test.ts.snap | 8 ++-- .../public_circuit_public_inputs.test.ts.snap | 4 +- .../circuits.js/src/structs/call_context.ts | 12 +----- .../src/structs/public_call_request.ts | 15 ++++++- .../circuits.js/src/tests/factories.ts | 2 +- .../src/type_conversion.ts | 2 - yarn-project/simulator/src/acvm/serialize.ts | 1 + .../src/client/client_execution_context.ts | 6 +-- .../simulator/src/client/execution_result.ts | 2 +- .../src/client/private_execution.test.ts | 3 +- .../simulator/src/client/simulator.ts | 1 - yarn-project/simulator/src/mocks/fixtures.ts | 2 +- yarn-project/simulator/src/public/executor.ts | 3 -- .../src/public/public_processor.test.ts | 30 +++++++------- .../simulator/src/public/side_effect_trace.ts | 10 +---- yarn-project/txe/src/oracle/txe_oracle.ts | 7 +--- 33 files changed, 127 insertions(+), 177 deletions(-) diff --git a/barretenberg/cpp/pil/avm/constants_gen.pil b/barretenberg/cpp/pil/avm/constants_gen.pil index a1f4cb2c1a5..f597ac43ddb 100644 --- a/barretenberg/cpp/pil/avm/constants_gen.pil +++ b/barretenberg/cpp/pil/avm/constants_gen.pil @@ -15,17 +15,17 @@ namespace constants(256); pol ADDRESS_SELECTOR = 1; pol STORAGE_ADDRESS_SELECTOR = 1; pol FUNCTION_SELECTOR_SELECTOR = 2; - pol START_GLOBAL_VARIABLES = 29; - pol CHAIN_ID_SELECTOR = 29; - pol VERSION_SELECTOR = 30; - pol BLOCK_NUMBER_SELECTOR = 31; - pol TIMESTAMP_SELECTOR = 32; - pol COINBASE_SELECTOR = 33; - pol FEE_PER_DA_GAS_SELECTOR = 35; - pol FEE_PER_L2_GAS_SELECTOR = 36; - pol END_GLOBAL_VARIABLES = 37; - pol START_SIDE_EFFECT_COUNTER = 37; - pol TRANSACTION_FEE_SELECTOR = 40; + pol START_GLOBAL_VARIABLES = 28; + pol CHAIN_ID_SELECTOR = 28; + pol VERSION_SELECTOR = 29; + pol BLOCK_NUMBER_SELECTOR = 30; + pol TIMESTAMP_SELECTOR = 31; + pol COINBASE_SELECTOR = 32; + pol FEE_PER_DA_GAS_SELECTOR = 34; + pol FEE_PER_L2_GAS_SELECTOR = 35; + pol END_GLOBAL_VARIABLES = 36; + pol START_SIDE_EFFECT_COUNTER = 36; + pol TRANSACTION_FEE_SELECTOR = 39; pol START_NOTE_HASH_EXISTS_WRITE_OFFSET = 0; pol START_NULLIFIER_EXISTS_OFFSET = 16; pol START_NULLIFIER_NON_EXISTS_OFFSET = 32; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp index 8ad866f7f54..156c52d7dc3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -15,7 +15,7 @@ #define AZTEC_ADDRESS_LENGTH 1 #define GAS_FEES_LENGTH 2 #define GAS_LENGTH 2 -#define CALL_CONTEXT_LENGTH 6 +#define CALL_CONTEXT_LENGTH 5 #define CONTENT_COMMITMENT_LENGTH 4 #define CONTRACT_STORAGE_READ_LENGTH 3 #define CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH 3 @@ -30,23 +30,23 @@ #define STATE_REFERENCE_LENGTH 8 #define TOTAL_FEES_LENGTH 1 #define HEADER_LENGTH 23 -#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 482 -#define PUBLIC_CONTEXT_INPUTS_LENGTH 41 +#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 481 +#define PUBLIC_CONTEXT_INPUTS_LENGTH 40 #define SENDER_SELECTOR 0 #define ADDRESS_SELECTOR 1 #define STORAGE_ADDRESS_SELECTOR 1 #define FUNCTION_SELECTOR_SELECTOR 2 -#define START_GLOBAL_VARIABLES 29 -#define CHAIN_ID_SELECTOR 29 -#define VERSION_SELECTOR 30 -#define BLOCK_NUMBER_SELECTOR 31 -#define TIMESTAMP_SELECTOR 32 -#define COINBASE_SELECTOR 33 -#define FEE_PER_DA_GAS_SELECTOR 35 -#define FEE_PER_L2_GAS_SELECTOR 36 -#define END_GLOBAL_VARIABLES 37 -#define START_SIDE_EFFECT_COUNTER 37 -#define TRANSACTION_FEE_SELECTOR 40 +#define START_GLOBAL_VARIABLES 28 +#define CHAIN_ID_SELECTOR 28 +#define VERSION_SELECTOR 29 +#define BLOCK_NUMBER_SELECTOR 30 +#define TIMESTAMP_SELECTOR 31 +#define COINBASE_SELECTOR 32 +#define FEE_PER_DA_GAS_SELECTOR 34 +#define FEE_PER_L2_GAS_SELECTOR 35 +#define END_GLOBAL_VARIABLES 36 +#define START_SIDE_EFFECT_COUNTER 36 +#define TRANSACTION_FEE_SELECTOR 39 #define START_NOTE_HASH_EXISTS_WRITE_OFFSET 0 #define START_NULLIFIER_EXISTS_OFFSET 16 #define START_NULLIFIER_NON_EXISTS_OFFSET 32 diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 5e0b04a587a..acb69d08a75 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -117,7 +117,7 @@ library Constants { uint256 internal constant GAS_FEES_LENGTH = 2; uint256 internal constant GAS_LENGTH = 2; uint256 internal constant GAS_SETTINGS_LENGTH = 7; - uint256 internal constant CALL_CONTEXT_LENGTH = 6; + uint256 internal constant CALL_CONTEXT_LENGTH = 5; uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4; uint256 internal constant CONTRACT_INSTANCE_LENGTH = 5; uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 3; @@ -142,7 +142,7 @@ library Constants { uint256 internal constant SCOPED_ENCRYPTED_LOG_HASH_LENGTH = 5; uint256 internal constant NOTE_LOG_HASH_LENGTH = 4; uint256 internal constant NOTE_HASH_LENGTH = 2; - uint256 internal constant SCOPED_NOTE_HASH_LENGTH = 4; + uint256 internal constant SCOPED_NOTE_HASH_LENGTH = 3; uint256 internal constant NULLIFIER_LENGTH = 3; uint256 internal constant SCOPED_NULLIFIER_LENGTH = 4; uint256 internal constant CALLER_CONTEXT_LENGTH = 3; @@ -154,10 +154,10 @@ library Constants { uint256 internal constant TX_REQUEST_LENGTH = 13; uint256 internal constant TOTAL_FEES_LENGTH = 1; uint256 internal constant HEADER_LENGTH = 23; - uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 393; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 482; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 396; - uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 41; + uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 392; + uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 481; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 395; + uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 40; uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16; uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2; @@ -166,8 +166,8 @@ library Constants { uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 333; uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 40; uint256 internal constant CALL_REQUEST_LENGTH = 7; - uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1152; - uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2227; + uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1088; + uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2163; uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 983; uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3258; uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 383; @@ -192,18 +192,18 @@ library Constants { uint256 internal constant ADDRESS_SELECTOR = 1; uint256 internal constant STORAGE_ADDRESS_SELECTOR = 1; uint256 internal constant FUNCTION_SELECTOR_SELECTOR = 2; - uint256 internal constant START_GLOBAL_VARIABLES = 29; - uint256 internal constant CHAIN_ID_SELECTOR = 29; - uint256 internal constant VERSION_SELECTOR = 30; - uint256 internal constant BLOCK_NUMBER_SELECTOR = 31; - uint256 internal constant TIMESTAMP_SELECTOR = 32; - uint256 internal constant COINBASE_SELECTOR = 33; - uint256 internal constant UNUSED_FEE_RECIPIENT_SELECTOR = 34; - uint256 internal constant FEE_PER_DA_GAS_SELECTOR = 35; - uint256 internal constant FEE_PER_L2_GAS_SELECTOR = 36; - uint256 internal constant END_GLOBAL_VARIABLES = 37; - uint256 internal constant START_SIDE_EFFECT_COUNTER = 37; - uint256 internal constant TRANSACTION_FEE_SELECTOR = 40; + uint256 internal constant START_GLOBAL_VARIABLES = 28; + uint256 internal constant CHAIN_ID_SELECTOR = 28; + uint256 internal constant VERSION_SELECTOR = 29; + uint256 internal constant BLOCK_NUMBER_SELECTOR = 30; + uint256 internal constant TIMESTAMP_SELECTOR = 31; + uint256 internal constant COINBASE_SELECTOR = 32; + uint256 internal constant UNUSED_FEE_RECIPIENT_SELECTOR = 33; + uint256 internal constant FEE_PER_DA_GAS_SELECTOR = 34; + uint256 internal constant FEE_PER_L2_GAS_SELECTOR = 35; + uint256 internal constant END_GLOBAL_VARIABLES = 36; + uint256 internal constant START_SIDE_EFFECT_COUNTER = 36; + uint256 internal constant TRANSACTION_FEE_SELECTOR = 39; uint256 internal constant START_NOTE_HASH_EXISTS_WRITE_OFFSET = 0; uint256 internal constant START_NULLIFIER_EXISTS_OFFSET = 16; uint256 internal constant START_NULLIFIER_NON_EXISTS_OFFSET = 32; diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 4f8b7f657f5..7e386fa9c5d 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -357,7 +357,6 @@ impl PrivateContext { is_delegate_call ); - assert_eq(item.public_inputs.call_context.side_effect_counter, start_side_effect_counter); assert_eq(item.public_inputs.start_side_effect_counter, start_side_effect_counter); let end_side_effect_counter = item.public_inputs.end_side_effect_counter; self.side_effect_counter = end_side_effect_counter + 1; @@ -555,7 +554,7 @@ impl PrivateContext { assert(contract_address.eq(item.contract_address)); assert(function_selector.eq(item.function_data.selector)); - assert_eq(item.public_inputs.call_context.side_effect_counter, self.side_effect_counter); + assert_eq(item.public_inputs.start_side_effect_counter, self.side_effect_counter); assert(args_hash == item.public_inputs.args_hash); diff --git a/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr b/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr index 7d9e0322217..df89503ce0a 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/enqueue_public_function_call.nr @@ -85,6 +85,7 @@ pub fn parse_public_call_stack_item_from_oracle(fields: [Field; ENQUEUE_PUBLIC_F function_data: FunctionData { selector: FunctionSelector::from_field(reader.read()), is_private: false }, public_inputs: PublicCircuitPublicInputs { call_context: reader.read_struct(CallContext::deserialize), + start_side_effect_counter: reader.read_u32(), args_hash: reader.read(), returns_hash: 0, note_hash_read_requests: [ReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], @@ -97,7 +98,6 @@ pub fn parse_public_call_stack_item_from_oracle(fields: [Field; ENQUEUE_PUBLIC_F note_hashes: [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL], nullifiers: [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL], l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL], - start_side_effect_counter: 0, end_side_effect_counter: 0, unencrypted_logs_hashes: [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL], historical_header: Header::empty(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index 72a7a5f9f32..9f6c6462c54 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -1,8 +1,7 @@ use crate::{ - abis::function_selector::FunctionSelector, address::{EthAddress, AztecAddress}, + abis::function_selector::FunctionSelector, address::AztecAddress, constants::{CALL_CONTEXT_LENGTH, GENERATOR_INDEX__CALL_CONTEXT}, hash::pedersen_hash, - traits::{Deserialize, Hash, Serialize, Empty}, abis::side_effect::Ordered, - abis::{gas_settings::GasSettings, gas::Gas}, utils::reader::Reader + traits::{Deserialize, Hash, Serialize, Empty}, utils::reader::Reader }; // docs:start:call-context @@ -13,21 +12,9 @@ struct CallContext { is_delegate_call : bool, is_static_call : bool, - - side_effect_counter : u32, } // docs:end:call-context -impl CallContext { - fn assert_is_zero(self) { - let serialized: [Field; CALL_CONTEXT_LENGTH] = self.serialize(); - - for i in 0..CALL_CONTEXT_LENGTH { - assert(serialized[i] == 0); - } - } -} - impl Eq for CallContext { fn eq(self, other: CallContext) -> bool { self.serialize() == other.serialize() @@ -49,7 +36,6 @@ impl Serialize for CallContext { serialized.push(self.function_selector.to_field()); serialized.push(self.is_delegate_call as Field); serialized.push(self.is_static_call as Field); - serialized.push(self.side_effect_counter as Field); serialized.storage } @@ -64,7 +50,6 @@ impl Deserialize for CallContext { function_selector: FunctionSelector::from_field(reader.read()), is_delegate_call: reader.read() as bool, is_static_call: reader.read() as bool, - side_effect_counter: reader.read() as u32, } } } @@ -77,7 +62,6 @@ impl Empty for CallContext { function_selector: FunctionSelector::empty(), is_delegate_call: false, is_static_call: false, - side_effect_counter: 0, } } } @@ -90,19 +74,6 @@ fn serialize_deserialize_of_empty() { assert(context.eq(deserialized)); } -#[test] -fn assert_is_zero() { - let context = CallContext::empty(); - context.assert_is_zero(); -} - -#[test(should_fail)] -fn not_zero_assert_is_zero() { - let mut context = CallContext::empty(); - context.is_delegate_call = true; - context.assert_is_zero(); -} - #[test] fn test_eq() { let mut context1 = CallContext::empty(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index bf322ef6adb..cec64cf55ba 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -85,6 +85,6 @@ fn empty_hash() { let hash = item.hash(); // Value from private_call_stack_item.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x157022d579f892f06461fb895cdf5550b24329e15e7a41df14f9dad582fa1bc5; + let test_data_empty_hash = 0x0c0c1a9624be4d634230bfc76fb7f13ec8eb734435cd4bedb0a6ac8c401cf3af; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 7848088a944..afbd0eef953 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -250,6 +250,6 @@ fn empty_hash() { let inputs = PrivateCircuitPublicInputs::empty(); let hash = inputs.hash(); // Value from private_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x1eb5048b5bdcea5ba66519ecd1cbdb9e18fd957d52830b2bcb309f4ce9bcfbd3; + let test_data_empty_hash = 0x24279032bb22986fb65e4d5ecb60e1d1c2203b4dfa477c69f61727e3bc2c2397; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr index 4c12a77d0d3..6d827aa0769 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr @@ -70,7 +70,7 @@ mod tests { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; // Value from public_call_stack_item.test.ts "Computes a callstack item request hash" test - let test_data_call_stack_item_request_hash = 0x022a2b82af83606ae5a8d4955ef6215e54025193356318aefbde3b5026952953; + let test_data_call_stack_item_request_hash = 0x097c4940595af6f4eb77602740b35eb02c867f2cbc97d6fd3ec4160dbced8838; assert_eq(call_stack_item.hash(), test_data_call_stack_item_request_hash); } @@ -88,7 +88,7 @@ mod tests { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; // Value from public_call_stack_item.test.ts "Computes a callstack item hash" test - let test_data_call_stack_item_hash = 0x23a1d22e7bf37df7d68e8fcbfb7e016c060194b7915e3771e2dcd72cea26e427; + let test_data_call_stack_item_hash = 0x29927739d440785b3a1693910d35c00194b541f6ede16c5ba7e295fd2810bb51; assert_eq(call_stack_item.hash(), test_data_call_stack_item_hash); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index 555ab222440..fba93acda45 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -201,6 +201,6 @@ fn empty_hash() { let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x2e08158f3f0d9a94e3f17338aadc3733a15bf5d163f94cef1afd8a47b446d789; + let test_data_empty_hash = 0x2b80e3db92cdbf588155e0eaa4f51b35366cbd6e10f587c335204be5bf337bac; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 256e090d569..8dddb6b9f0a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -168,7 +168,7 @@ global AZTEC_ADDRESS_LENGTH = 1; global GAS_FEES_LENGTH: u32 = 2; global GAS_LENGTH: u32 = 2; global GAS_SETTINGS_LENGTH: u32 = GAS_LENGTH * 2 + GAS_FEES_LENGTH + /* inclusion_fee */ 1; -global CALL_CONTEXT_LENGTH: u32 = 6; +global CALL_CONTEXT_LENGTH: u32 = 5; global CONTENT_COMMITMENT_LENGTH: u32 = 4; global CONTRACT_INSTANCE_LENGTH: u32 = 5; global CONTRACT_STORAGE_READ_LENGTH: u32 = 3; @@ -234,7 +234,7 @@ global CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 4 + GLOB // + 5 for rollup_type, height_in_block_tree, txs_effects_hash, out_hash, accumulated_fees global BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 5; -global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH: u32 = 3 + CALL_CONTEXT_LENGTH; +global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH: u32 = 4 + CALL_CONTEXT_LENGTH; global GET_NOTES_ORACLE_RETURN_LENGTH: u32 = 674; global NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP: u32 = 32 * MAX_NOTE_HASHES_PER_TX; global NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP: u32 = 32 * MAX_NULLIFIERS_PER_TX; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 6c7e69099de..8af6598864b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -211,8 +211,7 @@ impl FixtureBuilder { storage_contract_address: self.storage_contract_address, function_selector: self.function_data.selector, is_delegate_call: self.is_delegate_call, - is_static_call: self.is_static_call, - side_effect_counter: self.counter_start + is_static_call: self.is_static_call } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr index 7beaca99e36..55de13e3a3c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/public_call_data_builder.nr @@ -40,7 +40,6 @@ impl PublicCallDataBuilder { function_selector: function_data.selector, is_delegate_call: false, is_static_call: false, - side_effect_counter: 0, // needed? }; PublicCallDataBuilder { diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index a15d73e021e..48f60ba5567 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -72,7 +72,7 @@ export const mockTx = ( data.forPublic = PartialPrivateTailPublicInputsForPublic.empty(); publicCallRequests = publicCallRequests.length - ? publicCallRequests.slice().sort((a, b) => b.callContext.sideEffectCounter - a.callContext.sideEffectCounter) + ? publicCallRequests.slice().sort((a, b) => b.sideEffectCounter - a.sideEffectCounter) : times(totalPublicCallRequests, i => makePublicCallRequest(seed + 0x100 + i)); const revertibleBuilder = new PublicAccumulatedDataBuilder(); diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index d4c57415687..6c7cf1bf611 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -101,7 +101,7 @@ export const AZTEC_ADDRESS_LENGTH = 1; export const GAS_FEES_LENGTH = 2; export const GAS_LENGTH = 2; export const GAS_SETTINGS_LENGTH = 7; -export const CALL_CONTEXT_LENGTH = 6; +export const CALL_CONTEXT_LENGTH = 5; export const CONTENT_COMMITMENT_LENGTH = 4; export const CONTRACT_INSTANCE_LENGTH = 5; export const CONTRACT_STORAGE_READ_LENGTH = 3; @@ -126,7 +126,7 @@ export const ENCRYPTED_LOG_HASH_LENGTH = 4; export const SCOPED_ENCRYPTED_LOG_HASH_LENGTH = 5; export const NOTE_LOG_HASH_LENGTH = 4; export const NOTE_HASH_LENGTH = 2; -export const SCOPED_NOTE_HASH_LENGTH = 4; +export const SCOPED_NOTE_HASH_LENGTH = 3; export const NULLIFIER_LENGTH = 3; export const SCOPED_NULLIFIER_LENGTH = 4; export const CALLER_CONTEXT_LENGTH = 3; @@ -138,10 +138,10 @@ export const TX_CONTEXT_LENGTH = 9; export const TX_REQUEST_LENGTH = 13; export const TOTAL_FEES_LENGTH = 1; export const HEADER_LENGTH = 23; -export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 393; -export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 482; -export const PRIVATE_CALL_STACK_ITEM_LENGTH = 396; -export const PUBLIC_CONTEXT_INPUTS_LENGTH = 41; +export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 392; +export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 481; +export const PRIVATE_CALL_STACK_ITEM_LENGTH = 395; +export const PUBLIC_CONTEXT_INPUTS_LENGTH = 40; export const AGGREGATION_OBJECT_LENGTH = 16; export const SCOPED_READ_REQUEST_LEN = 3; export const PUBLIC_DATA_READ_LENGTH = 2; @@ -150,8 +150,8 @@ export const PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3; export const COMBINED_ACCUMULATED_DATA_LENGTH = 333; export const COMBINED_CONSTANT_DATA_LENGTH = 40; export const CALL_REQUEST_LENGTH = 7; -export const PRIVATE_ACCUMULATED_DATA_LENGTH = 1152; -export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2227; +export const PRIVATE_ACCUMULATED_DATA_LENGTH = 1088; +export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2163; export const PUBLIC_ACCUMULATED_DATA_LENGTH = 983; export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3258; export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 383; @@ -176,18 +176,18 @@ export const SENDER_SELECTOR = 0; export const ADDRESS_SELECTOR = 1; export const STORAGE_ADDRESS_SELECTOR = 1; export const FUNCTION_SELECTOR_SELECTOR = 2; -export const START_GLOBAL_VARIABLES = 29; -export const CHAIN_ID_SELECTOR = 29; -export const VERSION_SELECTOR = 30; -export const BLOCK_NUMBER_SELECTOR = 31; -export const TIMESTAMP_SELECTOR = 32; -export const COINBASE_SELECTOR = 33; -export const UNUSED_FEE_RECIPIENT_SELECTOR = 34; -export const FEE_PER_DA_GAS_SELECTOR = 35; -export const FEE_PER_L2_GAS_SELECTOR = 36; -export const END_GLOBAL_VARIABLES = 37; -export const START_SIDE_EFFECT_COUNTER = 37; -export const TRANSACTION_FEE_SELECTOR = 40; +export const START_GLOBAL_VARIABLES = 28; +export const CHAIN_ID_SELECTOR = 28; +export const VERSION_SELECTOR = 29; +export const BLOCK_NUMBER_SELECTOR = 30; +export const TIMESTAMP_SELECTOR = 31; +export const COINBASE_SELECTOR = 32; +export const UNUSED_FEE_RECIPIENT_SELECTOR = 33; +export const FEE_PER_DA_GAS_SELECTOR = 34; +export const FEE_PER_L2_GAS_SELECTOR = 35; +export const END_GLOBAL_VARIABLES = 36; +export const START_SIDE_EFFECT_COUNTER = 36; +export const TRANSACTION_FEE_SELECTOR = 39; export const START_NOTE_HASH_EXISTS_WRITE_OFFSET = 0; export const START_NULLIFIER_EXISTS_OFFSET = 16; export const START_NULLIFIER_NON_EXISTS_OFFSET = 32; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index 72fe84f15ce..30dbbeb4aab 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x157022d579f892f06461fb895cdf5550b24329e15e7a41df14f9dad582fa1bc5>`; +exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x0c0c1a9624be4d634230bfc76fb7f13ec8eb734435cd4bedb0a6ac8c401cf3af>`; -exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x029b1573da033e679c68a55e05987602c5e73419c4fdfdd6104e178a9a360834>`; +exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x0eb886ec2310cd708f65c6f59816213b20ca66fff96728b7fc7cbf64c77c9814>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 676f8aca357..e559c2fd79c 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x1eb5048b5bdcea5ba66519ecd1cbdb9e18fd957d52830b2bcb309f4ce9bcfbd3>`; +exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x24279032bb22986fb65e4d5ecb60e1d1c2203b4dfa477c69f61727e3bc2c2397>`; -exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0b02f49b7283dacf553c5cfc0615c979fdd1cd146a1d4e71c78610345a711d22>`; +exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0179e45ea9a710f90edc8558e599627757bf6a51def8e2f858edd2c06e4bfcec>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap index 4db396c18cd..418c7d1dc4c 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x23a1d22e7bf37df7d68e8fcbfb7e016c060194b7915e3771e2dcd72cea26e427"`; +exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x29927739d440785b3a1693910d35c00194b541f6ede16c5ba7e295fd2810bb51"`; -exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x022a2b82af83606ae5a8d4955ef6215e54025193356318aefbde3b5026952953"`; +exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x097c4940595af6f4eb77602740b35eb02c867f2cbc97d6fd3ec4160dbced8838"`; -exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x211932b705c9a5dbbaf2433d2ee4b0a896ef9fb720a4efbe7c1e783747c36588>`; +exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x0ad03515d9ca861945fa779502fda236d54d0bbcc4a2d693dfa671d2f213aa0e>`; -exports[`PublicCallStackItem computes hash 1`] = `Fr<0x2d9862fe4fb3db6fe24996cbc3064346aa4551ccd41246c1ca6b002b8b0201fd>`; +exports[`PublicCallStackItem computes hash 1`] = `Fr<0x1976666a5da5e2ab45cf4f1425455a7317a156f41529e6ad14e71820b791b0e2>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index df8a677f298..a19e83d6bea 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x2e08158f3f0d9a94e3f17338aadc3733a15bf5d163f94cef1afd8a47b446d789>`; +exports[`PublicCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x2b80e3db92cdbf588155e0eaa4f51b35366cbd6e10f587c335204be5bf337bac>`; -exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x17718899a1af9292f21e6cceab91915edf7dc356c0e7e7354340d25f91e935cf>`; +exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0f068c8c19112300cf78744661d3af705340aed011fb1b6ceb49526b15649f84>`; diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index 556c2b97461..99099464c26 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -33,10 +33,6 @@ export class CallContext { * Determines whether the call is modifying state. */ public isStaticCall: boolean, - /** - * The start side effect counter for this call context. - */ - public sideEffectCounter: number, ) {} /** @@ -44,7 +40,7 @@ export class CallContext { * @returns A new instance of CallContext with zero msg sender, storage contract address. */ public static empty(): CallContext { - return new CallContext(AztecAddress.ZERO, AztecAddress.ZERO, FunctionSelector.empty(), false, false, 0); + return new CallContext(AztecAddress.ZERO, AztecAddress.ZERO, FunctionSelector.empty(), false, false); } isEmpty() { @@ -64,7 +60,6 @@ export class CallContext { fields.functionSelector, fields.isDelegateCall, fields.isStaticCall, - fields.sideEffectCounter, ] as const; } @@ -99,7 +94,6 @@ export class CallContext { reader.readObject(FunctionSelector), reader.readBoolean(), reader.readBoolean(), - reader.readNumber(), ); } @@ -111,7 +105,6 @@ export class CallContext { reader.readObject(FunctionSelector), reader.readBoolean(), reader.readBoolean(), - reader.readU32(), ); } @@ -121,8 +114,7 @@ export class CallContext { callContext.storageContractAddress.equals(this.storageContractAddress) && callContext.functionSelector.equals(this.functionSelector) && callContext.isDelegateCall === this.isDelegateCall && - callContext.isStaticCall === this.isStaticCall && - callContext.sideEffectCounter === this.sideEffectCounter + callContext.isStaticCall === this.isStaticCall ); } } diff --git a/yarn-project/circuits.js/src/structs/public_call_request.ts b/yarn-project/circuits.js/src/structs/public_call_request.ts index 7c9384c95bd..9bf8898a1b1 100644 --- a/yarn-project/circuits.js/src/structs/public_call_request.ts +++ b/yarn-project/circuits.js/src/structs/public_call_request.ts @@ -38,6 +38,10 @@ export class PublicCallRequest { * TODO(#3417): Check if all fields of CallContext are actually needed. */ public parentCallContext: CallContext, + /** + * The start side effect counter for this call request. + */ + public sideEffectCounter: number, /** * Function arguments. */ @@ -58,6 +62,7 @@ export class PublicCallRequest { this.functionSelector, this.callContext, this.parentCallContext, + this.sideEffectCounter, new Vector(this.args), ); } @@ -74,6 +79,7 @@ export class PublicCallRequest { FunctionSelector.fromBuffer(reader), CallContext.fromBuffer(reader), CallContext.fromBuffer(reader), + reader.readNumber(), reader.readVector(Fr), ); } @@ -98,6 +104,7 @@ export class PublicCallRequest { fields.functionSelector, fields.callContext, fields.parentCallContext, + fields.sideEffectCounter, fields.args, ] as const; } @@ -135,7 +142,7 @@ export class PublicCallRequest { item.hash(), this.parentCallContext.storageContractAddress, callerContext, - new Fr(this.callContext.sideEffectCounter), + new Fr(this.sideEffectCounter), Fr.ZERO, ); } @@ -154,6 +161,7 @@ export class PublicCallRequest { FunctionSelector.empty(), CallContext.empty(), CallContext.empty(), + 0, [], ); } @@ -164,6 +172,7 @@ export class PublicCallRequest { this.functionSelector.isEmpty() && this.callContext.isEmpty() && this.parentCallContext.isEmpty() && + this.sideEffectCounter == 0 && this.args.length === 0 ); } @@ -174,6 +183,8 @@ export class PublicCallRequest { functionSelector: ${this.functionSelector} callContext: ${this.callContext} parentCallContext: ${this.parentCallContext} - args: ${this.args} }`; + sideEffectCounter: ${this.sideEffectCounter} + args: ${this.args} + }`; } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index f380c432041..4d55e100817 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -394,7 +394,6 @@ export function makeCallContext(seed = 0, overrides: Partial b.callContext.sideEffectCounter - a.callContext.sideEffectCounter); + ].sort((a, b) => b.sideEffectCounter - a.sideEffectCounter); } export function collectPublicTeardownFunctionCall(execResult: ExecutionResult): PublicCallRequest { diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 7eeb02a34d1..ae8ec83d6cf 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -888,7 +888,6 @@ describe('Private Execution test suite', () => { functionSelector: childSelector, isDelegateCall: false, isStaticCall: false, - sideEffectCounter: 2, }), parentCallContext: CallContext.from({ msgSender: parentAddress, @@ -896,8 +895,8 @@ describe('Private Execution test suite', () => { functionSelector: FunctionSelector.fromNameAndParameters(parentArtifact.name, parentArtifact.parameters), isDelegateCall: false, isStaticCall: false, - sideEffectCounter: 1, }), + sideEffectCounter: 2, }); const publicCallRequestHash = publicCallRequest.toPublicCallStackItem().hash(); diff --git a/yarn-project/simulator/src/client/simulator.ts b/yarn-project/simulator/src/client/simulator.ts index e72c4ef7e97..cf2abfb00bd 100644 --- a/yarn-project/simulator/src/client/simulator.ts +++ b/yarn-project/simulator/src/client/simulator.ts @@ -67,7 +67,6 @@ export class AcirSimulator { FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters), false, entryPointArtifact.isStatic, - startSideEffectCounter, ); const context = new ClientExecutionContext( contractAddress, diff --git a/yarn-project/simulator/src/mocks/fixtures.ts b/yarn-project/simulator/src/mocks/fixtures.ts index 2dd199084a1..40667e111b7 100644 --- a/yarn-project/simulator/src/mocks/fixtures.ts +++ b/yarn-project/simulator/src/mocks/fixtures.ts @@ -75,7 +75,7 @@ export class PublicExecutionResultBuilder { revertReason?: SimulationError; }) { const builder = new PublicExecutionResultBuilder({ - callContext: new CallContext(from, tx.to, tx.selector, false, false, 0), + callContext: new CallContext(from, tx.to, tx.selector, false, false), contractAddress: tx.to, functionSelector: tx.selector, args: tx.args, diff --git a/yarn-project/simulator/src/public/executor.ts b/yarn-project/simulator/src/public/executor.ts index 9a524c458c8..64f57d27d88 100644 --- a/yarn-project/simulator/src/public/executor.ts +++ b/yarn-project/simulator/src/public/executor.ts @@ -99,9 +99,6 @@ export class PublicExecutor { bytecode, avmResult, fnName, - /*requestSideEffectCounter=*/ executionRequest.callContext.sideEffectCounter, - // NOTE: startSideEffectCounter is not the same as the executionRequest's sideEffectCounter - // (which counts the request itself) ); return publicExecutionResult; diff --git a/yarn-project/simulator/src/public/public_processor.test.ts b/yarn-project/simulator/src/public/public_processor.test.ts index 70687522d83..09d1de5ef96 100644 --- a/yarn-project/simulator/src/public/public_processor.test.ts +++ b/yarn-project/simulator/src/public/public_processor.test.ts @@ -362,9 +362,9 @@ describe('public_processor', () => { baseContractAddressSeed, baseContractAddressSeed, ].map(makePublicCallRequest); - publicCallRequests[0].callContext.sideEffectCounter = 2; - publicCallRequests[1].callContext.sideEffectCounter = 3; - publicCallRequests[2].callContext.sideEffectCounter = 4; + publicCallRequests[0].sideEffectCounter = 2; + publicCallRequests[1].sideEffectCounter = 3; + publicCallRequests[2].sideEffectCounter = 4; const teardown = publicCallRequests.pop()!; // Remove the last call request to test that the processor can handle this const tx = mockTxWithPartialState({ @@ -494,9 +494,9 @@ describe('public_processor', () => { baseContractAddressSeed, baseContractAddressSeed, ].map(makePublicCallRequest); - publicCallRequests[0].callContext.sideEffectCounter = 2; - publicCallRequests[1].callContext.sideEffectCounter = 3; - publicCallRequests[2].callContext.sideEffectCounter = 4; + publicCallRequests[0].sideEffectCounter = 2; + publicCallRequests[1].sideEffectCounter = 3; + publicCallRequests[2].sideEffectCounter = 4; const teardown = publicCallRequests.pop()!; const tx = mockTxWithPartialState({ @@ -594,9 +594,9 @@ describe('public_processor', () => { baseContractAddressSeed, baseContractAddressSeed, ].map(makePublicCallRequest); - publicCallRequests[0].callContext.sideEffectCounter = 2; - publicCallRequests[1].callContext.sideEffectCounter = 3; - publicCallRequests[2].callContext.sideEffectCounter = 4; + publicCallRequests[0].sideEffectCounter = 2; + publicCallRequests[1].sideEffectCounter = 3; + publicCallRequests[2].sideEffectCounter = 4; const teardown = publicCallRequests.pop()!; const tx = mockTxWithPartialState({ @@ -719,9 +719,9 @@ describe('public_processor', () => { baseContractAddressSeed, baseContractAddressSeed, ].map(makePublicCallRequest); - publicCallRequests[0].callContext.sideEffectCounter = 2; - publicCallRequests[1].callContext.sideEffectCounter = 3; - publicCallRequests[2].callContext.sideEffectCounter = 4; + publicCallRequests[0].sideEffectCounter = 2; + publicCallRequests[1].sideEffectCounter = 3; + publicCallRequests[2].sideEffectCounter = 4; const teardown = publicCallRequests.pop()!; const tx = mockTxWithPartialState({ @@ -845,9 +845,9 @@ describe('public_processor', () => { baseContractAddressSeed, baseContractAddressSeed, ].map(makePublicCallRequest); - publicCallRequests[0].callContext.sideEffectCounter = 2; - publicCallRequests[1].callContext.sideEffectCounter = 3; - publicCallRequests[2].callContext.sideEffectCounter = 4; + publicCallRequests[0].sideEffectCounter = 2; + publicCallRequests[1].sideEffectCounter = 3; + publicCallRequests[2].sideEffectCounter = 4; const teardown = publicCallRequests.pop(); // Remove the last call request to test that the processor can handle this const tx = mockTxWithPartialState({ diff --git a/yarn-project/simulator/src/public/side_effect_trace.ts b/yarn-project/simulator/src/public/side_effect_trace.ts index b29506928b2..a42be29f898 100644 --- a/yarn-project/simulator/src/public/side_effect_trace.ts +++ b/yarn-project/simulator/src/public/side_effect_trace.ts @@ -273,11 +273,9 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { avmCallResults: AvmContractCallResult, /** Function name for logging */ functionName: string = 'unknown', - /** The side effect counter of the execution request itself */ - requestSideEffectCounter: number = this.startSideEffectCounter, ): PublicExecutionResult { return { - executionRequest: createPublicExecutionRequest(requestSideEffectCounter, avmEnvironment), + executionRequest: createPublicExecutionRequest(avmEnvironment), startSideEffectCounter: new Fr(this.startSideEffectCounter), endSideEffectCounter: new Fr(this.sideEffectCounter), @@ -319,17 +317,13 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { /** * Helper function to create a public execution request from an AVM execution environment */ -function createPublicExecutionRequest( - requestSideEffectCounter: number, - avmEnvironment: AvmExecutionEnvironment, -): PublicExecutionRequest { +function createPublicExecutionRequest(avmEnvironment: AvmExecutionEnvironment): PublicExecutionRequest { const callContext = CallContext.from({ msgSender: avmEnvironment.sender, storageContractAddress: avmEnvironment.storageAddress, functionSelector: avmEnvironment.functionSelector, isDelegateCall: avmEnvironment.isDelegateCall, isStaticCall: avmEnvironment.isStaticCall, - sideEffectCounter: requestSideEffectCounter, }); return { contractAddress: avmEnvironment.address, diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index be9bc639041..d22af98030a 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -179,7 +179,6 @@ export class TXE implements TypedOracle { inputs.historicalHeader.state = stateReference; inputs.callContext.msgSender = this.msgSender; inputs.callContext.storageContractAddress = this.contractAddress; - inputs.callContext.sideEffectCounter = sideEffectsCounter; inputs.callContext.isStaticCall = isStaticCall; inputs.callContext.isDelegateCall = isDelegateCall; inputs.startSideEffectCounter = sideEffectsCounter; @@ -721,7 +720,6 @@ export class TXE implements TypedOracle { TxContext.empty(), /* pendingNullifiers */ [], /* transactionFee */ Fr.ONE, - callContext.sideEffectCounter, ); } @@ -743,7 +741,6 @@ export class TXE implements TypedOracle { const callContext = CallContext.empty(); callContext.msgSender = this.msgSender; callContext.functionSelector = this.functionSelector; - callContext.sideEffectCounter = this.sideEffectsCounter; callContext.storageContractAddress = targetContractAddress; callContext.isStaticCall = isStaticCall; callContext.isDelegateCall = isDelegateCall; @@ -785,7 +782,6 @@ export class TXE implements TypedOracle { const callContext = CallContext.empty(); callContext.msgSender = this.msgSender; callContext.functionSelector = this.functionSelector; - callContext.sideEffectCounter = sideEffectCounter; callContext.storageContractAddress = targetContractAddress; callContext.isStaticCall = isStaticCall; callContext.isDelegateCall = isDelegateCall; @@ -827,7 +823,6 @@ export class TXE implements TypedOracle { const callContext = CallContext.empty(); callContext.msgSender = this.msgSender; callContext.functionSelector = this.functionSelector; - callContext.sideEffectCounter = sideEffectCounter; callContext.storageContractAddress = targetContractAddress; callContext.isStaticCall = isStaticCall; callContext.isDelegateCall = isDelegateCall; @@ -850,7 +845,6 @@ export class TXE implements TypedOracle { const parentCallContext = CallContext.empty(); parentCallContext.msgSender = currentMessageSender; parentCallContext.functionSelector = currentFunctionSelector; - parentCallContext.sideEffectCounter = sideEffectCounter; parentCallContext.storageContractAddress = currentContractAddress; parentCallContext.isStaticCall = isStaticCall; parentCallContext.isDelegateCall = isDelegateCall; @@ -860,6 +854,7 @@ export class TXE implements TypedOracle { contractAddress: targetContractAddress, functionSelector, callContext, + sideEffectCounter, args, }); } From 00f56e1371cf20af0d8f9abf771b241393b18e5f Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Thu, 4 Jul 2024 22:26:26 +0000 Subject: [PATCH 5/8] Update txe. --- yarn-project/txe/src/txe_service/txe_service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index ca36fb81228..cbc3381d821 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -675,6 +675,7 @@ export class TXEService { publicCallRequest.contractAddress.toField(), publicCallRequest.functionSelector.toField(), ...publicCallRequest.callContext.toFields(), + fromSingle(sideEffectCounter), publicCallRequest.getArgsHash(), ]; return toForeignCallResult([toArray(fields)]); @@ -701,6 +702,7 @@ export class TXEService { publicTeardownCallRequest.contractAddress.toField(), publicTeardownCallRequest.functionSelector.toField(), ...publicTeardownCallRequest.callContext.toFields(), + fromSingle(sideEffectCounter), publicTeardownCallRequest.getArgsHash(), ]; From 018c58e7755d093b96a1b342dacf55c433e3fa2e Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Fri, 5 Jul 2024 08:59:19 +0000 Subject: [PATCH 6/8] Update generated file. --- .../relations/generated/avm/main.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp index ccddbaad2c8..bb16f6812c3 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp @@ -1227,56 +1227,56 @@ template class mainImpl { // Contribution 118 { Avm_DECLARE_VIEWS(118); - auto tmp = (main_sel_op_transaction_fee * (kernel_kernel_in_offset - FF(40))); + auto tmp = (main_sel_op_transaction_fee * (kernel_kernel_in_offset - FF(39))); tmp *= scaling_factor; std::get<118>(evals) += tmp; } // Contribution 119 { Avm_DECLARE_VIEWS(119); - auto tmp = (main_sel_op_chain_id * (kernel_kernel_in_offset - FF(29))); + auto tmp = (main_sel_op_chain_id * (kernel_kernel_in_offset - FF(28))); tmp *= scaling_factor; std::get<119>(evals) += tmp; } // Contribution 120 { Avm_DECLARE_VIEWS(120); - auto tmp = (main_sel_op_version * (kernel_kernel_in_offset - FF(30))); + auto tmp = (main_sel_op_version * (kernel_kernel_in_offset - FF(29))); tmp *= scaling_factor; std::get<120>(evals) += tmp; } // Contribution 121 { Avm_DECLARE_VIEWS(121); - auto tmp = (main_sel_op_block_number * (kernel_kernel_in_offset - FF(31))); + auto tmp = (main_sel_op_block_number * (kernel_kernel_in_offset - FF(30))); tmp *= scaling_factor; std::get<121>(evals) += tmp; } // Contribution 122 { Avm_DECLARE_VIEWS(122); - auto tmp = (main_sel_op_timestamp * (kernel_kernel_in_offset - FF(32))); + auto tmp = (main_sel_op_timestamp * (kernel_kernel_in_offset - FF(31))); tmp *= scaling_factor; std::get<122>(evals) += tmp; } // Contribution 123 { Avm_DECLARE_VIEWS(123); - auto tmp = (main_sel_op_coinbase * (kernel_kernel_in_offset - FF(33))); + auto tmp = (main_sel_op_coinbase * (kernel_kernel_in_offset - FF(32))); tmp *= scaling_factor; std::get<123>(evals) += tmp; } // Contribution 124 { Avm_DECLARE_VIEWS(124); - auto tmp = (main_sel_op_fee_per_da_gas * (kernel_kernel_in_offset - FF(35))); + auto tmp = (main_sel_op_fee_per_da_gas * (kernel_kernel_in_offset - FF(34))); tmp *= scaling_factor; std::get<124>(evals) += tmp; } // Contribution 125 { Avm_DECLARE_VIEWS(125); - auto tmp = (main_sel_op_fee_per_l2_gas * (kernel_kernel_in_offset - FF(36))); + auto tmp = (main_sel_op_fee_per_l2_gas * (kernel_kernel_in_offset - FF(35))); tmp *= scaling_factor; std::get<125>(evals) += tmp; } From fb8b68ff82bc48042be930aeb7c167efbbad5a04 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Fri, 5 Jul 2024 11:17:48 +0000 Subject: [PATCH 7/8] Update snapshots. --- .../__snapshots__/private_call_stack_item.test.ts.snap | 4 ++-- .../private_circuit_public_inputs.test.ts.snap | 4 ++-- .../__snapshots__/public_call_stack_item.test.ts.snap | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap index f3095850f76..ec54f081688 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_call_stack_item.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x2dacef1b7e5d66445049df33ac3edad6689d86c83c1f11bb2bdaa4748309fd9f>`; +exports[`PrivateCallStackItem computes empty item hash 1`] = `Fr<0x26caeca330b5bde6c0904c933fca80c074cc7079b4a94bcc645d79dda873b91e>`; -exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x17171557d06226fae88f7e2b57e23acd8dd767160e5149965ca0f4bebbdedb06>`; +exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x0c98ab9cd827861d5942aaf589a598c797105582acbdf039e64c4bfd78c38f90>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index c0ae96d5768..3de2e9143a2 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x25748c9f85233dc2faf9eb73b1d2772d0fcb101075845a4f507baa837dc24f6b>`; +exports[`PrivateCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x10dc67419b4a75553a6d7ac750d794f61e808408d1e36634d74e8625eb562f1e>`; -exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0d8c2da0c15b53e26d2f612cec5d0ac71ce21fb6e1b00caf3e8aa5a8bb02ad65>`; +exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x18341818a4d8cd444c03af8d87a1eae1280eab0177f053b55411c2e66419817b>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap index bfbe51f2a09..7ded37d4183 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x1331fdec4ec7bd6bb23447c47753659b68e3a285d812ab6eaf9258a902d16e8e"`; +exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x2268218e4dd9e61345f407816d63de9c7a83b031b7820a17470748bae488fb50"`; -exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x1331fdec4ec7bd6bb23447c47753659b68e3a285d812ab6eaf9258a902d16e8e"`; +exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x2268218e4dd9e61345f407816d63de9c7a83b031b7820a17470748bae488fb50"`; -exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x077ecad5709816865f4c65422d74c646739f4177691a5d87c716219e72da0705>`; +exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x1741852830903d2d946b0406b738df1016ad0ce4c7c61cd81d005466eb1c57bc>`; -exports[`PublicCallStackItem computes hash 1`] = `Fr<0x2799d225e955c0d1db6fa7adb9be5cbd2ca760a48996443a629e01ce28a3919d>`; +exports[`PublicCallStackItem computes hash 1`] = `Fr<0x117437216ff7ce8362a16eeeca67f5b34f64a81ce57489887db1d77c1a16ef25>`; From ea73dce7bc9d467ce7b33d96f19630bc83d37d08 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Fri, 5 Jul 2024 11:43:22 +0000 Subject: [PATCH 8/8] Check split counter in tail_to_public. --- .../src/components/tail_to_public_output_validator.nr | 2 ++ .../src/private_kernel_tail_to_public.nr | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr index 0cb8a53fa5f..5566b3af809 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator.nr @@ -62,6 +62,8 @@ impl TailToPublicOutputValidator { fn validate_propagated_sorted_siloed_values(self, hints: TailToPublicOutputHints) { let split_counter = self.previous_kernel.min_revertible_side_effect_counter; + assert(split_counter != 0, "min_revertible_side_effect_counter must not be 0"); + let prev_data = self.previous_kernel.end; let output_non_revertible = self.output.end_non_revertible; let output_revertible = self.output.end; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index 3c94d6c5c2f..855a506442d 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -154,6 +154,13 @@ mod tests { builder.failed(); } + #[test(should_fail_with="min_revertible_side_effect_counter must not be 0")] + fn zero_min_revertible_side_effect_counter_fails() { + let mut builder = PrivateKernelTailToPublicInputsBuilder::new(); + builder.previous_kernel.min_revertible_side_effect_counter = 0; + builder.failed(); + } + #[test(should_fail_with="Must have public calls when exporting public kernel data from the tail circuit")] fn no_public_calls_should_fail() { let mut builder = PrivateKernelTailToPublicInputsBuilder::new();