Skip to content

Commit

Permalink
refactor: updated ordering in a block
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 28, 2023
1 parent 0d9db59 commit 2c82e7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
50 changes: 24 additions & 26 deletions yarn-project/types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class L2Block {
* @param endPublicDataTreeRoot - The tree root of the public data tree at the end of the rollup.
* @param newCommitments - The commitments to be inserted into the private data tree.
* @param newNullifiers - The nullifiers to be inserted into the nullifier tree.
* @param newPublicDataWrites - The public data writes to be inserted into the public data tree.
* @param newContracts - The contracts leafs to be inserted into the contract tree.
* @param newContractData - The aztec_address and eth_address for the deployed contract and its portal contract.
*/
Expand All @@ -46,19 +47,18 @@ export class L2Block {
public startContractTreeSnapshot: AppendOnlyTreeSnapshot,
public startTreeOfHistoricPrivateDataTreeRootsSnapshot: AppendOnlyTreeSnapshot,
public startTreeOfHistoricContractTreeRootsSnapshot: AppendOnlyTreeSnapshot,
public startPublicDataTreeRoot: Fr,
public endPrivateDataTreeSnapshot: AppendOnlyTreeSnapshot,
public endNullifierTreeSnapshot: AppendOnlyTreeSnapshot,
public endContractTreeSnapshot: AppendOnlyTreeSnapshot,
public endTreeOfHistoricPrivateDataTreeRootsSnapshot: AppendOnlyTreeSnapshot,
public endTreeOfHistoricContractTreeRootsSnapshot: AppendOnlyTreeSnapshot,
public endPublicDataTreeRoot: Fr,
public newCommitments: Fr[],
public newNullifiers: Fr[],
public newPublicDataWrites: PublicDataWrite[],
public newContracts: Fr[],
public newContractData: ContractData[],
// TODO: We set the public data entries at the end so we don't have to change the L1 decoder yet
public startPublicDataTreeRoot: Fr,
public endPublicDataTreeRoot: Fr,
public newPublicDataWrites: PublicDataWrite[],
) {}

static random(l2BlockNum: number, txsPerBlock = 1) {
Expand Down Expand Up @@ -111,9 +111,9 @@ export class L2Block {
endPublicDataTreeRoot: Fr;
newCommitments: Fr[];
newNullifiers: Fr[];
newPublicDataWrites: PublicDataWrite[];
newContracts: Fr[];
newContractData: ContractData[];
newPublicDataWrites: PublicDataWrite[];
}) {
return new this(
fields.number,
Expand All @@ -122,18 +122,18 @@ export class L2Block {
fields.startContractTreeSnapshot,
fields.startTreeOfHistoricPrivateDataTreeRootsSnapshot,
fields.startTreeOfHistoricContractTreeRootsSnapshot,
fields.startPublicDataTreeRoot,
fields.endPrivateDataTreeSnapshot,
fields.endNullifierTreeSnapshot,
fields.endContractTreeSnapshot,
fields.endTreeOfHistoricPrivateDataTreeRootsSnapshot,
fields.endTreeOfHistoricContractTreeRootsSnapshot,
fields.endPublicDataTreeRoot,
fields.newCommitments,
fields.newNullifiers,
fields.newPublicDataWrites,
fields.newContracts,
fields.newContractData,
fields.startPublicDataTreeRoot,
fields.endPublicDataTreeRoot,
fields.newPublicDataWrites,
);
}

Expand All @@ -149,23 +149,22 @@ export class L2Block {
this.startContractTreeSnapshot,
this.startTreeOfHistoricPrivateDataTreeRootsSnapshot,
this.startTreeOfHistoricContractTreeRootsSnapshot,
this.startPublicDataTreeRoot,
this.endPrivateDataTreeSnapshot,
this.endNullifierTreeSnapshot,
this.endContractTreeSnapshot,
this.endTreeOfHistoricPrivateDataTreeRootsSnapshot,
this.endTreeOfHistoricContractTreeRootsSnapshot,
this.endPublicDataTreeRoot,
this.newCommitments.length,
this.newCommitments,
this.newNullifiers.length,
this.newNullifiers,
this.newPublicDataWrites.length,
this.newPublicDataWrites,
this.newContracts.length,
this.newContracts,
this.newContractData,
// TODO: We set the public data entries at the end so we don't have to change the L1 decoder yet
this.startPublicDataTreeRoot,
this.endPublicDataTreeRoot,
this.newPublicDataWrites.length,
this.newPublicDataWrites,
);
}

Expand All @@ -190,19 +189,18 @@ export class L2Block {
const startContractTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const startTreeOfHistoricPrivateDataTreeRootsSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const startTreeOfHistoricContractTreeRootsSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const startPublicDataTreeRoot = reader.readObject(Fr);
const endPrivateDataTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const endNullifierTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const endContractTreeSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const endTreeOfHistoricPrivateDataTreeRootsSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const endTreeOfHistoricContractTreeRootsSnapshot = reader.readObject(AppendOnlyTreeSnapshot);
const endPublicDataTreeRoot = reader.readObject(Fr);
const newCommitments = reader.readVector(Fr);
const newNullifiers = reader.readVector(Fr);
const newPublicDataWrites = reader.readVector(PublicDataWrite);
const newContracts = reader.readVector(Fr);
const newContractData = reader.readArray(newContracts.length, ContractData);
// TODO: We set the public data entries at the end so we don't have to change the L1 decoder yet
const startPublicDataTreeRoot = reader.readObject(Fr);
const endPublicDataTreeRoot = reader.readObject(Fr);
const newPublicDataWrites = reader.readVector(PublicDataWrite);

return L2Block.fromFields({
number,
Expand All @@ -220,9 +218,9 @@ export class L2Block {
endPublicDataTreeRoot,
newCommitments,
newNullifiers,
newPublicDataWrites,
newContracts,
newContractData,
newPublicDataWrites,
});
}

Expand All @@ -245,6 +243,10 @@ export class L2Block {
KERNEL_NEW_NULLIFIERS_LENGTH * txIndex,
KERNEL_NEW_NULLIFIERS_LENGTH * (txIndex + 1),
);
const newPublicDataWrites = this.newPublicDataWrites.slice(
STATE_TRANSITIONS_LENGTH * txIndex,
STATE_TRANSITIONS_LENGTH * (txIndex + 1),
);
const newContracts = this.newContracts.slice(
KERNEL_NEW_CONTRACTS_LENGTH * txIndex,
KERNEL_NEW_CONTRACTS_LENGTH * (txIndex + 1),
Expand All @@ -253,12 +255,8 @@ export class L2Block {
KERNEL_NEW_CONTRACTS_LENGTH * txIndex,
KERNEL_NEW_CONTRACTS_LENGTH * (txIndex + 1),
);
const newPublicDataWrites = this.newPublicDataWrites.slice(
STATE_TRANSITIONS_LENGTH * txIndex,
STATE_TRANSITIONS_LENGTH * (txIndex + 1),
);

return new L2Tx(newCommitments, newNullifiers, newContracts, newContractData, newPublicDataWrites);
return new L2Tx(newCommitments, newNullifiers, newPublicDataWrites, newContracts, newContractData);
}

/**
Expand All @@ -285,28 +283,28 @@ export class L2Block {
`startPrivateDataTreeSnapshot: ${inspectTreeSnapshot(this.startPrivateDataTreeSnapshot)}`,
`startNullifierTreeSnapshot: ${inspectTreeSnapshot(this.startNullifierTreeSnapshot)}`,
`startContractTreeSnapshot: ${inspectTreeSnapshot(this.startContractTreeSnapshot)}`,
`startPublicDataTreeRoot: ${this.startPublicDataTreeRoot.toString()}`,
`startTreeOfHistoricPrivateDataTreeRootsSnapshot: ${inspectTreeSnapshot(
this.startTreeOfHistoricPrivateDataTreeRootsSnapshot,
)}`,
`startTreeOfHistoricContractTreeRootsSnapshot: ${inspectTreeSnapshot(
this.startTreeOfHistoricContractTreeRootsSnapshot,
)}`,
`startPublicDataTreeRoot: ${this.startPublicDataTreeRoot.toString()}`,
`endPrivateDataTreeSnapshot: ${inspectTreeSnapshot(this.endPrivateDataTreeSnapshot)}`,
`endNullifierTreeSnapshot: ${inspectTreeSnapshot(this.endNullifierTreeSnapshot)}`,
`endContractTreeSnapshot: ${inspectTreeSnapshot(this.endContractTreeSnapshot)}`,
`endPublicDataTreeRoot: ${this.endPublicDataTreeRoot.toString()}`,
`endTreeOfHistoricPrivateDataTreeRootsSnapshot: ${inspectTreeSnapshot(
this.endTreeOfHistoricPrivateDataTreeRootsSnapshot,
)}`,
`endTreeOfHistoricContractTreeRootsSnapshot: ${inspectTreeSnapshot(
this.endTreeOfHistoricContractTreeRootsSnapshot,
)}`,
`endPublicDataTreeRoot: ${this.endPublicDataTreeRoot.toString()}`,
`newCommitments: ${inspectFrArray(this.newCommitments)}`,
`newNullifiers: ${inspectFrArray(this.newNullifiers)}`,
`newPublicDataWrite: ${inspectPublicDataWriteArray(this.newPublicDataWrites)}`,
`newContracts: ${inspectFrArray(this.newContracts)}`,
`newContractData: ${inspectContractDataArray(this.newContractData)}`,
`newPublicDataWrite: ${inspectPublicDataWriteArray(this.newPublicDataWrites)}`,
].join('\n');
}
}
2 changes: 1 addition & 1 deletion yarn-project/types/src/l2_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export class L2Tx {
constructor(
public newCommitments: Fr[],
public newNullifiers: Fr[],
public newPublicDataWrites: PublicDataWrite[],
public newContracts: Fr[],
public newContractData: ContractData[],
public newPublicDataWrites: PublicDataWrite[],
private hash?: TxHash,
) {}

Expand Down

0 comments on commit 2c82e7b

Please sign in to comment.