Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
10eb0b5
Update trees as we generate blocks
spalladino Mar 28, 2023
27862b3
Block builder test in progress
spalladino Mar 28, 2023
2b61f99
Fix import and format
spalladino Mar 28, 2023
5525f98
Build fixes after rebase
spalladino Mar 28, 2023
2ff3d0f
Formatting
spalladino Mar 29, 2023
a40e526
Use same empty proof size as cpp
spalladino Mar 29, 2023
4ccd2cf
Fix fr initialization in test
spalladino Mar 29, 2023
b24e5f6
Aztec address back to 32 bytes
spalladino Mar 29, 2023
f6407bb
Adjust rollup subtree sizes
spalladino Mar 29, 2023
4e6c10f
Add toString to fields
spalladino Mar 29, 2023
4f4b34a
Remove unused checkLength util
spalladino Mar 29, 2023
351b5e2
Make empty txs explicit
spalladino Mar 29, 2023
4000c23
Expose leaf values in merkle trees for debugging
spalladino Mar 29, 2023
ca80973
Handle empty txs in block builder
spalladino Mar 29, 2023
3ef1e8d
Update root rollup inputs
spalladino Mar 29, 2023
b7379b5
Pedersen hash new contract data from a tx
spalladino Mar 29, 2023
73a94fd
Add util for inspecting a tree
spalladino Mar 29, 2023
ddc1508
Updates to block builder (wip)
spalladino Mar 29, 2023
871d09e
Block builder test passing
spalladino Mar 29, 2023
f052b80
Merge remote-tracking branch 'origin/master' into palla/update-trees-…
spalladino Mar 29, 2023
3db619e
Pick toBuffer32 is available in serialization (fixes ethAddress)
spalladino Mar 29, 2023
4b7b8af
Updated test
PhilWindle Mar 29, 2023
3787e12
Format
spalladino Mar 29, 2023
51ab655
Update base rollup inputs snapshot
spalladino Mar 29, 2023
fea2fc6
Update circuits to latest (includes fix for base rollup inputs)
spalladino Mar 29, 2023
eea2d67
Merge remote-tracking branch 'origin/master' into palla/update-trees-…
spalladino Mar 29, 2023
f3db683
Merge remote-tracking branch 'origin/master' into palla/update-trees-…
spalladino Mar 29, 2023
7f92e44
Update circuits to latest
spalladino Mar 29, 2023
0d86b59
Fix aztec.js dockerfile build
spalladino Mar 29, 2023
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
2 changes: 1 addition & 1 deletion circuits
Submodule circuits updated 501 files
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder
COPY . .
RUN cd aztec-rpc && yarn build
RUN cd aztec-js && yarn build
WORKDIR /usr/src/yarn-project/aztec.js
RUN yarn build && yarn formatting && yarn test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ portal_contract_address: 0x707070707070707070707070707070707070707
is_private: 1

proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ]
vk: 0x12ca00
vk: 0x12c940
vk_index: 42
vk_path: [ 0x1000 0x1001 0x1002 ]
public_inputs: end:
Expand Down Expand Up @@ -231,7 +231,7 @@ portal_contract_address: 0x707070707070707070707070707070707070707
is_private: 1

proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ]
vk: 0x135540
vk: 0x135480
vk_index: 42
vk_path: [ 0x1000 0x1001 0x1002 ]
]
Expand Down Expand Up @@ -284,11 +284,11 @@ sibling_path: [ 0x2006 0x2007 0x2008 0x2009 0x200a 0x200b 0x200c 0x200d ]
sibling_path: [ 0x2007 0x2008 0x2009 0x200a 0x200b 0x200c 0x200d 0x200e ]
]
new_commitments_subtree_sibling_path:
[ 0x3000 0x3001 0x3002 0x3003 0x3004 0x3005 0x3006 0x3007 ]
[ 0x3000 0x3001 0x3002 0x3003 0x3004 ]
new_nullifiers_subtree_sibling_path:
[ 0x4000 0x4001 0x4002 0x4003 0x4004 0x4005 0x4006 0x4007 ]
[ 0x4000 0x4001 0x4002 0x4003 0x4004 ]
new_contracts_subtree_sibling_path:
[ 0x5000 0x5001 0x5002 0x5003 ]
[ 0x5000 0x5001 0x5002 ]
historic_private_data_tree_root_membership_witnesses:
[ leaf_index: 6000
sibling_path: [ 0x6000 0x6001 0x6002 0x6003 0x6004 0x6005 0x6006 0x6007 ]
Expand Down
15 changes: 12 additions & 3 deletions yarn-project/circuits.js/src/structs/base_rollup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ describe('structs/base_rollup', () => {
MembershipWitness.mock(NULLIFIER_TREE_HEIGHT, x),
);

const newCommitmentsSubtreeSiblingPath = range(PRIVATE_DATA_TREE_HEIGHT, 0x3000).map(x => fr(x));
const newNullifiersSubtreeSiblingPath = range(NULLIFIER_TREE_HEIGHT, 0x4000).map(x => fr(x));
const newContractsSubtreeSiblingPath = range(CONTRACT_TREE_HEIGHT, 0x5000).map(x => fr(x));
const newCommitmentsSubtreeSiblingPath = range(
PRIVATE_DATA_TREE_HEIGHT - BaseRollupInputs.PRIVATE_DATA_SUBTREE_HEIGHT,
0x3000,
).map(x => fr(x));
const newNullifiersSubtreeSiblingPath = range(
NULLIFIER_TREE_HEIGHT - BaseRollupInputs.NULLIFIER_SUBTREE_HEIGHT,
0x4000,
).map(x => fr(x));
const newContractsSubtreeSiblingPath = range(
CONTRACT_TREE_HEIGHT - BaseRollupInputs.CONTRACT_SUBTREE_HEIGHT,
0x5000,
).map(x => fr(x));

const historicPrivateDataTreeRootMembershipWitnesses: BaseRollupInputs['historicPrivateDataTreeRootMembershipWitnesses'] =
[
Expand Down
28 changes: 23 additions & 5 deletions yarn-project/circuits.js/src/structs/base_rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { serializeToBuffer } from '../utils/serialize.js';
import {
CONTRACT_TREE_HEIGHT,
CONTRACT_TREE_ROOTS_TREE_HEIGHT,
KERNEL_NEW_COMMITMENTS_LENGTH,
KERNEL_NEW_CONTRACTS_LENGTH,
KERNEL_NEW_NULLIFIERS_LENGTH,
NULLIFIER_TREE_HEIGHT,
PRIVATE_DATA_TREE_HEIGHT,
Expand Down Expand Up @@ -85,6 +87,10 @@ export class ConstantBaseRollupData {
* Inputs to the base rollup circuit
*/
export class BaseRollupInputs {
public static PRIVATE_DATA_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_COMMITMENTS_LENGTH * 2);
public static CONTRACT_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_CONTRACTS_LENGTH * 2);
public static NULLIFIER_SUBTREE_HEIGHT = Math.log2(KERNEL_NEW_NULLIFIERS_LENGTH * 2);

constructor(
public kernelData: [PreviousKernelData, PreviousKernelData],

Expand Down Expand Up @@ -112,9 +118,21 @@ export class BaseRollupInputs {
) {
assertLength(this, 'lowNullifierLeafPreimages', 2 * KERNEL_NEW_NULLIFIERS_LENGTH);
assertLength(this, 'lowNullifierMembershipWitness', 2 * KERNEL_NEW_NULLIFIERS_LENGTH);
assertLength(this, 'newCommitmentsSubtreeSiblingPath', PRIVATE_DATA_TREE_HEIGHT);
assertLength(this, 'newNullifiersSubtreeSiblingPath', NULLIFIER_TREE_HEIGHT);
assertLength(this, 'newContractsSubtreeSiblingPath', CONTRACT_TREE_HEIGHT);
assertLength(
this,
'newCommitmentsSubtreeSiblingPath',
PRIVATE_DATA_TREE_HEIGHT - BaseRollupInputs.PRIVATE_DATA_SUBTREE_HEIGHT,
);
assertLength(
this,
'newNullifiersSubtreeSiblingPath',
NULLIFIER_TREE_HEIGHT - BaseRollupInputs.NULLIFIER_SUBTREE_HEIGHT,
);
assertLength(
this,
'newContractsSubtreeSiblingPath',
CONTRACT_TREE_HEIGHT - BaseRollupInputs.CONTRACT_SUBTREE_HEIGHT,
);
}

static from(fields: FieldsOf<BaseRollupInputs>): BaseRollupInputs {
Expand Down Expand Up @@ -155,7 +173,7 @@ export class BaseRollupPublicInputs {
public endPrivateDataTreeSnapshot: AppendOnlyTreeSnapshot,

public startNullifierTreeSnapshot: AppendOnlyTreeSnapshot,
public endNullifierTreeSnapshots: AppendOnlyTreeSnapshot,
public endNullifierTreeSnapshot: AppendOnlyTreeSnapshot,

public startContractTreeSnapshot: AppendOnlyTreeSnapshot,
public endContractTreeSnapshot: AppendOnlyTreeSnapshot,
Expand Down Expand Up @@ -196,7 +214,7 @@ export class BaseRollupPublicInputs {
this.endPrivateDataTreeSnapshot,

this.startNullifierTreeSnapshot,
this.endNullifierTreeSnapshots,
this.endNullifierTreeSnapshot,

this.startContractTreeSnapshot,
this.endContractTreeSnapshot,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/call_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CallContext {
return serializeToBuffer(
this.msgSender,
this.storageContractAddress,
this.portalContractAddress.toBuffer(),
this.portalContractAddress,
this.isDelegateCall,
this.isStaticCall,
this.isContractDeployment,
Expand Down
37 changes: 19 additions & 18 deletions yarn-project/circuits.js/src/structs/root_rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@ import { Fr } from '@aztec/foundation';
import { assertLength, FieldsOf } from '../utils/jsUtils.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { AppendOnlyTreeSnapshot } from './base_rollup.js';
import { CONTRACT_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT } from './constants.js';
import { CONTRACT_TREE_ROOTS_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT } from './constants.js';
import { PreviousRollupData } from './merge_rollup.js';
import { AggregationObject } from './shared.js';

export class RootRollupInputs {
constructor(
public previousRollupData: [PreviousRollupData, PreviousRollupData],

public startPrivateDataTreeSnapshot: AppendOnlyTreeSnapshot,
// Note: the start_nullifier_tree_snapshot is contained within previous_rollup_data[0].public_inputs.start_nullifier_tree_snapshot.
public startContractTreeSnapshot: AppendOnlyTreeSnapshot,

// For inserting the new subtrees into their respective trees:
// Note: the insertion leaf index can be derived from the above snapshots' `next_available_leaf_index` values.
public newCommitmentsSubtreeSiblingPath: Fr[],
public newNullifiersSubtreeSiblingPath: Fr[],
public newContractsSubtreeSiblingPath: Fr[],
public newHistoricPrivateDataTreeRootSiblingPath: Fr[],
public newHistoricContractDataTreeRootSiblingPath: Fr[],
) {
assertLength(this, 'newCommitmentsSubtreeSiblingPath', PRIVATE_DATA_TREE_HEIGHT);
assertLength(this, 'newNullifiersSubtreeSiblingPath', NULLIFIER_TREE_HEIGHT);
assertLength(this, 'newContractsSubtreeSiblingPath', CONTRACT_TREE_HEIGHT);
assertLength(this, 'newHistoricPrivateDataTreeRootSiblingPath', PRIVATE_DATA_TREE_HEIGHT);
assertLength(this, 'newHistoricContractDataTreeRootSiblingPath', CONTRACT_TREE_ROOTS_TREE_HEIGHT);
}

toBuffer() {
return serializeToBuffer(
this.previousRollupData,
this.startPrivateDataTreeSnapshot,
this.startContractTreeSnapshot,
this.newCommitmentsSubtreeSiblingPath,
this.newNullifiersSubtreeSiblingPath,
this.newContractsSubtreeSiblingPath,
this.newHistoricPrivateDataTreeRootSiblingPath,
this.newHistoricContractDataTreeRootSiblingPath,
);
}

static from(fields: FieldsOf<RootRollupInputs>): RootRollupInputs {
return new RootRollupInputs(...RootRollupInputs.getFields(fields));
}

static getFields(fields: FieldsOf<RootRollupInputs>) {
return [
fields.previousRollupData,
fields.newHistoricPrivateDataTreeRootSiblingPath,
fields.newHistoricContractDataTreeRootSiblingPath,
] as const;
}
}

export class RootRollupPublicInputs {
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/circuits.js/src/structs/shared.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BufferReader } from '@aztec/foundation';
import { Fq, Fr } from '@aztec/foundation/fields';
import { assertLength, checkLength, range } from '../utils/jsUtils.js';
import { assertLength, range } from '../utils/jsUtils.js';
import { Bufferable, serializeToBuffer } from '../utils/serialize.js';

export class MembershipWitness<N extends number> {
constructor(pathSize: N, public leafIndex: UInt32, public siblingPath: Fr[]) {
checkLength(this.siblingPath, pathSize, 'MembershipWitness.siblingPath');
assertLength(this, 'siblingPath', pathSize);
}

toBuffer() {
Expand Down
29 changes: 25 additions & 4 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EthAddress, Fq, Fr, AztecAddress } from '@aztec/foundation';
import { CallContext, PrivateCircuitPublicInputs } from '../index.js';
import { AztecAddress, EthAddress, Fq, Fr } from '@aztec/foundation';
import { CallContext, PrivateCircuitPublicInputs, RootRollupPublicInputs } from '../index.js';
import { AppendOnlyTreeSnapshot, BaseRollupPublicInputs, ConstantBaseRollupData } from '../structs/base_rollup.js';
import {
ARGS_LENGTH,
Expand Down Expand Up @@ -38,9 +38,9 @@ import {
AffineElement,
AggregationObject,
ComposerType,
EcdsaSignature,
MembershipWitness,
UInt8Vector,
EcdsaSignature,
} from '../structs/shared.js';
import { ContractDeploymentData, SignedTxRequest, TxContext, TxRequest } from '../structs/tx.js';
import { CommitmentMap, G1AffineElement, VerificationKey } from '../structs/verification_key.js';
Expand Down Expand Up @@ -246,10 +246,31 @@ export function makeBaseRollupPublicInputs(seed = 0) {
makeAppendOnlyTreeSnapshot(seed + 0x600),
makeAppendOnlyTreeSnapshot(seed + 0x700),
makeAppendOnlyTreeSnapshot(seed + 0x800),
range(2, seed + 0x901).map(fr) as [Fr, Fr],
[fr(seed + 0x901), fr(seed + 0x902)],
);
}

export function makeRootRollupPublicInputs(seed = 0) {
return RootRollupPublicInputs.from({
startContractTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x100),
startNullifierTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x200),
startPrivateDataTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x300),
startTreeOfHistoricContractTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x400),
startTreeOfHistoricPrivateDataTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x500),
endContractTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x600),
endNullifierTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x700),
endPrivateDataTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x800),
endTreeOfHistoricContractTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x900),
endTreeOfHistoricPrivateDataTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x1000),
endAggregationObject: makeAggregationObject(seed + 0x1100),
newCommitmentsHash: fr(seed + 0x1200),
newContractDataHash: fr(seed + 0x1200),
newL1MsgsHash: fr(seed + 0x1200),
newNullifiersHash: fr(seed + 0x1200),
proverContributionsHash: fr(seed + 0x1200),
});
}

/**
* Test only. Easy to identify big endian field serialize.
* @param num - The number.
Expand Down
12 changes: 0 additions & 12 deletions yarn-project/circuits.js/src/utils/jsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ export function assertLength<F extends string, T extends { [f in F]: { length: n
}
}

/**
* Asserts a collection has a certain length.
* @param arr Collection to check.
* @param expected Expected length.
* @param label Optional name for the collection to use in the error message.
*/
export function checkLength(arr: { length: number }, expected: number, label = 'array') {
if (arr.length !== expected) {
throw new Error(`Invalid length for ${label} (got ${arr.length}, expected ${expected})`);
}
}

/**
* Strips methods of a type.
*/
Expand Down
12 changes: 12 additions & 0 deletions yarn-project/circuits.js/src/utils/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export type Bufferable =
| Buffer
| number
| string
| {
/**
* Serialize to a buffer of 32 bytes.
*/
toBuffer32: () => Buffer;
}
| {
/**
* Serialize to a buffer.
Expand All @@ -113,6 +119,10 @@ export type Bufferable =
}
| Bufferable[];

function isSerializableToBuffer32(obj: Object): obj is { toBuffer32: () => Buffer } {
return !!(obj as { toBuffer32: () => Buffer }).toBuffer32;
}

/**
* Serializes a list of objects contiguously for calling into wasm.
* @param objs - Objects to serialize.
Expand All @@ -134,6 +144,8 @@ export function serializeToBufferArray(...objs: Bufferable[]): Buffer[] {
} else if (typeof obj === 'string') {
ret.push(numToUInt32BE(obj.length));
ret.push(Buffer.from(obj));
} else if (isSerializableToBuffer32(obj)) {
ret.push(obj.toBuffer32());
} else {
ret.push(obj.toBuffer());
}
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/foundation/src/fields/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class Fr {
toBuffer() {
return toBufferBE(this.value, Fr.SIZE_IN_BYTES);
}

toString() {
return '0x' + this.value.toString(16);
}
}

export class Fq {
Expand All @@ -53,4 +57,8 @@ export class Fq {
toBuffer() {
return toBufferBE(this.value, Fq.SIZE_IN_BYTES);
}

toString() {
return '0x' + this.value.toString(16);
}
}
3 changes: 3 additions & 0 deletions yarn-project/sequencer-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@
"@aztec/foundation": "workspace:^",
"@aztec/l1-contracts": "workspace:^",
"@aztec/l2-block": "workspace:^",
"@aztec/merkle-tree": "workspace:^",
"@aztec/p2p": "workspace:^",
"@aztec/tx": "workspace:^",
"@aztec/world-state": "workspace:^",
"lodash.flatmap": "^4.5.0",
"lodash.times": "^4.3.2",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.4.3",
"@rushstack/eslint-patch": "^1.1.4",
"@types/jest": "^29.4.0",
"@types/lodash.flatmap": "^4.5.7",
"@types/lodash.times": "^4.3.7",
"@types/node": "^18.7.23",
"concurrently": "^7.6.0",
Expand Down
Loading