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

refactor: nuking old BlockHeader #4154

Merged
merged 62 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
dd33ee7
refactor: nuking block_header.nr
benesjan Jan 19, 2024
e59708b
WIP
benesjan Jan 23, 2024
e23fec9
WIP
benesjan Jan 23, 2024
0bbdeb7
fixes
benesjan Jan 23, 2024
50c5333
WIP
benesjan Jan 23, 2024
28f7f65
WIP
benesjan Jan 23, 2024
87734eb
WIP
benesjan Jan 23, 2024
f1fd093
WIP
benesjan Jan 23, 2024
c2d3243
WIP
benesjan Jan 23, 2024
42d1a44
nuking getTreeRoots function
benesjan Jan 24, 2024
55cb1ab
WIP
benesjan Jan 24, 2024
d4555bf
it compiles!
benesjan Jan 24, 2024
53e227b
block builder test fix
benesjan Jan 24, 2024
0700543
fixed abi test
benesjan Jan 24, 2024
e4c37ae
fix
benesjan Jan 24, 2024
8889d3d
fixes
benesjan Jan 24, 2024
eb9e6a7
disabling e2e dependent test
benesjan Jan 24, 2024
a7fa10d
db fix
benesjan Jan 24, 2024
8e725ae
fixed non-determinism of abis test
benesjan Jan 24, 2024
0461b84
fix
benesjan Jan 24, 2024
1f9c99d
disabling fixed value tests
benesjan Jan 25, 2024
4969f5f
fix integration l1 publisher test
benesjan Jan 25, 2024
cbb25d5
WIP
benesjan Jan 25, 2024
a381696
fix
benesjan Jan 25, 2024
b5bb32c
fixes
benesjan Jan 25, 2024
9a44485
fix
benesjan Jan 25, 2024
f98e1ee
fixes after rebase
benesjan Jan 25, 2024
5996733
fixed private execution test
benesjan Jan 25, 2024
332cbcb
updated interop test
benesjan Jan 25, 2024
6de111d
fmt
benesjan Jan 26, 2024
44c8dcd
refreshed nested-call-private-kernel-inner.hex
benesjan Jan 26, 2024
e780288
updated naming
benesjan Jan 26, 2024
af48a96
fixes after rebase
benesjan Jan 29, 2024
35d8c8c
updated snaps
benesjan Jan 29, 2024
b375a69
updated circuits snap
benesjan Jan 29, 2024
16e829d
nuked get_nullifier_root_block_number oracle
benesjan Jan 29, 2024
40a0db7
fixed docs
benesjan Jan 29, 2024
816531d
fmt
benesjan Jan 29, 2024
5e43492
fixed inclusion e2e
benesjan Jan 29, 2024
9ccac5b
e2e pxe test fix
benesjan Jan 29, 2024
4a5b4bf
linking issue
benesjan Jan 29, 2024
21b0cd6
nuked getTreeRoots from AztecNode
benesjan Jan 29, 2024
b86a8e8
replaced MerkleTree.getTreeRoots with getStateReference
benesjan Jan 29, 2024
d31f10d
buildInitialHeader func cleanup
benesjan Jan 29, 2024
40c21a2
makeHeader cleanup
benesjan Jan 29, 2024
48047e5
linking issue
benesjan Jan 29, 2024
e2637e7
linked issues + fmt
benesjan Jan 29, 2024
7ff2af2
saving one block num call
benesjan Jan 29, 2024
fce94dc
MerkleTrees cleanup
benesjan Jan 29, 2024
2e817f2
header -> historical_header in contexts
benesjan Jan 29, 2024
19bd066
final cleanup
benesjan Jan 29, 2024
4f0eb2a
updated header naming
benesjan Jan 30, 2024
eea6b83
get_header_at
benesjan Jan 30, 2024
8df308a
removing no longer necessary TODOs
benesjan Jan 30, 2024
9a72c78
updated block hash comment
benesjan Jan 30, 2024
d8e4131
comment cleanup
benesjan Jan 30, 2024
e39d8ce
fixed formatting and links
benesjan Jan 30, 2024
9ad0708
linking issue #3941
benesjan Jan 30, 2024
68cab09
AppendOnlyTreeSnapshot.zero instead of empty
benesjan Jan 30, 2024
4d31d69
using initialSyncBlockNumber
benesjan Jan 30, 2024
6342a9a
linking todo
benesjan Jan 30, 2024
e92a7a5
using read_struct on Header
benesjan Jan 30, 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
8 changes: 5 additions & 3 deletions docs/docs/developers/contracts/syntax/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ The call context contains information about the current call being made:
- is_static_call: This will be set if and only if the current call is a static call. In a static call, state changing altering operations are not allowed.
- is_contract_deployment: This will be set if and only if the current call is the contract's constructor.

### Block Header
### Header

Another structure that is contained within the context is the Block Header object. This object is a special one as it contains all of the roots of Aztec's data trees.
Another structure that is contained within the context is the Header object.
In the private context this is a header of a block which used to generate proofs against.
In the public context this TBD TODO(#4262)

#include_code block-header /yarn-project/noir-protocol-circuits/src/crates/types/src/abis/block_header.nr rust
#include_code header /yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr rust

### Contract Deployment Data

Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ library Constants {
uint256 internal constant MAX_NOTES_PER_PAGE = 10;
uint256 internal constant VIEW_NOTE_ORACLE_RETURN_LENGTH = 212;
uint256 internal constant CALL_CONTEXT_LENGTH = 8;
uint256 internal constant BLOCK_HEADER_LENGTH = 7;
uint256 internal constant HEADER_LENGTH = 18;
uint256 internal constant FUNCTION_DATA_LENGTH = 4;
uint256 internal constant CONTRACT_DEPLOYMENT_DATA_LENGTH = 6;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 189;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 200;
uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 190;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 199;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 87;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 177;
uint256 internal constant CALL_PRIVATE_FUNCTION_RETURN_SIZE = 210;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 98;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH = 188;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Destroys the backend
generateFinalProof(decompressedWitness): Promise<ProofData>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this file were made by bootstrap after rebase.

```

Generate a final proof. This is the proof for the circuit which will verify
benesjan marked this conversation as resolved.
Show resolved Hide resolved
intermediate proofs and or can be seen as the proof created for regular circuits.

#### Parameters

| Parameter | Type |
Expand All @@ -65,10 +68,6 @@ generateFinalProof(decompressedWitness): Promise<ProofData>

[`Backend`](../interfaces/Backend.md).[`generateFinalProof`](../interfaces/Backend.md#generatefinalproof)

#### Description

Generates a final proof (not meant to be verified in another circuit)

***

### generateIntermediateProof()
Expand All @@ -77,6 +76,14 @@ Generates a final proof (not meant to be verified in another circuit)
generateIntermediateProof(witness): Promise<ProofData>
```

Generates an intermediate proof. This is the proof that can be verified
in another circuit.

This is sometimes referred to as a recursive proof.
We avoid this terminology as the only property of this proof
that matters is the fact that it is easy to verify in another circuit.
We _could_ choose to verify this proof outside of a circuit just as easily.

#### Parameters

| Parameter | Type |
Expand Down Expand Up @@ -105,6 +112,16 @@ const intermediateProof = await backend.generateIntermediateProof(witness);
generateIntermediateProofArtifacts(proofData, numOfPublicInputs): Promise<object>
```

Generates artifacts that will be passed to a circuit that will verify this proof.

Instead of passing the proof and verification key as a byte array, we pass them
as fields which makes it cheaper to verify in a circuit.

The proof that is passed here will have been created using the `generateIntermediateProof`
method.

The number of public inputs denotes how many public inputs are in the inner proof.

#### Parameters

| Parameter | Type | Default value |
Expand Down
30 changes: 7 additions & 23 deletions yarn-project/acir-simulator/src/acvm/deserialize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
BlockHeader,
CallContext,
ContractDeploymentData,
ContractStorageRead,
ContractStorageUpdateRequest,
HEADER_LENGTH,
Header,
MAX_NEW_COMMITMENTS_PER_CALL,
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
MAX_NEW_NULLIFIERS_PER_CALL,
Expand Down Expand Up @@ -100,16 +101,7 @@ export function extractPrivateCircuitPublicInputs(
const encryptedLogPreimagesLength = witnessReader.readField();
const unencryptedLogPreimagesLength = witnessReader.readField();

const blockHeader = new BlockHeader(
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
Fr.ZERO, // TODO(#3441)
witnessReader.readField(),
witnessReader.readField(),
);
const header = Header.fromFieldArray(witnessReader.readFieldArray(HEADER_LENGTH));

const contractDeploymentData = new ContractDeploymentData(
new Point(witnessReader.readField(), witnessReader.readField()),
Expand Down Expand Up @@ -138,7 +130,7 @@ export function extractPrivateCircuitPublicInputs(
unencryptedLogsHash,
encryptedLogPreimagesLength,
unencryptedLogPreimagesLength,
blockHeader,
header,
contractDeploymentData,
chainId,
version,
Expand Down Expand Up @@ -184,16 +176,8 @@ export function extractPublicCircuitPublicInputs(partialWitness: ACVMWitness, ac
const unencryptedLogsHash = witnessReader.readFieldArray(NUM_FIELDS_PER_SHA256);
const unencryptedLogPreimagesLength = witnessReader.readField();

const blockHeader = new BlockHeader(
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
witnessReader.readField(),
Fr.ZERO, // TODO(#3441)
witnessReader.readField(),
witnessReader.readField(),
);
const header = Header.fromFieldArray(witnessReader.readFieldArray(HEADER_LENGTH));

const proverAddress = AztecAddress.fromField(witnessReader.readField());

return new PublicCircuitPublicInputs(
Expand All @@ -211,7 +195,7 @@ export function extractPublicCircuitPublicInputs(partialWitness: ACVMWitness, ac
newL2ToL1Msgs,
unencryptedLogsHash,
unencryptedLogPreimagesLength,
blockHeader,
header,
proverAddress,
);
}
20 changes: 5 additions & 15 deletions yarn-project/acir-simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ACVMField } from '../acvm_types.js';
import { frToNumber, fromACVMField } from '../deserialize.js';
import {
toACVMField,
toACVMHeader,
toAcvmCallPrivateStackItem,
toAcvmEnqueuePublicFunctionResult,
toAcvmL1ToL2MessageLoadOracleInputs,
Expand Down Expand Up @@ -124,25 +125,14 @@ export class Oracle {
return witness.toFieldArray().map(toACVMField);
}

async getBlockHeader([blockNumber]: ACVMField[]): Promise<ACVMField[]> {
async getHeader([blockNumber]: ACVMField[]): Promise<ACVMField[]> {
const parsedBlockNumber = frToNumber(fromACVMField(blockNumber));

const blockHeader = await this.typedOracle.getBlockHeader(parsedBlockNumber);
if (!blockHeader) {
const header = await this.typedOracle.getHeader(parsedBlockNumber);
if (!header) {
throw new Error(`Block header not found for block ${parsedBlockNumber}.`);
}
return blockHeader.toArray().map(toACVMField);
}

// TODO(#3564) - Nuke this oracle and inject the number directly to context
async getNullifierRootBlockNumber([nullifierTreeRoot]: ACVMField[]): Promise<ACVMField> {
const parsedRoot = fromACVMField(nullifierTreeRoot);

const blockNumber = await this.typedOracle.getNullifierRootBlockNumber(parsedRoot);
if (!blockNumber) {
throw new Error(`Block header not found for block ${parsedRoot}.`);
}
return toACVMField(blockNumber);
return toACVMHeader(header);
}

async getAuthWitness([messageHash]: ACVMField[]): Promise<ACVMField[]> {
Expand Down
9 changes: 2 additions & 7 deletions yarn-project/acir-simulator/src/acvm/oracle/typed_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PublicKey,
UnencryptedL2Log,
} from '@aztec/circuit-types';
import { BlockHeader, GrumpkinPrivateKey, PrivateCallStackItem, PublicCallRequest } from '@aztec/circuits.js';
import { GrumpkinPrivateKey, Header, PrivateCallStackItem, PublicCallRequest } from '@aztec/circuits.js';
import { FunctionSelector } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
Expand Down Expand Up @@ -111,12 +111,7 @@ export abstract class TypedOracle {
throw new Error('Not available.');
}

getBlockHeader(_blockNumber: number): Promise<BlockHeader | undefined> {
throw new Error('Not available.');
}

// TODO(#3564) - Nuke this oracle and inject the number directly to context
getNullifierRootBlockNumber(_nullifierTreeRoot: Fr): Promise<number | undefined> {
getHeader(_blockNumber: number): Promise<Header | undefined> {
throw new Error('Not available.');
}

Expand Down
18 changes: 5 additions & 13 deletions yarn-project/acir-simulator/src/acvm/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
BlockHeader,
CallContext,
ContractDeploymentData,
FunctionData,
GlobalVariables,
Header,
PrivateCallStackItem,
PrivateCircuitPublicInputs,
PublicCallRequest,
Expand Down Expand Up @@ -103,19 +103,11 @@ export function toACVMContractDeploymentData(contractDeploymentData: ContractDep

/**
* Converts a block header into ACVM fields.
* @param blockHeader - The block header object to convert.
* @param header - The block header object to convert.
* @returns The ACVM fields.
*/
export function toACVMBlockHeader(blockHeader: BlockHeader): ACVMField[] {
return [
toACVMField(blockHeader.noteHashTreeRoot),
toACVMField(blockHeader.nullifierTreeRoot),
toACVMField(blockHeader.contractTreeRoot),
toACVMField(blockHeader.l1ToL2MessageTreeRoot),
toACVMField(blockHeader.archiveRoot),
toACVMField(blockHeader.publicDataTreeRoot),
toACVMField(blockHeader.globalVariablesHash),
];
export function toACVMHeader(header: Header): ACVMField[] {
return header.toFieldArray().map(toACVMField);
}

/**
Expand Down Expand Up @@ -157,7 +149,7 @@ export function toACVMPublicInputs(publicInputs: PrivateCircuitPublicInputs): AC
toACVMField(publicInputs.encryptedLogPreimagesLength),
toACVMField(publicInputs.unencryptedLogPreimagesLength),

...toACVMBlockHeader(publicInputs.blockHeader),
...toACVMHeader(publicInputs.historicalHeader),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall, at some point you would like to have publicInputs.historicalHeader.toACVM()? It this still something you think could be good to have. I think the use of toFieldArray() is quite nice here, but not sure if that is the target to use that structure generally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had a plan to do it in this issue (might split it to a separate issue now that I think about it).

In general it seems to be a good idea to have all the serialization in the classes themselves so I would probably implement a FieldReader in foundation/serialize (akin to BufferReader) and use that in these types which are passed in the witness.


...toACVMContractDeploymentData(publicInputs.contractDeploymentData),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AuthWitness, FunctionL2Logs, L1NotePayload, Note, UnencryptedL2Log } from '@aztec/circuit-types';
import {
BlockHeader,
CallContext,
ContractDeploymentData,
FunctionData,
FunctionSelector,
Header,
PublicCallRequest,
ReadRequestMembershipWitness,
SideEffect,
Expand All @@ -19,9 +19,9 @@ import { createDebugLogger } from '@aztec/foundation/log';

import {
NoteData,
toACVMBlockHeader,
toACVMCallContext,
toACVMContractDeploymentData,
toACVMHeader,
toACVMWitness,
} from '../acvm/index.js';
import { PackedArgsCache } from '../common/packed_args_cache.js';
Expand Down Expand Up @@ -64,8 +64,8 @@ export class ClientExecutionContext extends ViewDataOracle {
private readonly argsHash: Fr,
private readonly txContext: TxContext,
private readonly callContext: CallContext,
/** Data required to reconstruct the block hash, it contains historical roots. */
protected readonly blockHeader: BlockHeader,
/** Header of a block whose state is used during private execution. */
protected readonly historicalHeader: Header,
/** List of transient auth witnesses to be used during this simulation */
protected readonly authWitnesses: AuthWitness[],
private readonly packedArgsCache: PackedArgsCache,
Expand All @@ -74,7 +74,7 @@ export class ClientExecutionContext extends ViewDataOracle {
private readonly curve: Grumpkin,
protected log = createDebugLogger('aztec:simulator:client_execution_context'),
) {
super(contractAddress, blockHeader, authWitnesses, db, undefined, log);
super(contractAddress, historicalHeader, authWitnesses, db, undefined, log);
}

// We still need this function until we can get user-defined ordering of structs for fn arguments
Expand All @@ -97,7 +97,7 @@ export class ClientExecutionContext extends ViewDataOracle {

const fields = [
...toACVMCallContext(this.callContext),
...toACVMBlockHeader(this.blockHeader),
...toACVMHeader(this.historicalHeader),
...toACVMContractDeploymentData(contractDeploymentData),

this.txContext.chainId,
Expand Down Expand Up @@ -341,7 +341,7 @@ export class ClientExecutionContext extends ViewDataOracle {
argsHash,
derivedTxContext,
derivedCallContext,
this.blockHeader,
this.historicalHeader,
this.authWitnesses,
this.packedArgsCache,
this.noteCache,
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/acir-simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { L2Block, MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/circuit-types';
import { BlockHeader, CompleteAddress } from '@aztec/circuits.js';
import { CompleteAddress, Header } from '@aztec/circuits.js';
import { FunctionArtifactWithDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
Expand Down Expand Up @@ -111,9 +111,9 @@ export interface DBOracle extends CommitmentsDB {
* Retrieve the databases view of the Block Header object.
* This structure is fed into the circuits simulator and is used to prove against certain historical roots.
*
* @returns A Promise that resolves to a BlockHeader object.
* @returns A Promise that resolves to a Header object.
*/
getBlockHeader(): Promise<BlockHeader>;
getHeader(): Promise<Header>;

/**
* Fetch the index of the leaf in the respective tree
Expand Down
Loading
Loading