Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meta_hwm to PrivateCircuitPublicInputs #4341

Merged
merged 14 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ library Constants {
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant MAX_NEW_COMMITMENTS_PER_TX_META = 8;
uint256 internal constant MAX_NEW_NULLIFIERS_PER_TX_META = 8;
uint256 internal constant MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META = 2;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
uint256 internal constant VK_TREE_HEIGHT = 3;
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
Expand All @@ -64,8 +67,7 @@ library Constants {
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 32;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 32;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 1000;
uint256 internal constant CONTRACT_CLASS_REGISTERED_MAGIC_VALUE =
0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8;
uint256 internal constant CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = 0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8;
uint256 internal constant L1_TO_L2_MESSAGE_LENGTH = 8;
uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 25;
uint256 internal constant MAX_NOTE_FIELDS_LENGTH = 20;
Expand All @@ -79,8 +81,8 @@ library Constants {
uint256 internal constant HEADER_LENGTH = 18;
uint256 internal constant FUNCTION_DATA_LENGTH = 4;
uint256 internal constant CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 209;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 205;
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 210;
uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 201;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ export class ClientExecutionContext extends ViewDataOracle {
* @param targetContractAddress - The address of the contract to call.
* @param functionSelector - The function selector of the function to call.
* @param argsHash - The packed arguments to pass to the function.
* @param sideffectCounter - The side effect counter at the start of the call.
* @param sideEffectCounter - The side effect counter at the start of the call.
* @returns The execution result.
*/
async callPrivateFunction(
targetContractAddress: AztecAddress,
functionSelector: FunctionSelector,
argsHash: Fr,
sideffectCounter: number,
sideEffectCounter: number,
) {
this.log(
`Calling private function ${this.contractAddress}:${functionSelector} from ${this.callContext.storageContractAddress}`,
Expand All @@ -328,7 +328,7 @@ export class ClientExecutionContext extends ViewDataOracle {
const derivedCallContext = await this.deriveCallContext(
targetContractAddress,
targetArtifact,
sideffectCounter,
sideEffectCounter,
false,
false,
);
Expand Down
46 changes: 25 additions & 21 deletions yarn-project/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ struct PrivateContext {
inputs: PrivateContextInputs,
side_effect_counter: u32,

meta_hwm: u32,

args_hash : Field,
return_values : BoundedVec<Field, RETURN_VALUES_LENGTH>,

Expand Down Expand Up @@ -101,6 +103,7 @@ impl PrivateContext {
PrivateContext {
inputs: inputs,
side_effect_counter: inputs.call_context.start_side_effect_counter,
meta_hwm: 0,

args_hash: args_hash,
return_values: BoundedVec::new(0),
Expand Down Expand Up @@ -172,6 +175,7 @@ impl PrivateContext {
call_context: self.inputs.call_context,
args_hash: self.args_hash,
return_values: self.return_values.storage,
meta_hwm: self.meta_hwm,
read_requests: self.read_requests.storage,
nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage,
new_commitments: self.new_commitments.storage,
Expand Down Expand Up @@ -239,7 +243,7 @@ impl PrivateContext {
}

// docs:start:context_message_portal
pub fn message_portal(&mut self, content: Field)
pub fn message_portal(&mut self, content: Field)
// docs:end:context_message_portal
{
self.new_l2_to_l1_msgs.push(content);
Expand All @@ -254,7 +258,7 @@ impl PrivateContext {
msg_key: Field,
content: Field,
secret: Field
)
)
// docs:end:context_consume_l1_to_l2_message
{
let nullifier = process_l1_to_l2_message(self.historical_header.state.l1_to_l2_message_tree.root, self.this_address(), self.this_portal_address(), self.chain_id(), self.version(), msg_key, content, secret);
Expand All @@ -278,8 +282,8 @@ impl PrivateContext {

pub fn call_private_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
Expand All @@ -289,8 +293,8 @@ impl PrivateContext {

pub fn call_private_function_no_args(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
contract_address: AztecAddress,
function_selector: FunctionSelector,
) -> [Field; RETURN_VALUES_LENGTH] {
self.call_private_function_with_packed_args(contract_address, function_selector, 0)
}
Expand All @@ -303,14 +307,14 @@ impl PrivateContext {
) -> [Field; RETURN_VALUES_LENGTH] {
let item = call_private_function_internal(
contract_address,
function_selector,
function_selector,
args_hash,
self.side_effect_counter,
);

assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1;

assert(contract_address.eq(item.contract_address));
assert(function_selector.eq(item.function_data.selector));

Expand All @@ -333,8 +337,8 @@ impl PrivateContext {

pub fn call_public_function<ARGS_COUNT>(
&mut self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT]
) {
let args_hash = hash_args(args);
Expand All @@ -344,7 +348,7 @@ impl PrivateContext {

pub fn call_public_function_no_args(
&mut self,
contract_address: AztecAddress,
contract_address: AztecAddress,
function_selector: FunctionSelector,
) {
self.call_public_function_with_packed_args(contract_address, function_selector, 0)
Expand All @@ -357,8 +361,8 @@ impl PrivateContext {
args_hash: Field
) {
let fields = enqueue_public_function_call_internal(
contract_address,
function_selector,
contract_address,
function_selector,
args_hash,
self.side_effect_counter
);
Expand Down Expand Up @@ -395,7 +399,7 @@ impl PrivateContext {
assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
// We increment the sideffect counter by one, to account for the call itself being a side effect.
self.side_effect_counter = self.side_effect_counter + 1;

assert(args_hash == item.public_inputs.args_hash);

// Assert that the call context of the enqueued call generated by the oracle matches our request.
Expand Down Expand Up @@ -457,7 +461,7 @@ impl PublicContext {

new_l2_to_l1_msgs: BoundedVec::new(0),


unencrypted_logs_hash: BoundedVec::new(0),
unencrypted_logs_preimages_length: 0,

Expand Down Expand Up @@ -574,27 +578,27 @@ impl PublicContext {

pub fn call_public_function<ARGS_COUNT>(
_self: Self,
contract_address: AztecAddress,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field; ARGS_COUNT],
) -> [Field; RETURN_VALUES_LENGTH] {
let args_hash = hash_args(args);
assert(args_hash == arguments::pack_arguments(args));
call_public_function_internal(
contract_address,
function_selector,
contract_address,
function_selector,
args_hash,
)
}

pub fn call_public_function_no_args(
_self: Self,
contract_address: AztecAddress,
contract_address: AztecAddress,
function_selector: FunctionSelector,
) -> [Field; RETURN_VALUES_LENGTH] {
call_public_function_internal(
contract_address,
function_selector,
contract_address,
function_selector,
0,
)
}
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const MAX_READ_REQUESTS_PER_TX = 128;
export const MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
export const NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
export const NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
export const MAX_NEW_COMMITMENTS_PER_TX_META = 8;
export const MAX_NEW_NULLIFIERS_PER_TX_META = 8;
export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX_META = 2;
export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
export const VK_TREE_HEIGHT = 3;
export const FUNCTION_TREE_HEIGHT = 5;
Expand Down Expand Up @@ -64,7 +67,7 @@ export const STATE_REFERENCE_LENGTH = 10;
export const HEADER_LENGTH = 18;
export const FUNCTION_DATA_LENGTH = 4;
export const CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 204;
export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 206;
export const PRIVATE_CALL_STACK_ITEM_LENGTH = 209;
export const CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
export const CONTRACT_STORAGE_READ_LENGTH = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,41 @@ Fr {

exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `
Fr {
"asBigInt": 7655509707748365385586683354008259293573299722789964529445054772581519738939n,
"asBigInt": 17965057432304162663609649222224826000756674060660466974194339783441351638025n,
"asBuffer": {
"data": [
16,
236,
221,
108,
242,
63,
20,
45,
47,
147,
239,
244,
141,
4,
39,
183,
220,
183,
64,
232,
229,
199,
125,
34,
72,
231,
214,
40,
82,
141,
21,
179,
158,
65,
218,
247,
23,
13,
105,
121,
159,
29,
162,
114,
51,
52,
186,
54,
94,
72,
59,
196,
233,
228,
61,
55,
62,
71,
106,
218,
252,
9,
],
"type": "Buffer",
},
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/call_context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FunctionSelector } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { Fr, FunctionSelector } from './index.js';

/**
* Call context.
* @see abis/call_context.hpp
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/circuits.js/src/structs/function_data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FunctionAbi, FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { ContractFunctionDao, Fr, GeneratorIndex } from '../index.js';
import { GeneratorIndex } from '../constants.gen.js';
import { ContractFunctionDao } from '../types/contract_function_dao.js';

/**
* Function description for circuit.
Expand Down
Loading
Loading