Skip to content

Commit

Permalink
feat: Only one tx per base rollup (AztecProtocol#3742)
Browse files Browse the repository at this point in the history
This PR makes the base rollup process only one TX at a time, lowering
the min TX per rollup from 4 to 2.
  • Loading branch information
sirasistant authored Jan 2, 2024
1 parent c3d8b5d commit 9eef247
Show file tree
Hide file tree
Showing 16 changed files with 394 additions and 793 deletions.
32 changes: 14 additions & 18 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ library Constants {
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
uint256 internal constant KERNELS_PER_BASE_ROLLUP = 2;
uint256 internal constant MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP = 128;
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 = 5;
uint256 internal constant CONTRACT_TREE_HEIGHT = 16;
Expand All @@ -51,14 +47,14 @@ library Constants {
uint256 internal constant NULLIFIER_TREE_HEIGHT = 20;
uint256 internal constant L1_TO_L2_MSG_TREE_HEIGHT = 16;
uint256 internal constant ROLLUP_VK_TREE_HEIGHT = 8;
uint256 internal constant CONTRACT_SUBTREE_HEIGHT = 1;
uint256 internal constant CONTRACT_SUBTREE_SIBLING_PATH_LENGTH = 15;
uint256 internal constant NOTE_HASH_SUBTREE_HEIGHT = 7;
uint256 internal constant NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 25;
uint256 internal constant NULLIFIER_SUBTREE_HEIGHT = 7;
uint256 internal constant CONTRACT_SUBTREE_HEIGHT = 0;
uint256 internal constant CONTRACT_SUBTREE_SIBLING_PATH_LENGTH = 16;
uint256 internal constant NOTE_HASH_SUBTREE_HEIGHT = 6;
uint256 internal constant NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 26;
uint256 internal constant NULLIFIER_SUBTREE_HEIGHT = 6;
uint256 internal constant PUBLIC_DATA_SUBTREE_HEIGHT = 4;
uint256 internal constant ARCHIVE_HEIGHT = 16;
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 13;
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 14;
uint256 internal constant PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 36;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
Expand Down Expand Up @@ -86,12 +82,12 @@ library Constants {
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 161;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 87;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 144;
uint256 internal constant COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
uint256 internal constant PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 128;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 104;
uint256 internal constant L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 128;
uint256 internal constant LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 128;
uint256 internal constant COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 1024;
uint256 internal constant CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 32;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 52;
uint256 internal constant L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 64;
uint256 internal constant LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 64;
}
57 changes: 17 additions & 40 deletions l1-contracts/src/core/libraries/Decoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ library Decoder {
bytes32[] baseLeaves;
bytes32[] l2ToL1Msgs;
bytes baseLeaf;
bytes32 encryptedLogsHashKernel1;
bytes32 encryptedLogsHashKernel2;
bytes32 unencryptedLogsHashKernel1;
bytes32 unencryptedLogsHashKernel2;
bytes32 encryptedLogsHash;
bytes32 unencryptedLogsHash;
uint256 l1Tol2MsgsCount;
}

Expand Down Expand Up @@ -210,7 +208,7 @@ library Decoder {

// Commitments
uint256 count = read4(_l2Block, offset);
vars.baseLeaves = new bytes32[](count / (Constants.MAX_NEW_COMMITMENTS_PER_TX * 2));
vars.baseLeaves = new bytes32[](count / Constants.MAX_NEW_COMMITMENTS_PER_TX);
offsets.commitment = BLOCK_HEADER_OFFSET + 0x4;
offset += 0x4 + count * 0x20;
offsets.nullifier = offset + 0x4; // + 0x4 to offset by next read4
Expand Down Expand Up @@ -261,24 +259,15 @@ library Decoder {
/*
* Compute the leaf to insert.
* Leaf_i = (
* newCommitmentsKernel1,
* newCommitmentsKernel2,
* newNullifiersKernel1,
* newNullifiersKernel2,
* newPublicDataWritesKernel1,
* newPublicDataWritesKernel2,
* newL2ToL1MsgsKernel1,
* newL2ToL1MsgsKernel2,
* newContractLeafKernel1,
* newContractLeafKernel2,
* newContractDataKernel1.aztecAddress,
* newContractDataKernel1.ethAddress (padded to 32 bytes),
* newContractDataKernel2.aztecAddress,
* newContractDataKernel2.ethAddress (padded to 32 bytes), ____
* encryptedLogsHashKernel1, |
* encryptedLogsHashKernel2, |=> Computed below from logs' preimages.
* unencryptedLogsHashKernel1, |
* unencryptedLogsHashKernel2 ____|
* newCommitmentsKernel,
* newNullifiersKernel,
* newPublicDataWritesKernel,
* newL2ToL1MsgsKernel,
* newContractLeafKernel,
* newContractDataKernel.aztecAddress,
* newContractDataKernel.ethAddress (padded to 32 bytes),
* encryptedLogsHash, |
* unencryptedLogsHash, ____|=> Computed below from logs' preimages.
* );
* Note that we always read data, the l2Block (atm) must therefore include dummy or zero-notes for
* Zero values.
Expand All @@ -288,14 +277,10 @@ library Decoder {
* Compute encrypted and unencrypted logs hashes corresponding to the current leaf.
* Note: will advance offsets by the number of bytes processed.
*/
(vars.encryptedLogsHashKernel1, offsets.encryptedLogs) =
computeKernelLogsHash(offsets.encryptedLogs, _l2Block);
(vars.encryptedLogsHashKernel2, offsets.encryptedLogs) =
(vars.encryptedLogsHash, offsets.encryptedLogs) =
computeKernelLogsHash(offsets.encryptedLogs, _l2Block);

(vars.unencryptedLogsHashKernel1, offsets.unencryptedLogs) =
computeKernelLogsHash(offsets.unencryptedLogs, _l2Block);
(vars.unencryptedLogsHashKernel2, offsets.unencryptedLogs) =
(vars.unencryptedLogsHash, offsets.unencryptedLogs) =
computeKernelLogsHash(offsets.unencryptedLogs, _l2Block);

// Insertions are split into multiple `bytes.concat` to work around stack too deep.
Expand All @@ -310,19 +295,11 @@ library Decoder {
slice(_l2Block, offsets.contracts, Constants.CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP)
),
bytes.concat(
slice(_l2Block, offsets.contractData, 0x20), // newContractDataKernel1.aztecAddress
slice(_l2Block, offsets.contractData, 0x20), // newContractDataKernel.aztecAddress
bytes12(0),
slice(_l2Block, offsets.contractData + 0x20, 0x14), // newContractDataKernel1.ethAddress
slice(_l2Block, offsets.contractData + 0x34, 0x20), // newContractDataKernel2.aztecAddress
bytes12(0),
slice(_l2Block, offsets.contractData + 0x54, 0x14) // newContractDataKernel2.ethAddress
slice(_l2Block, offsets.contractData + 0x20, 0x14) // newContractDataKernel.ethAddress
),
bytes.concat(
vars.encryptedLogsHashKernel1,
vars.encryptedLogsHashKernel2,
vars.unencryptedLogsHashKernel1,
vars.unencryptedLogsHashKernel2
)
bytes.concat(vars.encryptedLogsHash, vars.unencryptedLogsHash)
);

offsets.commitment += Constants.COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP;
Expand Down
32 changes: 14 additions & 18 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export const MAX_PENDING_READ_REQUESTS_PER_TX = 128;
export const NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
export const NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
export const KERNELS_PER_BASE_ROLLUP = 2;
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 = 5;
export const CONTRACT_TREE_HEIGHT = 16;
Expand All @@ -37,14 +33,14 @@ export const PUBLIC_DATA_TREE_HEIGHT = 40;
export const NULLIFIER_TREE_HEIGHT = 20;
export const L1_TO_L2_MSG_TREE_HEIGHT = 16;
export const ROLLUP_VK_TREE_HEIGHT = 8;
export const CONTRACT_SUBTREE_HEIGHT = 1;
export const CONTRACT_SUBTREE_SIBLING_PATH_LENGTH = 15;
export const NOTE_HASH_SUBTREE_HEIGHT = 7;
export const NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 25;
export const NULLIFIER_SUBTREE_HEIGHT = 7;
export const CONTRACT_SUBTREE_HEIGHT = 0;
export const CONTRACT_SUBTREE_SIBLING_PATH_LENGTH = 16;
export const NOTE_HASH_SUBTREE_HEIGHT = 6;
export const NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 26;
export const NULLIFIER_SUBTREE_HEIGHT = 6;
export const PUBLIC_DATA_SUBTREE_HEIGHT = 4;
export const ARCHIVE_HEIGHT = 16;
export const NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 13;
export const NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 14;
export const PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 36;
export const L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
export const L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12;
Expand Down Expand Up @@ -72,14 +68,14 @@ export const EMPTY_NULLIFIED_COMMITMENT = 1000000;
export const CALL_PRIVATE_FUNCTION_RETURN_SIZE = 161;
export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 87;
export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 144;
export const COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
export const NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 4096;
export const PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 2048;
export const CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 64;
export const CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 128;
export const CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 104;
export const L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 128;
export const LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 128;
export const COMMITMENTS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
export const NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
export const PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP = 1024;
export const CONTRACTS_NUM_BYTES_PER_BASE_ROLLUP = 32;
export const CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP = 64;
export const CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED = 52;
export const L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP = 64;
export const LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 64;
export enum GeneratorIndex {
COMMITMENT = 1,
COMMITMENT_NONCE = 2,
Expand Down
55 changes: 20 additions & 35 deletions yarn-project/circuits.js/src/structs/rollup/base_rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { BufferReader, Tuple } from '@aztec/foundation/serialize';
import {
ARCHIVE_HEIGHT,
CONTRACT_SUBTREE_SIBLING_PATH_LENGTH,
KERNELS_PER_BASE_ROLLUP,
MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP,
MAX_NEW_NULLIFIERS_PER_TX,
MAX_PUBLIC_DATA_READS_PER_TX,
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH,
Expand Down Expand Up @@ -98,7 +97,7 @@ export class BaseRollupInputs {
/**
* Data of the 2 kernels that preceded this base rollup circuit.
*/
public kernelData: Tuple<PreviousKernelData, typeof KERNELS_PER_BASE_ROLLUP>,
public kernelData: PreviousKernelData,
/**
* Snapshot of the note hash tree at the start of the base rollup circuit.
*/
Expand All @@ -123,23 +122,23 @@ export class BaseRollupInputs {
/**
* The nullifiers to be inserted in the tree, sorted high to low.
*/
public sortedNewNullifiers: Tuple<Fr, typeof MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP>,
public sortedNewNullifiers: Tuple<Fr, typeof MAX_NEW_NULLIFIERS_PER_TX>,
/**
* The indexes of the sorted nullifiers to the original ones.
*/
public sortednewNullifiersIndexes: Tuple<UInt32, typeof MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP>,
public sortednewNullifiersIndexes: Tuple<UInt32, typeof MAX_NEW_NULLIFIERS_PER_TX>,
/**
* The nullifiers which need to be updated to perform the batch insertion of the new nullifiers.
* See `StandardIndexedTree.batchInsert` function for more details.
*/
public lowNullifierLeafPreimages: Tuple<NullifierLeafPreimage, typeof MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP>,
public lowNullifierLeafPreimages: Tuple<NullifierLeafPreimage, typeof MAX_NEW_NULLIFIERS_PER_TX>,
/**
* Membership witnesses for the nullifiers which need to be updated to perform the batch insertion of the new
* nullifiers.
*/
public lowNullifierMembershipWitness: Tuple<
MembershipWitness<typeof NULLIFIER_TREE_HEIGHT>,
typeof MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP
typeof MAX_NEW_NULLIFIERS_PER_TX
>,

/**
Expand All @@ -157,65 +156,51 @@ export class BaseRollupInputs {
/**
* The public data writes to be inserted in the tree, sorted high slot to low slot.
*/
public sortedPublicDataWrites: Tuple<
Tuple<PublicDataTreeLeaf, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
>,
public sortedPublicDataWrites: Tuple<PublicDataTreeLeaf, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,

/**
* The indexes of the sorted public data writes to the original ones.
*/
public sortedPublicDataWritesIndexes: Tuple<
Tuple<UInt32, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
>,
public sortedPublicDataWritesIndexes: Tuple<UInt32, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
/**
* The public data writes which need to be updated to perform the batch insertion of the new public data writes.
* See `StandardIndexedTree.batchInsert` function for more details.
*/
public lowPublicDataWritesPreimages: Tuple<
Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
PublicDataTreeLeafPreimage,
typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
>,
/**
* Membership witnesses for the nullifiers which need to be updated to perform the batch insertion of the new
* nullifiers.
*/
public lowPublicDataWritesMembershipWitnesses: Tuple<
Tuple<MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>,
typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
>,

/**
* Sibling path "pointing to" where the new public data subtree should be inserted into the public data tree.
*/
public publicDataWritesSubtreeSiblingPaths: Tuple<
Tuple<Fr, typeof PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH>,
typeof KERNELS_PER_BASE_ROLLUP
>,
public publicDataWritesSubtreeSiblingPath: Tuple<Fr, typeof PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH>,

/**
* Preimages of leaves which are to be read by the public data reads.
*/
public publicDataReadsPreimages: Tuple<
Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
>,
public publicDataReadsPreimages: Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
/**
* Sibling paths of leaves which are to be read by the public data reads.
* Each item in the array is the sibling path that corresponds to a read request.
*/
public publicDataReadsMembershipWitnesses: Tuple<
Tuple<MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
typeof KERNELS_PER_BASE_ROLLUP
MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>,
typeof MAX_PUBLIC_DATA_READS_PER_TX
>,

/**
* Membership witnesses of blocks referred by each of the 2 kernels.
*/
public archiveRootMembershipWitnesses: Tuple<
MembershipWitness<typeof ARCHIVE_HEIGHT>,
typeof KERNELS_PER_BASE_ROLLUP
>,
public archiveRootMembershipWitness: MembershipWitness<typeof ARCHIVE_HEIGHT>,
/**
* Data which is not modified by the base rollup circuit.
*/
Expand Down Expand Up @@ -245,10 +230,10 @@ export class BaseRollupInputs {
fields.sortedPublicDataWritesIndexes,
fields.lowPublicDataWritesPreimages,
fields.lowPublicDataWritesMembershipWitnesses,
fields.publicDataWritesSubtreeSiblingPaths,
fields.publicDataWritesSubtreeSiblingPath,
fields.publicDataReadsPreimages,
fields.publicDataReadsMembershipWitnesses,
fields.archiveRootMembershipWitnesses,
fields.archiveRootMembershipWitness,
fields.constants,
] as const;
}
Expand Down
Loading

0 comments on commit 9eef247

Please sign in to comment.