diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 5e0b04a587a..81d2dd41d83 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -146,17 +146,17 @@ library Constants { uint256 internal constant NULLIFIER_LENGTH = 3; uint256 internal constant SCOPED_NULLIFIER_LENGTH = 4; uint256 internal constant CALLER_CONTEXT_LENGTH = 3; - uint256 internal constant PRIVATE_CALL_REQUEST_LENGTH = 6; - uint256 internal constant SCOPED_PRIVATE_CALL_REQUEST_LENGTH = 7; + uint256 internal constant PRIVATE_CALL_REQUEST_LENGTH = 16; + uint256 internal constant SCOPED_PRIVATE_CALL_REQUEST_LENGTH = 17; uint256 internal constant ROLLUP_VALIDATION_REQUESTS_LENGTH = 2; uint256 internal constant STATE_REFERENCE_LENGTH = 8; uint256 internal constant TX_CONTEXT_LENGTH = 9; 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 PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 433; uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 482; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 396; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 436; uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 41; uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16; uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; @@ -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 = 1232; + uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2307; 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; 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..dc03685f842 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -405,7 +405,16 @@ impl PrivateContext { caller_context.storage_contract_address = self.inputs.call_context.storage_contract_address; } self.private_call_requests.push( - PrivateCallRequest { hash: item.hash(), caller_context, start_side_effect_counter, end_side_effect_counter } + PrivateCallRequest { + target: item.contract_address, + call_context: item.public_inputs.call_context, + function_data: item.function_data, + args_hash: item.public_inputs.args_hash, + returns_hash: item.public_inputs.returns_hash, + caller_context, + start_side_effect_counter, + end_side_effect_counter + } ); PackedReturns::new(item.public_inputs.returns_hash) 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..d5eb93ae4b0 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 @@ -156,8 +156,8 @@ impl PrivateCallDataValidator { let caller_contract_address = scoped_call_request.contract_address; let request = scoped_call_request.call_request; - assert_eq( - request.hash, call_stack_item.hash(), "calculated private_call_hash does not match provided private_call_hash at the top of the call stack" + assert( + request.matches_stack_item(call_stack_item), "calculated private_call_hash does not match provided private_call_hash at the top of the call stack" ); let call_context = call_stack_item.public_inputs.call_context; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr index 31d93adb6ba..512d318e18e 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -88,9 +88,7 @@ mod tests { pub fn execute(&mut self) -> PrivateKernelCircuitPublicInputs { let private_call = self.private_call.to_private_call_data(); // Update the previous_kernel's private_call_stack with the current call_stack_item. - let hash = private_call.call_stack_item.hash(); - let is_delegate_call = private_call.call_stack_item.public_inputs.call_context.is_delegate_call; - self.previous_kernel.add_private_call_request(hash, is_delegate_call); + self.previous_kernel.add_private_call_from_call_stack_item(private_call.call_stack_item); let previous_kernel = self.previous_kernel.to_private_kernel_data(); let kernel = PrivateKernelInnerCircuitPrivateInputs { previous_kernel, private_call }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_against_call_request.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_against_call_request.nr index e17350a5d4d..67978f54441 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_against_call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_against_call_request.nr @@ -34,7 +34,7 @@ fn validate_against_call_request_mismatch_hash_fails() { let mut request = builder.private_call.build_private_call_request(); // Tweak the hash to be a different value. - request.call_request.hash += 1; + request.call_request.args_hash += 1; builder.validate_against_call_request(request); } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/mod.nr index 0778847c9b8..a58f1a8d033 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_output_validator_builder/mod.nr @@ -64,7 +64,7 @@ impl PrivateKernelCircuitOutputValidatorBuilder { // Append one private call request for the current call. let num_private_call_requests = self.previous_kernel.private_call_requests.len(); previous_kernel.end.private_call_stack[num_private_call_requests] = ScopedPrivateCallRequest::empty(); - previous_kernel.end.private_call_stack[num_private_call_requests].call_request.hash = 98765432; + previous_kernel.end.private_call_stack[num_private_call_requests].call_request.args_hash = 98765432; let previous_kernel_array_lengths = PrivateKernelCircuitPublicInputsArrayLengths::new(previous_kernel); let private_call = self.private_call.to_private_call_data(); diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr index 84b73931906..86403b3c94c 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_circuit_public_inputs_composer_builder/mod.nr @@ -54,7 +54,7 @@ impl PrivateKernelCircuitPublicInputsComposerBuilder { let mut previous_kernel = self.previous_kernel.to_private_kernel_circuit_public_inputs(); let num_private_call_requests = self.previous_kernel.private_call_requests.len(); previous_kernel.end.private_call_stack[num_private_call_requests] = ScopedPrivateCallRequest::empty(); - previous_kernel.end.private_call_stack[num_private_call_requests].call_request.hash = 98765432; + previous_kernel.end.private_call_stack[num_private_call_requests].call_request.args_hash = 98765432; let private_call = self.private_call.to_private_call_data(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr index 7b97099d8f4..778778d1ab9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr @@ -1,11 +1,19 @@ use crate::{ - abis::{caller_context::CallerContext, side_effect::{Ordered, RangeOrdered, Scoped}}, + abis::{ + private_call_stack_item::PrivateCallStackItem, call_context::CallContext, + function_data::FunctionData, caller_context::CallerContext, + side_effect::{Ordered, RangeOrdered, Scoped} +}, address::AztecAddress, constants::{PRIVATE_CALL_REQUEST_LENGTH, SCOPED_PRIVATE_CALL_REQUEST_LENGTH}, traits::{Empty, Serialize, Deserialize}, utils::reader::Reader }; struct PrivateCallRequest { - hash: Field, + target: AztecAddress, + call_context: CallContext, + function_data: FunctionData, + args_hash: Field, + returns_hash: Field, caller_context: CallerContext, start_side_effect_counter: u32, end_side_effect_counter: u32, @@ -28,7 +36,11 @@ impl RangeOrdered for PrivateCallRequest { impl Eq for PrivateCallRequest { fn eq(self, other: PrivateCallRequest) -> bool { - (self.hash == other.hash) + (self.target == other.target) + & (self.call_context == other.call_context) + & (self.function_data == other.function_data) + & (self.args_hash == other.args_hash) + & (self.returns_hash == other.returns_hash) & (self.caller_context == other.caller_context) & (self.start_side_effect_counter == other.start_side_effect_counter) & (self.end_side_effect_counter == other.end_side_effect_counter) @@ -38,7 +50,11 @@ impl Eq for PrivateCallRequest { impl Empty for PrivateCallRequest { fn empty() -> Self { PrivateCallRequest { - hash: 0, + target: AztecAddress::empty(), + call_context: CallContext::empty(), + function_data: FunctionData::empty(), + args_hash: 0, + returns_hash: 0, caller_context: CallerContext::empty(), start_side_effect_counter: 0, end_side_effect_counter: 0, @@ -50,7 +66,11 @@ impl Serialize for PrivateCallRequest { fn serialize(self) -> [Field; PRIVATE_CALL_REQUEST_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(); - fields.push(self.hash); + fields.push(self.target.to_field()); + fields.extend_from_array(self.call_context.serialize()); + fields.extend_from_array(self.function_data.serialize()); + fields.push(self.args_hash); + fields.push(self.returns_hash); fields.extend_from_array(self.caller_context.serialize()); fields.push(self.start_side_effect_counter as Field); fields.push(self.end_side_effect_counter as Field); @@ -65,7 +85,11 @@ impl Deserialize for PrivateCallRequest { fn deserialize(fields: [Field; PRIVATE_CALL_REQUEST_LENGTH]) -> PrivateCallRequest { let mut reader = Reader::new(fields); let item = PrivateCallRequest { - hash: reader.read(), + target: reader.read_struct(AztecAddress::deserialize), + call_context: reader.read_struct(CallContext::deserialize), + function_data: reader.read_struct(FunctionData::deserialize), + args_hash: reader.read(), + returns_hash: reader.read(), caller_context: reader.read_struct(CallerContext::deserialize), start_side_effect_counter: reader.read_u32(), end_side_effect_counter: reader.read_u32(), @@ -79,6 +103,18 @@ impl PrivateCallRequest { pub fn scope(self, contract_address: AztecAddress) -> ScopedPrivateCallRequest { ScopedPrivateCallRequest { call_request: self, contract_address } } + + pub fn matches_stack_item(self, stack_item: PrivateCallStackItem) -> bool { + (self.target == stack_item.contract_address) + & (self.call_context == stack_item.public_inputs.call_context) + & (self.function_data == stack_item.function_data) + & (self.args_hash == stack_item.public_inputs.args_hash) + & (self.returns_hash == stack_item.public_inputs.returns_hash) + & (self.start_side_effect_counter + == stack_item.public_inputs.start_side_effect_counter) + & (self.end_side_effect_counter + == stack_item.public_inputs.end_side_effect_counter) + } } struct ScopedPrivateCallRequest { 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..81496505942 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 = 0x2dacef1b7e5d66445049df33ac3edad6689d86c83c1f11bb2bdaa4748309fd9f; 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..1d9a035b12c 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 = 0x25748c9f85233dc2faf9eb73b1d2772d0fcb101075845a4f507baa837dc24f6b; 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..3b2ea1e741f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -197,7 +197,7 @@ global SCOPED_NOTE_HASH_LENGTH = NOTE_HASH_LENGTH + 1; global NULLIFIER_LENGTH = 3; global SCOPED_NULLIFIER_LENGTH = NULLIFIER_LENGTH + 1; global CALLER_CONTEXT_LENGTH = 2 * AZTEC_ADDRESS_LENGTH + 1; -global PRIVATE_CALL_REQUEST_LENGTH = 3 + CALLER_CONTEXT_LENGTH; +global PRIVATE_CALL_REQUEST_LENGTH = AZTEC_ADDRESS_LENGTH + CALL_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH + 4 + CALLER_CONTEXT_LENGTH; global SCOPED_PRIVATE_CALL_REQUEST_LENGTH = PRIVATE_CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; global ROLLUP_VALIDATION_REQUESTS_LENGTH = MAX_BLOCK_NUMBER_LENGTH; global STATE_REFERENCE_LENGTH: u32 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; 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..fa3397e73b4 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 @@ -217,7 +217,7 @@ impl FixtureBuilder { } pub fn build_private_call_request(self) -> ScopedPrivateCallRequest { - let hash = self.to_private_call_stack_item().hash(); + let item = self.to_private_call_stack_item(); let is_delegate_call = self.is_delegate_call; let mut caller_context = CallerContext::empty(); caller_context.is_static_call = self.is_static_call; @@ -226,7 +226,11 @@ impl FixtureBuilder { caller_context.storage_contract_address = self.storage_contract_address; }; PrivateCallRequest { - hash, + target: item.contract_address, + call_context: item.public_inputs.call_context, + function_data: item.function_data, + args_hash: item.public_inputs.args_hash, + returns_hash: item.public_inputs.returns_hash, caller_context, start_side_effect_counter: self.counter_start, end_side_effect_counter: self.counter @@ -784,7 +788,33 @@ impl FixtureBuilder { self.unencrypted_log_preimages_length = preimages_length; } - pub fn add_private_call_request(&mut self, hash: Field, is_delegate_call: bool) { + pub fn add_private_call_from_call_stack_item(&mut self, item: PrivateCallStackItem) { + let mut caller_context = CallerContext::empty(); + let is_delegate_call = item.public_inputs.call_context.is_delegate_call; + caller_context.is_static_call = self.is_static_call; + if is_delegate_call { + caller_context.msg_sender = self.msg_sender; + caller_context.storage_contract_address = self.storage_contract_address; + } + let start_counter = item.public_inputs.start_side_effect_counter; + let end_counter = item.public_inputs.end_side_effect_counter; + self.counter = end_counter + 1; + + self.private_call_requests.push( + PrivateCallRequest { + target: item.contract_address, + call_context: item.public_inputs.call_context, + function_data: item.function_data, + args_hash: item.public_inputs.args_hash, + returns_hash: item.public_inputs.returns_hash, + caller_context, + start_side_effect_counter: start_counter, + end_side_effect_counter: end_counter + }.scope(self.contract_address) + ); + } + + pub fn add_private_call_request(&mut self, args_hash: Field, is_delegate_call: bool) { let mut caller_context = CallerContext::empty(); caller_context.is_static_call = self.is_static_call; if is_delegate_call { @@ -794,8 +824,23 @@ impl FixtureBuilder { let start_counter = self.next_counter(); let end_counter = start_counter + 10; self.counter = end_counter + 1; + + let target = AztecAddress::empty(); + let call_context = CallContext::empty(); + let function_data = FunctionData::empty(); + let returns_hash = 0; + self.private_call_requests.push( - PrivateCallRequest { hash, caller_context, start_side_effect_counter: start_counter, end_side_effect_counter: end_counter }.scope(self.contract_address) + PrivateCallRequest { + target, + call_context, + function_data, + args_hash, + returns_hash, + caller_context, + start_side_effect_counter: start_counter, + end_side_effect_counter: end_counter + }.scope(self.contract_address) ); } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index d4c57415687..a4ec3031333 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -130,17 +130,17 @@ export const SCOPED_NOTE_HASH_LENGTH = 4; export const NULLIFIER_LENGTH = 3; export const SCOPED_NULLIFIER_LENGTH = 4; export const CALLER_CONTEXT_LENGTH = 3; -export const PRIVATE_CALL_REQUEST_LENGTH = 6; -export const SCOPED_PRIVATE_CALL_REQUEST_LENGTH = 7; +export const PRIVATE_CALL_REQUEST_LENGTH = 16; +export const SCOPED_PRIVATE_CALL_REQUEST_LENGTH = 17; export const ROLLUP_VALIDATION_REQUESTS_LENGTH = 2; export const STATE_REFERENCE_LENGTH = 8; 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 PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 433; export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 482; -export const PRIVATE_CALL_STACK_ITEM_LENGTH = 396; +export const PRIVATE_CALL_STACK_ITEM_LENGTH = 436; export const PUBLIC_CONTEXT_INPUTS_LENGTH = 41; export const AGGREGATION_OBJECT_LENGTH = 16; export const SCOPED_READ_REQUEST_LEN = 3; @@ -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 = 1232; +export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2307; export const PUBLIC_ACCUMULATED_DATA_LENGTH = 983; export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3258; export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 383; 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..f3095850f76 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<0x2dacef1b7e5d66445049df33ac3edad6689d86c83c1f11bb2bdaa4748309fd9f>`; -exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x029b1573da033e679c68a55e05987602c5e73419c4fdfdd6104e178a9a360834>`; +exports[`PrivateCallStackItem computes hash 1`] = `Fr<0x17171557d06226fae88f7e2b57e23acd8dd767160e5149965ca0f4bebbdedb06>`; 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..c0ae96d5768 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<0x25748c9f85233dc2faf9eb73b1d2772d0fcb101075845a4f507baa837dc24f6b>`; -exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0b02f49b7283dacf553c5cfc0615c979fdd1cd146a1d4e71c78610345a711d22>`; +exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x0d8c2da0c15b53e26d2f612cec5d0ac71ce21fb6e1b00caf3e8aa5a8bb02ad65>`; diff --git a/yarn-project/circuits.js/src/structs/call_context.ts b/yarn-project/circuits.js/src/structs/call_context.ts index 556c2b97461..0d2aa3e0a7a 100644 --- a/yarn-project/circuits.js/src/structs/call_context.ts +++ b/yarn-project/circuits.js/src/structs/call_context.ts @@ -1,10 +1,11 @@ import { FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { pedersenHash } from '@aztec/foundation/crypto'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; -import { CALL_CONTEXT_LENGTH } from '../constants.gen.js'; +import { CALL_CONTEXT_LENGTH, GeneratorIndex } from '../constants.gen.js'; /** * Call context. @@ -125,4 +126,8 @@ export class CallContext { callContext.sideEffectCounter === this.sideEffectCounter ); } + + hash(): Fr { + return pedersenHash(this.toFields(), GeneratorIndex.CALL_CONTEXT); + } } diff --git a/yarn-project/circuits.js/src/structs/function_data.ts b/yarn-project/circuits.js/src/structs/function_data.ts index 65a00a98a2b..490636695cf 100644 --- a/yarn-project/circuits.js/src/structs/function_data.ts +++ b/yarn-project/circuits.js/src/structs/function_data.ts @@ -48,6 +48,15 @@ export class FunctionData { return this.selector.isEmpty(); } + /** + * Returns whether this instance is equal to another. + * @param other + * @returns + */ + equals(other: FunctionData): boolean { + return this.selector.equals(other.selector) && this.isPrivate === other.isPrivate; + } + /** * Returns a new instance of FunctionData with zero function selector. * @param args - Arguments to pass to the constructor. diff --git a/yarn-project/circuits.js/src/structs/private_call_request.ts b/yarn-project/circuits.js/src/structs/private_call_request.ts index 2363165925c..a81b8d36fa7 100644 --- a/yarn-project/circuits.js/src/structs/private_call_request.ts +++ b/yarn-project/circuits.js/src/structs/private_call_request.ts @@ -2,14 +2,33 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; +import { CallContext } from './call_context.js'; import { CallerContext } from './caller_context.js'; +import { FunctionData } from './function_data.js'; +import { type PrivateCallStackItem } from './index.js'; export class PrivateCallRequest { constructor( /** - * The call stack item hash of the call. + * The address of the contract being called. */ - public hash: Fr, + public target: AztecAddress, + /** + * The call context of the call. + */ + public callContext: CallContext, + /** + * The function data of the call. + */ + public functionData: FunctionData, + /** + * The hash of the arguments of the call. + */ + public argsHash: Fr, + /** + * The hash of the return values of the call. + */ + public returnsHash: Fr, /** * The call context of the contract making the call. */ @@ -25,12 +44,25 @@ export class PrivateCallRequest { ) {} toFields(): Fr[] { - return serializeToFields([this.hash, this.callerContext, this.startSideEffectCounter, this.endSideEffectCounter]); + return serializeToFields([ + this.target, + this.callContext, + this.functionData, + this.argsHash, + this.returnsHash, + this.callerContext, + this.startSideEffectCounter, + this.endSideEffectCounter, + ]); } static fromFields(fields: Fr[] | FieldReader) { const reader = FieldReader.asReader(fields); return new PrivateCallRequest( + reader.readObject(AztecAddress), + reader.readObject(CallContext), + reader.readObject(FunctionData), + reader.readField(), reader.readField(), reader.readObject(CallerContext), reader.readU32(), @@ -39,12 +71,25 @@ export class PrivateCallRequest { } toBuffer() { - return serializeToBuffer(this.hash, this.callerContext, this.startSideEffectCounter, this.endSideEffectCounter); + return serializeToBuffer( + this.target, + this.callContext, + this.functionData, + this.argsHash, + this.returnsHash, + this.callerContext, + this.startSideEffectCounter, + this.endSideEffectCounter, + ); } public static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); return new PrivateCallRequest( + reader.readObject(AztecAddress), + reader.readObject(CallContext), + reader.readObject(FunctionData), + Fr.fromBuffer(reader), Fr.fromBuffer(reader), reader.readObject(CallerContext), reader.readNumber(), @@ -54,7 +99,11 @@ export class PrivateCallRequest { isEmpty() { return ( - this.hash.isZero() && + this.target.isZero() && + this.callContext.isEmpty() && + this.functionData.isEmpty() && + this.argsHash.isZero() && + this.returnsHash.isZero() && this.callerContext.isEmpty() && this.startSideEffectCounter === 0 && this.endSideEffectCounter === 0 @@ -62,12 +111,25 @@ export class PrivateCallRequest { } public static empty() { - return new PrivateCallRequest(Fr.ZERO, CallerContext.empty(), 0, 0); + return new PrivateCallRequest( + AztecAddress.ZERO, + CallContext.empty(), + FunctionData.empty(), + Fr.ZERO, + Fr.ZERO, + CallerContext.empty(), + 0, + 0, + ); } equals(callRequest: PrivateCallRequest) { return ( - callRequest.hash.equals(this.hash) && + callRequest.target.equals(this.target) && + callRequest.callContext.equals(this.callContext) && + callRequest.functionData.equals(this.functionData) && + callRequest.argsHash.equals(this.argsHash) && + callRequest.returnsHash.equals(this.returnsHash) && callRequest.callerContext.equals(this.callerContext) && callRequest.startSideEffectCounter === this.startSideEffectCounter && callRequest.endSideEffectCounter === this.endSideEffectCounter @@ -75,7 +137,19 @@ export class PrivateCallRequest { } toString() { - return `PrivateCallRequest(hash: ${this.hash}, callerContext: ${this.callerContext}, startSideEffectCounter: ${this.startSideEffectCounter}, endSideEffectCounter: ${this.endSideEffectCounter})`; + return `PrivateCallRequest(target: ${this.target}, callContext: ${this.callContext}, functionData: ${this.functionData}, argsHash: ${this.argsHash}, returnsHash: ${this.returnsHash}, callerContext: ${this.callerContext}, startSideEffectCounter: ${this.startSideEffectCounter}, endSideEffectCounter: ${this.endSideEffectCounter})`; + } + + matchesStackItem(stackItem: PrivateCallStackItem) { + return ( + stackItem.contractAddress.equals(this.target) && + stackItem.publicInputs.callContext.equals(this.callContext) && + stackItem.functionData.equals(this.functionData) && + stackItem.publicInputs.argsHash.equals(this.argsHash) && + stackItem.publicInputs.returnsHash.equals(this.returnsHash) && + stackItem.publicInputs.startSideEffectCounter.equals(new Fr(this.startSideEffectCounter)) && + stackItem.publicInputs.endSideEffectCounter.equals(new Fr(this.endSideEffectCounter)) + ); } } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index f380c432041..968a491ca78 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -635,7 +635,16 @@ export function makeCallRequest(seed = 1): CallRequest { } function makePrivateCallRequest(seed = 1): PrivateCallRequest { - return new PrivateCallRequest(fr(seed), makeCallerContext(seed + 0x2), seed + 0x10, seed + 0x11); + return new PrivateCallRequest( + makeAztecAddress(seed), + makeCallContext(seed + 0x1), + new FunctionData(makeSelector(seed + 0x2), /*isPrivate=*/ true), + fr(seed + 0x3), + fr(seed + 0x4), + makeCallerContext(seed + 0x5), + seed + 0x10, + seed + 0x11, + ); } /** diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 163df4f5e43..32e454308cb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -533,7 +533,11 @@ export function mapCallerContextToNoir(callerContext: CallerContext): CallerCont function mapPrivateCallRequestFromNoir(callRequest: PrivateCallRequestNoir) { return new PrivateCallRequest( - mapFieldFromNoir(callRequest.hash), + mapAztecAddressFromNoir(callRequest.target), + mapCallContextFromNoir(callRequest.call_context), + mapFunctionDataFromNoir(callRequest.function_data), + mapFieldFromNoir(callRequest.args_hash), + mapFieldFromNoir(callRequest.returns_hash), mapCallerContextFromNoir(callRequest.caller_context), mapNumberFromNoir(callRequest.start_side_effect_counter), mapNumberFromNoir(callRequest.end_side_effect_counter), @@ -542,7 +546,11 @@ function mapPrivateCallRequestFromNoir(callRequest: PrivateCallRequestNoir) { function mapPrivateCallRequestToNoir(callRequest: PrivateCallRequest): PrivateCallRequestNoir { return { - hash: mapFieldToNoir(callRequest.hash), + target: mapAztecAddressToNoir(callRequest.target), + call_context: mapCallContextToNoir(callRequest.callContext), + function_data: mapFunctionDataToNoir(callRequest.functionData), + args_hash: mapFieldToNoir(callRequest.argsHash), + returns_hash: mapFieldToNoir(callRequest.returnsHash), caller_context: mapCallerContextToNoir(callRequest.callerContext), start_side_effect_counter: mapNumberToNoir(callRequest.startSideEffectCounter), end_side_effect_counter: mapNumberToNoir(callRequest.endSideEffectCounter), diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 7eeb02a34d1..2c6bf39ea2c 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -564,8 +564,11 @@ describe('Private Execution test suite', () => { expect(result.nestedExecutions[0].returnValues).toEqual([new Fr(privateIncrement)]); // check that Aztec.nr calculated the call stack item hash like cpp does - const expectedCallStackItemHash = result.nestedExecutions[0].callStackItem.hash(); - expect(result.callStackItem.publicInputs.privateCallRequests[0].hash).toEqual(expectedCallStackItemHash); + expect( + result.callStackItem.publicInputs.privateCallRequests[0].matchesStackItem( + result.nestedExecutions[0].callStackItem, + ), + ).toBeTruthy(); }); });