Skip to content

Commit

Permalink
chore: Increase functions per contract from 16 to 32 (#3503)
Browse files Browse the repository at this point in the history
We got users hitting the contract functions limit.
  • Loading branch information
spalladino authored Dec 1, 2023
1 parent 30fca33 commit ebdeea3
Show file tree
Hide file tree
Showing 29 changed files with 543 additions and 558 deletions.
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ constexpr size_t LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP =

// TREES RELATED CONSTANTS
constexpr size_t VK_TREE_HEIGHT = 3;
constexpr size_t FUNCTION_TREE_HEIGHT = 4;
constexpr size_t FUNCTION_TREE_HEIGHT = 5;
constexpr size_t CONTRACT_TREE_HEIGHT = 16;
constexpr size_t NOTE_HASH_TREE_HEIGHT = 32;
constexpr size_t PUBLIC_DATA_TREE_HEIGHT = 254;
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ library Constants {
uint256 internal constant MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_BASE_ROLLUP = 32;
uint256 internal constant MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP = 32;
uint256 internal constant VK_TREE_HEIGHT = 3;
uint256 internal constant FUNCTION_TREE_HEIGHT = 4;
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
uint256 internal constant CONTRACT_TREE_HEIGHT = 16;
uint256 internal constant NOTE_HASH_TREE_HEIGHT = 32;
uint256 internal constant PUBLIC_DATA_TREE_HEIGHT = 254;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/constants_gen.nr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ global MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP: Field = 32;

// TREES RELATED CONSTANTS
global VK_TREE_HEIGHT: Field = 3;
global FUNCTION_TREE_HEIGHT: Field = 4;
global FUNCTION_TREE_HEIGHT: Field = 5;
global CONTRACT_TREE_HEIGHT: Field = 16;
global NOTE_HASH_TREE_HEIGHT: Field = 32;
global PUBLIC_DATA_TREE_HEIGHT: Field = 254;
Expand Down
64 changes: 32 additions & 32 deletions yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -612,41 +612,41 @@ Fr {

exports[`abis computes function tree root 1`] = `
Fr {
"asBigInt": 21090938391652199999535994101952511109725456907725564751008805452452294036010n,
"asBigInt": 18902231782334398705464257251364974449663398212058621439366133672872128659209n,
"asBuffer": {
"data": [
46,
161,
12,
80,
15,
148,
101,
167,
237,
48,
42,
247,
41,
202,
72,
183,
227,
53,
212,
51,
133,
173,
223,
25,
183,
14,
155,
146,
117,
106,
78,
36,
159,
144,
106,
160,
190,
170,
211,
213,
47,
102,
180,
244,
10,
42,
5,
105,
58,
143,
86,
204,
9,
239,
140,
187,
195,
116,
164,
13,
173,
191,
9,
],
"type": "Buffer",
},
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP = 128;
export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_BASE_ROLLUP = 32;
export const MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP = 32;
export const VK_TREE_HEIGHT = 3;
export const FUNCTION_TREE_HEIGHT = 4;
export const FUNCTION_TREE_HEIGHT = 5;
export const CONTRACT_TREE_HEIGHT = 16;
export const NOTE_HASH_TREE_HEIGHT = 32;
export const PUBLIC_DATA_TREE_HEIGHT = 254;
Expand Down
16 changes: 16 additions & 0 deletions yarn-project/circuits.js/src/structs/call_stack_item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { BufferReader } from '@aztec/foundation/serialize';

import { computePrivateCallStackItemHash, computePublicCallStackItemHash } from '../abis/abis.js';
import { serializeToBuffer } from '../utils/serialize.js';
Expand Down Expand Up @@ -39,6 +40,21 @@ export class PrivateCallStackItem {
return serializeToBuffer(this.contractAddress, this.functionData, this.publicInputs, this.isExecutionRequest);
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateCallStackItem {
const reader = BufferReader.asReader(buffer);
return new PrivateCallStackItem(
reader.readObject(AztecAddress),
reader.readObject(FunctionData),
reader.readObject(PrivateCircuitPublicInputs),
reader.readBoolean(),
);
}

/**
* Returns a new instance of PrivateCallStackItem with zero contract address, function data and public inputs.
* @returns A new instance of PrivateCallStackItem with zero contract address, function data and public inputs.
Expand Down
11 changes: 11 additions & 0 deletions yarn-project/circuits.js/src/structs/kernel/private_kernel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { makePrivateKernelInputsInner } from '../../tests/factories.js';
import { PrivateKernelInputsInner } from './private_kernel.js';

describe('PrivateKernel', function () {
it(`serializes PrivateKernelInputsInner to buffer and deserializes it back`, () => {
const expected = makePrivateKernelInputsInner();
const buffer = expected.toBuffer();
const res = PrivateKernelInputsInner.fromBuffer(buffer);
expect(res).toEqual(expected);
});
});
33 changes: 32 additions & 1 deletion yarn-project/circuits.js/src/structs/kernel/private_kernel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fr } from '@aztec/foundation/fields';
import { Tuple } from '@aztec/foundation/serialize';
import { BufferReader, Tuple } from '@aztec/foundation/serialize';

import {
CONTRACT_TREE_HEIGHT,
Expand Down Expand Up @@ -100,6 +100,27 @@ export class PrivateCallData {
toBuffer(): Buffer {
return serializeToBuffer(...PrivateCallData.getFields(this));
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateCallData {
const reader = BufferReader.asReader(buffer);
return new PrivateCallData(
reader.readObject(PrivateCallStackItem),
reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, CallRequest),
reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, CallRequest),
reader.readObject(Proof),
reader.readObject(VerificationKey),
reader.readObject(MembershipWitness.deserializer(FUNCTION_TREE_HEIGHT)),
reader.readObject(MembershipWitness.deserializer(CONTRACT_TREE_HEIGHT)),
reader.readArray(MAX_READ_REQUESTS_PER_CALL, ReadRequestMembershipWitness),
reader.readObject(Fr),
reader.readObject(Fr),
);
}
}

/**
Expand Down Expand Up @@ -148,6 +169,16 @@ export class PrivateKernelInputsInner {
toBuffer() {
return serializeToBuffer(this.previousKernel, this.privateCall);
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateKernelInputsInner {
const reader = BufferReader.asReader(buffer);
return new PrivateKernelInputsInner(reader.readObject(PreviousKernelData), reader.readObject(PrivateCallData));
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions yarn-project/circuits.js/src/structs/membership_witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ export class MembershipWitness<N extends number> {
return this.fromBufferArray(leafIndex, siblingPath);
}

/**
* Creates a deserializer object for a MembershipWitness with a given size.
* @param size - Expected size of the witness.
* @returns A deserializer object.
*/
static deserializer<N extends number>(size: N): { fromBuffer(buffer: Buffer | BufferReader): MembershipWitness<N> } {
return {
fromBuffer: (buffer: Buffer | BufferReader) => {
const reader = BufferReader.asReader(buffer);
const leafIndex = toBigIntBE(reader.readBytes(32));
const siblingPath = reader.readArray(size, Fr);
return new MembershipWitness(size, leafIndex, siblingPath);
},
};
}

// import { SiblingPath } from '@aztec/merkle-tree';
// static fromSiblingPath<N extends number>(leafIndex: bigint, siblingPath: SiblingPath<N>): MembershipWitness<N> {
// return new MembershipWitness<N>(siblingPath.pathSize, leafIndex, siblingPath.toFieldArray() as Tuple<Fr, N>);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArrayEmpty } from '@aztec/foundation/collection';
import { Fr } from '@aztec/foundation/fields';
import { Tuple } from '@aztec/foundation/serialize';
import { BufferReader, Tuple } from '@aztec/foundation/serialize';

import {
MAX_NEW_COMMITMENTS_PER_CALL,
Expand Down Expand Up @@ -106,6 +106,7 @@ export class PrivateCircuitPublicInputs {
*/
public version: Fr,
) {}

/**
* Create PrivateCircuitPublicInputs from a fields dictionary.
* @param fields - The dictionary.
Expand All @@ -115,6 +116,36 @@ export class PrivateCircuitPublicInputs {
return new PrivateCircuitPublicInputs(...PrivateCircuitPublicInputs.getFields(fields));
}

/**
* Deserializes from a buffer or reader.
* @param buffer - Buffer or reader to read from.
* @returns The deserialized instance.
*/
static fromBuffer(buffer: Buffer | BufferReader): PrivateCircuitPublicInputs {
const reader = BufferReader.asReader(buffer);
return new PrivateCircuitPublicInputs(
reader.readObject(CallContext),
reader.readObject(Fr),
reader.readArray(RETURN_VALUES_LENGTH, Fr),
reader.readArray(MAX_READ_REQUESTS_PER_CALL, Fr),
reader.readArray(MAX_PENDING_READ_REQUESTS_PER_CALL, Fr),
reader.readArray(MAX_NEW_COMMITMENTS_PER_CALL, Fr),
reader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, Fr),
reader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, Fr),
reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr),
reader.readArray(MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, Fr),
reader.readArray(MAX_NEW_L2_TO_L1_MSGS_PER_CALL, Fr),
reader.readArray(NUM_FIELDS_PER_SHA256, Fr),
reader.readArray(NUM_FIELDS_PER_SHA256, Fr),
reader.readObject(Fr),
reader.readObject(Fr),
reader.readObject(BlockHeader),
reader.readObject(ContractDeploymentData),
reader.readObject(Fr),
reader.readObject(Fr),
);
}

/**
* Create an empty PrivateCircuitPublicInputs.
* @returns An empty PrivateCircuitPublicInputs object.
Expand Down
28 changes: 22 additions & 6 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {

const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
const cliVersion: string = JSON.parse(readFileSync(packageJsonPath).toString()).version;
const logJson = (obj: object) => log(JSON.stringify(obj, null, 2));

program.name('aztec-cli').description('CLI for interacting with Aztec.').version(cliVersion);

Expand Down Expand Up @@ -242,10 +243,11 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
'Optional deployment salt as a hex string for generating the deployment address.',
parseSaltFromHexString,
)
.option('--json', 'Emit output as json')
// `options.wait` is default true. Passing `--no-wait` will set it to false.
// https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
.option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
.action(async (artifactPath, { rpcUrl, publicKey, args: rawArgs, portalAddress, salt, wait }) => {
.action(async (artifactPath, { json, rpcUrl, publicKey, args: rawArgs, portalAddress, salt, wait }) => {
const contractArtifact = await getContractArtifact(artifactPath, log);
const constructorArtifact = contractArtifact.functions.find(({ name }) => name === 'constructor');

Expand Down Expand Up @@ -277,12 +279,26 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
debugLogger(`Deploy tx sent with hash ${txHash}`);
if (wait) {
const deployed = await tx.wait();
log(`\nContract deployed at ${deployed.contract.completeAddress.address.toString()}\n`);
log(`Contract partial address ${deployed.contract.completeAddress.partialAddress.toString()}\n`);
const { address, partialAddress } = deployed.contract.completeAddress;
if (json) {
logJson({ address: address.toString(), partialAddress: partialAddress.toString() });
} else {
log(`\nContract deployed at ${address.toString()}\n`);
log(`Contract partial address ${partialAddress.toString()}\n`);
}
} else {
log(`\nContract Address: ${deploy.completeAddress?.address.toString() ?? 'N/A'}`);
log(`Contract Partial Address: ${deploy.completeAddress?.partialAddress.toString() ?? 'N/A'}`);
log(`Deployment transaction hash: ${txHash}\n`);
const { address, partialAddress } = deploy.completeAddress ?? {};
if (json) {
logJson({
address: address?.toString() ?? 'N/A',
partialAddress: partialAddress?.toString() ?? 'N/A',
txHash: txHash.toString(),
});
} else {
log(`\nContract Address: ${deploy.completeAddress?.address.toString() ?? 'N/A'}`);
log(`Contract Partial Address: ${deploy.completeAddress?.partialAddress.toString() ?? 'N/A'}`);
log(`Deployment transaction hash: ${txHash}\n`);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN yarn cache clean && yarn workspaces focus --production
# TODO: Not very minimal as chromium adds about 500MB of bloat :/ Separate or install at test runtime?
FROM node:18-alpine
RUN apk update && apk add --no-cache \
jq \
bash \
chromium \
chromium-chromedriver \
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/end-to-end/src/e2e_nested_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AztecAddress, BatchCall, DebugLogger, Fr, PXE, Wallet, toBigIntBE } from '@aztec/aztec.js';
import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing';
import { ChildContract, ImportTestContract, ParentContract, TestContract } from '@aztec/noir-contracts/types';

import { writeFileSync } from 'fs';

import { setup } from './fixtures/utils.js';

describe('e2e_nested_contract', () => {
Expand Down Expand Up @@ -31,6 +34,15 @@ describe('e2e_nested_contract', () => {
.entryPoint(childContract.address, childContract.methods.value.selector.toField())
.send()
.wait();

if (isGenerateTestDataEnabled()) {
const privateKernelInputs = getTestData('private-kernel-inputs-inner');
const nestedCallPrivateKernelInput = privateKernelInputs[privateKernelInputs.length - 1];
writeFileSync(
'../noir-protocol-circuits/src/fixtures/nested-call-private-kernel-inner.hex',
nestedCallPrivateKernelInput.toBuffer().toString('hex'),
);
}
}, 100_000);

it('fails simulation if calling a function not allowed to be called externally', async () => {
Expand Down
15 changes: 4 additions & 11 deletions yarn-project/end-to-end/src/guides/up_quick_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@
set -eux

# The following accounts and pks must match the ones exposed by the sandbox.
# This test also requires that no other transactions have been sent to the sandbox
# so the contract address hardcoded into $CONTRACT is correct. Otherwise, we'd need
# to extract the deployed address from the cli `deploy` command.

# docs:start:declare-accounts
ALICE="0x29e53e3e43377c80c8a1e390ed90ddf1167f376c4c063844ec18f8a81516c1c0"
BOB="0x2b66c968c3ae3b827b6614719141be12667bad86f13b401c667d64a7c56d911c"
ALICE="0x06357cc85cb8fc561adbf741f63cd75efa26ffba1c80d431ec77d036d8edf022"
BOB="0x1b18a972d54db0283a04abaace5f7b03c3fca5a4b2c0cf113b457de6ea4991e7"
ALICE_PRIVATE_KEY="0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281"
# docs:end:declare-accounts

# docs:start:deploy
aztec-cli deploy \
TokenContractArtifact \
--salt 0 \
--args $ALICE

CONTRACT="0x18a018014978f3a6b8f69548fbfc5fded6b829b36becea24dd7f7ee34927dff7"
CONTRACT=$(aztec-cli deploy TokenContractArtifact --salt 0 --args $ALICE --json | jq -r '.address')
echo "Deployed contract at $CONTRACT"
aztec-cli check-deploy --contract-address $CONTRACT
# docs:end:deploy

Expand Down
Loading

0 comments on commit ebdeea3

Please sign in to comment.