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: PartialStateReference and StateReference structs #3827

Merged
merged 39 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
09755c8
WIP
benesjan Jan 4, 2024
d3a3f76
WIP
benesjan Jan 4, 2024
8b7cb66
updated naming
benesjan Jan 4, 2024
f1e6259
WIP
benesjan Jan 5, 2024
4dcae2f
WIP
benesjan Jan 5, 2024
0894ce8
WIP
benesjan Jan 5, 2024
826e934
WIP
benesjan Jan 5, 2024
8f4f5ba
WIP
benesjan Jan 5, 2024
6267f07
WIP
benesjan Jan 5, 2024
4c16822
WIP
benesjan Jan 8, 2024
070340e
WIP
benesjan Jan 8, 2024
21cbe16
WIP
benesjan Jan 8, 2024
edba919
WIP
benesjan Jan 8, 2024
065c3a3
fixing cycles
benesjan Jan 8, 2024
848952a
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 8, 2024
39eac0d
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 9, 2024
39d16be
import fix
benesjan Jan 9, 2024
62d7681
test workaround
benesjan Jan 9, 2024
b8e1dd2
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 9, 2024
5c0ea28
temporarily disabling old state check
benesjan Jan 9, 2024
3f060e3
formatting
benesjan Jan 9, 2024
9444f62
stale comment fix
benesjan Jan 9, 2024
b11cc3f
comment
benesjan Jan 9, 2024
426ff44
fix
benesjan Jan 10, 2024
eaefe52
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 10, 2024
d5cf965
note processor test fix
benesjan Jan 10, 2024
6415649
stale naming fix
benesjan Jan 10, 2024
98b815c
Update yarn-project/accounts/src/testing/create_account.ts
benesjan Jan 11, 2024
1052827
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 11, 2024
0081f16
linking issues
benesjan Jan 11, 2024
f0b9f2a
merge fix
benesjan Jan 11, 2024
73b4b69
linking block hash issue
benesjan Jan 11, 2024
c08e06a
more standard deserialization of sha256 hash
benesjan Jan 11, 2024
5e3ea0e
Merge branch 'master' into janb/introducing-state-reference
benesjan Jan 11, 2024
7dfa3d9
auto-updated noir docs
benesjan Jan 11, 2024
739e933
temporarily disabling the new start state check
benesjan Jan 11, 2024
13977e8
cleanup
benesjan Jan 11, 2024
6bed131
cleaned up mocks
benesjan Jan 11, 2024
56c95b1
disabling old state check test
benesjan Jan 11, 2024
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
7 changes: 4 additions & 3 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ contract Rollup is IRollup {
_computePublicInputHash(_l2Block[:HeaderDecoder.BLOCK_HEADER_SIZE], txsHash, inHash);

// @todo @LHerskind Proper genesis state. If the state is empty, we allow anything for now.
if (rollupStateHash != bytes32(0) && rollupStateHash != oldStateHash) {
revert Errors.Rollup__InvalidStateHash(rollupStateHash, oldStateHash);
}
// TODO(#3936): Temporarily disabling this because L2Block encoding has not yet been updated.
// if (rollupStateHash != bytes32(0) && rollupStateHash != oldStateHash) {
// revert Errors.Rollup__InvalidStateHash(rollupStateHash, oldStateHash);
// }

bytes32[] memory publicInputs = new bytes32[](1);
publicInputs[0] = publicInputHash;
Expand Down
9 changes: 5 additions & 4 deletions noir/docs/docs/reference/NoirJS/backend_barretenberg/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@

## Functions

### flattenPublicInputs()
### publicInputsToWitnessMap()

```ts
flattenPublicInputs(publicInputs): string[]
publicInputsToWitnessMap(publicInputs, abi): WitnessMap
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `publicInputs` | `WitnessMap` |
| `publicInputs` | `string`[] |
| `abi` | `Abi` |

#### Returns

`string`[]
`WitnessMap`

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The representation of a proof
| Member | Type | Description |
| :------ | :------ | :------ |
| `proof` | `Uint8Array` | **Description**<br /><br />An byte array representing the proof |
| `publicInputs` | `WitnessMap` | **Description**<br /><br />Public inputs of a proof |
| `publicInputs` | `string`[] | **Description**<br /><br />Public inputs of a proof |

***

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The representation of a proof
| Member | Type | Description |
| :------ | :------ | :------ |
| `proof` | `Uint8Array` | **Description**<br /><br />An byte array representing the proof |
| `publicInputs` | `WitnessMap` | **Description**<br /><br />Public inputs of a proof |
| `publicInputs` | `string`[] | **Description**<br /><br />Public inputs of a proof |

***

Expand Down
3 changes: 3 additions & 0 deletions yarn-project/accounts/src/testing/create_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export async function createAccounts(pxe: PXE, numberOfAccounts = 1): Promise<Ac
// Prepare deployments
for (let i = 0; i < numberOfAccounts; ++i) {
const account = getSchnorrAccount(pxe, GrumpkinScalar.random(), GrumpkinScalar.random());
// Unfortunately the function below is not stateless and we call it here because it takes a long time to run and
// the results get stored within the account object. By calling it here we increase the probability of all the
// accounts being deployed in the same block because it makes the deploy() method basically instant.
await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt }));
accounts.push(account);
}
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/acir-simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export class ViewDataOracle extends TypedOracle {
return undefined;
}
return new BlockHeader(
block.endNoteHashTreeSnapshot.root,
block.endNullifierTreeSnapshot.root,
block.endContractTreeSnapshot.root,
block.endL1ToL2MessageTreeSnapshot.root,
block.endArchiveSnapshot.root,
block.header.state.partial.noteHashTree.root,
block.header.state.partial.nullifierTree.root,
block.header.state.partial.contractTree.root,
block.header.state.l1ToL2MessageTree.root,
block.archive.root,
new Fr(0), // TODO(#3441) privateKernelVkTreeRoot is not present in L2Block and it's not yet populated in noir
block.endPublicDataTreeSnapshot.root,
computeGlobalsHash(block.globalVariables),
block.header.state.partial.publicDataTree.root,
computeGlobalsHash(block.header.globalVariables),
);
}

Expand All @@ -145,10 +145,10 @@ export class ViewDataOracle extends TypedOracle {
if (!block) {
throw new Error(`Block ${i} not found`);
}
if (block.endNullifierTreeSnapshot.root.equals(nullifierTreeRoot)) {
if (block.header.state.partial.nullifierTree.root.equals(nullifierTreeRoot)) {
return i;
}
if (block.startNullifierTreeSnapshot.root.equals(nullifierTreeRoot)) {
if (block.header.state.partial.nullifierTree.root.equals(nullifierTreeRoot)) {
return i - 1;
}
}
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ export class AztecNodeService implements AztecNode {
* Returns the currently committed block header.
* @returns The current committed block header.
*/
// TODO(#3937): Nuke this
public async getBlockHeader(): Promise<BlockHeader> {
const committedDb = await this.#getWorldState('latest');
const [roots, globalsHash] = await Promise.all([this.getTreeRoots(), committedDb.getLatestGlobalVariablesHash()]);
Expand All @@ -585,7 +586,8 @@ export class AztecNodeService implements AztecNode {
this.log.info(`Simulating tx ${await tx.getTxHash()}`);
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(new Fr(blockNumber));
const prevGlobalVariables = (await this.blockSource.getBlock(-1))?.globalVariables ?? GlobalVariables.empty();
const prevGlobalVariables =
(await this.blockSource.getBlock(-1))?.header.globalVariables ?? GlobalVariables.empty();

// Instantiate merkle trees so uncommitted updates by this simulation are local to it.
// TODO we should be able to remove this after https://github.com/AztecProtocol/aztec-packages/issues/1869
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Fr {
* @param publicDataTreeRoot - The root of the public data tree.
* @returns The block hash.
*/
// TODO(#3941)
export function computeBlockHashWithGlobals(
globals: GlobalVariables,
noteHashTreeRoot: Fr,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/global_variables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { FieldsOf } from '../index.js';
import { serializeToBuffer } from '../utils/index.js';

/**
Expand Down
36 changes: 36 additions & 0 deletions yarn-project/circuits.js/src/structs/header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';

import { NUM_FIELDS_PER_SHA256 } from '../constants.gen.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { GlobalVariables } from './global_variables.js';
import { AppendOnlyTreeSnapshot } from './rollup/append_only_tree_snapshot.js';
import { StateReference } from './state_reference.js';

/** A header of an L2 block. */
export class Header {
constructor(
/** Snapshot of archive before the block is applied. */
public lastArchive: AppendOnlyTreeSnapshot,
/** Hash of the body of an L2 block. */
public bodyHash: [Fr, Fr],
/** State reference. */
public state: StateReference,
/** Global variables of an L2 block. */
public globalVariables: GlobalVariables,
) {}

toBuffer() {
return serializeToBuffer(this.lastArchive, this.bodyHash, this.state, this.globalVariables);
}

static fromBuffer(buffer: Buffer | BufferReader): Header {
const reader = BufferReader.asReader(buffer);
return new Header(
reader.readObject(AppendOnlyTreeSnapshot),
reader.readArray(NUM_FIELDS_PER_SHA256, Fr) as [Fr, Fr],
reader.readObject(StateReference),
reader.readObject(GlobalVariables),
);
}
}
3 changes: 3 additions & 0 deletions yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './complete_address.js';
export * from './function_data.js';
export * from './function_leaf_preimage.js';
export * from './global_variables.js';
export * from './header.js';
export * from './kernel/combined_accumulated_data.js';
export * from './kernel/combined_constant_data.js';
export * from './kernel/block_header.js';
Expand All @@ -32,6 +33,8 @@ export * from './side_effects.js';
export * from './tx_context.js';
export * from './tx_request.js';
export * from './verification_key.js';
export * from './state_reference.js';
export * from './partial_state_reference.js';

export { FunctionSelector } from '@aztec/foundation/abi';
export * from '@aztec/foundation/aztec-address';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const STRING_ENCODING: BufferEncoding = 'hex';
/**
* Information about the tree roots used for both public and private kernels.
*/
// TODO(#3937): Nuke this
export class BlockHeader {
constructor(
/**
Expand Down
34 changes: 34 additions & 0 deletions yarn-project/circuits.js/src/structs/partial_state_reference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BufferReader } from '@aztec/foundation/serialize';

import { serializeToBuffer } from '../utils/serialize.js';
import { AppendOnlyTreeSnapshot } from './rollup/append_only_tree_snapshot.js';

/**
* Stores snapshots of trees which are commonly needed by base or merge rollup circuits.
*/
export class PartialStateReference {
constructor(
/** Snapshot of the note hash tree. */
public readonly noteHashTree: AppendOnlyTreeSnapshot,
/** Snapshot of the nullifier tree. */
public readonly nullifierTree: AppendOnlyTreeSnapshot,
/** Snapshot of the contract tree. */
public readonly contractTree: AppendOnlyTreeSnapshot,
/** Snapshot of the public data tree. */
public readonly publicDataTree: AppendOnlyTreeSnapshot,
) {}

static fromBuffer(buffer: Buffer | BufferReader): PartialStateReference {
const reader = BufferReader.asReader(buffer);
return new PartialStateReference(
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
);
}

toBuffer() {
return serializeToBuffer(this.noteHashTree, this.nullifierTree, this.contractTree, this.publicDataTree);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BufferReader } from '@aztec/foundation/serialize';
import { NUM_FIELDS_PER_SHA256 } from '../../constants.gen.js';
import { serializeToBuffer } from '../../utils/serialize.js';
import { AggregationObject } from '../aggregation_object.js';
import { PartialStateReference } from '../partial_state_reference.js';
import { RollupTypes } from '../shared.js';
import { AppendOnlyTreeSnapshot } from './append_only_tree_snapshot.js';
import { ConstantRollupData } from './base_rollup.js';

/**
Expand All @@ -26,48 +26,19 @@ export class BaseOrMergeRollupPublicInputs {
/**
* Native aggregation state at the end of the rollup circuit.
*/
public endAggregationObject: AggregationObject,
public aggregationObject: AggregationObject,
/**
* Data which is forwarded through the rollup circuits unchanged.
*/
public constants: ConstantRollupData,

/**
* Snapshot of the note hash tree at the start of the rollup circuit.
*/
public startNoteHashTreeSnapshot: AppendOnlyTreeSnapshot,
/**
* Snapshot of the note hash tree at the end of the rollup circuit.
*/
public endNoteHashTreeSnapshot: AppendOnlyTreeSnapshot,

/**
* Snapshot of the nullifier tree at the start of the rollup circuit.
*/
public startNullifierTreeSnapshot: AppendOnlyTreeSnapshot,
/**
* Snapshot of the nullifier tree at the end of the rollup circuit.
*/
public endNullifierTreeSnapshot: AppendOnlyTreeSnapshot,

/**
* Snapshot of the contract tree at the start of the rollup circuit.
*/
public startContractTreeSnapshot: AppendOnlyTreeSnapshot,
/**
* Snapshot of the contract tree at the end of the rollup circuit.
*/
public endContractTreeSnapshot: AppendOnlyTreeSnapshot,

/**
* Snapshot of the public data tree at the start of the rollup circuit.
* Partial state reference at the start of the rollup circuit.
*/
public startPublicDataTreeSnapshot: AppendOnlyTreeSnapshot,
public start: PartialStateReference,
/**
* Snapshot of the public data tree at the end of the rollup circuit.
* Partial state reference at the end of the rollup circuit.
*/
public endPublicDataTreeSnapshot: AppendOnlyTreeSnapshot,

public end: PartialStateReference,
/**
* SHA256 hashes of calldata. Used to make public inputs constant-sized (to then be unpacked on-chain).
* Note: Length 2 for high and low.
Expand All @@ -88,14 +59,8 @@ export class BaseOrMergeRollupPublicInputs {
Fr.fromBuffer(reader),
reader.readObject(AggregationObject),
reader.readObject(ConstantRollupData),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(AppendOnlyTreeSnapshot),
reader.readObject(PartialStateReference),
reader.readObject(PartialStateReference),
reader.readArray(NUM_FIELDS_PER_SHA256, Fr) as [Fr, Fr],
benesjan marked this conversation as resolved.
Show resolved Hide resolved
);
}
Expand All @@ -108,20 +73,11 @@ export class BaseOrMergeRollupPublicInputs {
return serializeToBuffer(
this.rollupType,
this.rollupSubtreeHeight,
this.endAggregationObject,
this.aggregationObject,
this.constants,

this.startNoteHashTreeSnapshot,
this.endNoteHashTreeSnapshot,

this.startNullifierTreeSnapshot,
this.endNullifierTreeSnapshot,

this.startContractTreeSnapshot,
this.endContractTreeSnapshot,

this.startPublicDataTreeSnapshot,
this.endPublicDataTreeSnapshot,
this.start,
this.end,

this.calldataHash,
);
Expand Down
Loading