@aztec/prover-client 3.0.0-devnet.5 → 3.0.0-devnet.6-patch.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/block-factory/index.d.ts +1 -1
- package/dest/block-factory/light.d.ts +8 -8
- package/dest/block-factory/light.d.ts.map +1 -1
- package/dest/block-factory/light.js +37 -23
- package/dest/config.d.ts +1 -1
- package/dest/config.js +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/light/lightweight_checkpoint_builder.d.ts +29 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +108 -0
- package/dest/mocks/fixtures.d.ts +1 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +7 -17
- package/dest/mocks/test_context.d.ts +27 -46
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +102 -116
- package/dest/orchestrator/block-building-helpers.d.ts +19 -21
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +93 -118
- package/dest/orchestrator/block-proving-state.d.ts +17 -11
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +81 -20
- package/dest/orchestrator/checkpoint-proving-state.d.ts +8 -8
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +15 -16
- package/dest/orchestrator/epoch-proving-state.d.ts +10 -9
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +6 -6
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +13 -13
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +54 -60
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.d.ts +6 -6
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +14 -23
- package/dest/prover-client/factory.d.ts +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.d.ts +9 -8
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +4 -4
- package/dest/proving_broker/broker_prover_facade.d.ts +21 -21
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +7 -6
- package/dest/proving_broker/config.d.ts +12 -8
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +8 -2
- package/dest/proving_broker/factory.d.ts +1 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.d.ts +2 -2
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +4 -3
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.d.ts +3 -2
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +3 -3
- package/dest/proving_broker/rpc.d.ts +4 -4
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +5 -6
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +3 -3
- package/package.json +18 -17
- package/src/block-factory/light.ts +40 -43
- package/src/config.ts +1 -1
- package/src/light/lightweight_checkpoint_builder.ts +144 -0
- package/src/mocks/fixtures.ts +7 -30
- package/src/mocks/test_context.ts +145 -177
- package/src/orchestrator/block-building-helpers.ts +133 -215
- package/src/orchestrator/block-proving-state.ts +103 -25
- package/src/orchestrator/checkpoint-proving-state.ts +24 -20
- package/src/orchestrator/epoch-proving-state.ts +15 -11
- package/src/orchestrator/orchestrator.ts +76 -74
- package/src/orchestrator/tx-proving-state.ts +24 -33
- package/src/prover-client/server-epoch-prover.ts +8 -9
- package/src/proving_broker/broker_prover_facade.ts +32 -29
- package/src/proving_broker/config.ts +8 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proving_broker.ts +4 -3
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +5 -4
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +5 -4
- package/src/test/mock_prover.ts +9 -7
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { SpongeBlob } from '@aztec/blob-lib';
|
|
1
|
+
import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
2
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
3
3
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { L2Block } from '@aztec/stdlib/block';
|
|
6
|
+
import { L2Block, L2BlockHeader } from '@aztec/stdlib/block';
|
|
7
7
|
import type { IBlockFactory, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
8
|
+
import { computeBlockOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
8
9
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
import type
|
|
10
|
+
import { ContentCommitment, type GlobalVariables, type ProcessedTx } from '@aztec/stdlib/tx';
|
|
10
11
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
11
12
|
|
|
12
13
|
import {
|
|
13
14
|
buildHeaderAndBodyFromTxs,
|
|
14
15
|
getTreeSnapshot,
|
|
15
|
-
|
|
16
|
+
insertSideEffects,
|
|
16
17
|
} from '../orchestrator/block-building-helpers.js';
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -25,12 +26,13 @@ import {
|
|
|
25
26
|
* PublicProcessor which will do this for you as it processes transactions.
|
|
26
27
|
*
|
|
27
28
|
* If you haven't already inserted the side effects, e.g. because you are in a testing context, you can use the helper
|
|
28
|
-
* function `buildBlockWithCleanDB`, which calls `
|
|
29
|
+
* function `buildBlockWithCleanDB`, which calls `insertSideEffects` for you.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Use LightweightCheckpointBuilder instead. This only works for one block per checkpoint.
|
|
29
32
|
*/
|
|
30
33
|
export class LightweightBlockFactory implements IBlockFactory {
|
|
31
34
|
private globalVariables?: GlobalVariables;
|
|
32
35
|
private l1ToL2Messages?: Fr[];
|
|
33
|
-
private startSpongeBlob?: SpongeBlob;
|
|
34
36
|
private txs: ProcessedTx[] | undefined;
|
|
35
37
|
|
|
36
38
|
private readonly logger = createLogger('lightweight-block-factory');
|
|
@@ -40,20 +42,10 @@ export class LightweightBlockFactory implements IBlockFactory {
|
|
|
40
42
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
41
43
|
) {}
|
|
42
44
|
|
|
43
|
-
async startNewBlock(
|
|
44
|
-
globalVariables: GlobalVariables,
|
|
45
|
-
l1ToL2Messages: Fr[],
|
|
46
|
-
// Must be provided to generate the correct spongeBlobHash for the block header if there's more than one block in the checkpoint.
|
|
47
|
-
startSpongeBlob?: SpongeBlob,
|
|
48
|
-
// Only insert l1 to l2 messages for the first block in a checkpoint.
|
|
49
|
-
isFirstBlock = true,
|
|
50
|
-
): Promise<void> {
|
|
45
|
+
async startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise<void> {
|
|
51
46
|
this.logger.debug('Starting new block', { globalVariables: globalVariables.toInspect(), l1ToL2Messages });
|
|
52
47
|
this.globalVariables = globalVariables;
|
|
53
|
-
this.l1ToL2Messages =
|
|
54
|
-
? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
|
|
55
|
-
: [];
|
|
56
|
-
this.startSpongeBlob = startSpongeBlob;
|
|
48
|
+
this.l1ToL2Messages = padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
57
49
|
this.txs = undefined;
|
|
58
50
|
// Update L1 to L2 tree
|
|
59
51
|
await this.db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, this.l1ToL2Messages!);
|
|
@@ -75,21 +67,40 @@ export class LightweightBlockFactory implements IBlockFactory {
|
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
private async buildBlock(): Promise<L2Block> {
|
|
78
|
-
const
|
|
79
|
-
|
|
70
|
+
const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
71
|
+
const state = await this.db.getStateReference();
|
|
72
|
+
|
|
73
|
+
const txs = this.txs ?? [];
|
|
74
|
+
const startSpongeBlob = SpongeBlob.init();
|
|
75
|
+
|
|
76
|
+
const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
|
|
77
|
+
txs,
|
|
78
|
+
lastArchive,
|
|
79
|
+
state,
|
|
80
80
|
this.globalVariables!,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.startSpongeBlob,
|
|
81
|
+
startSpongeBlob,
|
|
82
|
+
true,
|
|
84
83
|
);
|
|
85
84
|
|
|
86
85
|
header.state.validate();
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
await this.db.updateArchive(blockHeader);
|
|
87
|
+
await this.db.updateArchive(header);
|
|
90
88
|
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
91
89
|
|
|
92
|
-
const
|
|
90
|
+
const outHash = computeBlockOutHash(txs.map(tx => tx.txEffect.l2ToL1Msgs));
|
|
91
|
+
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages!);
|
|
92
|
+
const numBlobFields = blockBlobFields.length + 1;
|
|
93
|
+
const blobFields = blockBlobFields.concat([encodeCheckpointEndMarker({ numBlobFields })]);
|
|
94
|
+
const blobsHash = computeBlobsHashFromBlobs(getBlobsPerL1Block(blobFields));
|
|
95
|
+
const blockHeaderHash = await header.hash();
|
|
96
|
+
const contentCommitment = new ContentCommitment(blobsHash, inHash, outHash);
|
|
97
|
+
const l2BlockHeader = L2BlockHeader.from({
|
|
98
|
+
...header,
|
|
99
|
+
blockHeadersHash: blockHeaderHash,
|
|
100
|
+
contentCommitment,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const block = new L2Block(newArchive, l2BlockHeader, body);
|
|
93
104
|
|
|
94
105
|
this.logger.debug(`Built block ${block.number}`, {
|
|
95
106
|
globalVariables: this.globalVariables?.toInspect(),
|
|
@@ -112,27 +123,13 @@ export async function buildBlockWithCleanDB(
|
|
|
112
123
|
globalVariables: GlobalVariables,
|
|
113
124
|
l1ToL2Messages: Fr[],
|
|
114
125
|
db: MerkleTreeWriteOperations,
|
|
115
|
-
startSpongeBlob?: SpongeBlob,
|
|
116
|
-
isFirstBlock = true,
|
|
117
126
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
118
127
|
) {
|
|
119
|
-
const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
120
128
|
const builder = new LightweightBlockFactory(db, telemetry);
|
|
121
|
-
await builder.startNewBlock(globalVariables, l1ToL2Messages
|
|
122
|
-
const l1ToL2MessageTree = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
129
|
+
await builder.startNewBlock(globalVariables, l1ToL2Messages);
|
|
123
130
|
|
|
124
131
|
for (const tx of txs) {
|
|
125
|
-
|
|
126
|
-
// Their values don't matter here because we are not using the return private inputs to build the block.
|
|
127
|
-
const proverId = Fr.ZERO;
|
|
128
|
-
await insertSideEffectsAndBuildBaseRollupHints(
|
|
129
|
-
tx,
|
|
130
|
-
lastArchive,
|
|
131
|
-
l1ToL2MessageTree,
|
|
132
|
-
startSpongeBlob?.clone() ?? SpongeBlob.empty(),
|
|
133
|
-
proverId,
|
|
134
|
-
db,
|
|
135
|
-
);
|
|
132
|
+
await insertSideEffects(tx, db);
|
|
136
133
|
}
|
|
137
134
|
await builder.addTxs(txs);
|
|
138
135
|
|
package/src/config.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const bbConfigMappings: ConfigMappingsType<BBConfig & ACVMConfig> = {
|
|
|
44
44
|
},
|
|
45
45
|
numConcurrentIVCVerifiers: {
|
|
46
46
|
env: 'BB_NUM_IVC_VERIFIERS',
|
|
47
|
-
description: 'Max number of
|
|
47
|
+
description: 'Max number of chonk verifiers to run concurrently',
|
|
48
48
|
...numberConfigHelper(8),
|
|
49
49
|
},
|
|
50
50
|
bbIVCConcurrency: {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
3
|
+
import type { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
8
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
9
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import { computeCheckpointOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
11
|
+
import { CheckpointConstantData, CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
|
|
12
|
+
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
+
import { ContentCommitment, type GlobalVariables, type ProcessedTx, StateReference } from '@aztec/stdlib/tx';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
buildHeaderAndBodyFromTxs,
|
|
17
|
+
getTreeSnapshot,
|
|
18
|
+
insertSideEffects,
|
|
19
|
+
} from '../orchestrator/block-building-helpers.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Builds a checkpoint and its header and the blocks in it from a set of processed tx without running any circuits.
|
|
23
|
+
*
|
|
24
|
+
* It updates the l1-to-l2 message tree when starting a new checkpoint, inserts the side effects to note hash,
|
|
25
|
+
* nullifier, and public data trees, then updates the archive tree when a block is added.
|
|
26
|
+
*/
|
|
27
|
+
export class LightweightCheckpointBuilder {
|
|
28
|
+
private readonly logger = createLogger('lightweight-checkpoint-builder');
|
|
29
|
+
private lastArchives: AppendOnlyTreeSnapshot[] = [];
|
|
30
|
+
private spongeBlob: SpongeBlob;
|
|
31
|
+
private blocks: L2BlockNew[] = [];
|
|
32
|
+
private blobFields: Fr[] = [];
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
private checkpointNumber: CheckpointNumber,
|
|
36
|
+
private constants: CheckpointConstantData,
|
|
37
|
+
private l1ToL2Messages: Fr[],
|
|
38
|
+
private db: MerkleTreeWriteOperations,
|
|
39
|
+
) {
|
|
40
|
+
this.spongeBlob = SpongeBlob.init();
|
|
41
|
+
this.logger.debug('Starting new checkpoint', { constants: constants.toInspect(), l1ToL2Messages });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static async startNewCheckpoint(
|
|
45
|
+
checkpointNumber: CheckpointNumber,
|
|
46
|
+
constants: CheckpointConstantData,
|
|
47
|
+
l1ToL2Messages: Fr[],
|
|
48
|
+
db: MerkleTreeWriteOperations,
|
|
49
|
+
): Promise<LightweightCheckpointBuilder> {
|
|
50
|
+
// Insert l1-to-l2 messages into the tree.
|
|
51
|
+
await db.appendLeaves(
|
|
52
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
53
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async addBlock(globalVariables: GlobalVariables, endState: StateReference, txs: ProcessedTx[]): Promise<L2BlockNew> {
|
|
60
|
+
const isFirstBlock = this.blocks.length === 0;
|
|
61
|
+
if (isFirstBlock) {
|
|
62
|
+
this.lastArchives.push(await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const lastArchive = this.lastArchives.at(-1)!;
|
|
66
|
+
|
|
67
|
+
for (const tx of txs) {
|
|
68
|
+
await insertSideEffects(tx, this.db);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
|
|
72
|
+
txs,
|
|
73
|
+
lastArchive,
|
|
74
|
+
endState,
|
|
75
|
+
globalVariables,
|
|
76
|
+
this.spongeBlob,
|
|
77
|
+
isFirstBlock,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
await this.db.updateArchive(header);
|
|
81
|
+
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
82
|
+
this.lastArchives.push(newArchive);
|
|
83
|
+
|
|
84
|
+
const indexWithinCheckpoint = this.blocks.length;
|
|
85
|
+
const block = new L2BlockNew(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
|
|
86
|
+
this.blocks.push(block);
|
|
87
|
+
|
|
88
|
+
await this.spongeBlob.absorb(blockBlobFields);
|
|
89
|
+
this.blobFields.push(...blockBlobFields);
|
|
90
|
+
|
|
91
|
+
this.logger.debug(`Built block ${header.getBlockNumber()}`, {
|
|
92
|
+
globalVariables: globalVariables.toInspect(),
|
|
93
|
+
archiveRoot: newArchive.root.toString(),
|
|
94
|
+
stateReference: header.state.toInspect(),
|
|
95
|
+
blockHash: (await block.hash()).toString(),
|
|
96
|
+
txs: block.body.txEffects.map(tx => tx.txHash.toString()),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return block;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async completeCheckpoint(): Promise<Checkpoint> {
|
|
103
|
+
if (!this.blocks.length) {
|
|
104
|
+
throw new Error('No blocks added to checkpoint.');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const numBlobFields = this.blobFields.length + 1; // +1 for the checkpoint end marker.
|
|
108
|
+
const checkpointEndMarker = encodeCheckpointEndMarker({ numBlobFields });
|
|
109
|
+
this.blobFields.push(checkpointEndMarker);
|
|
110
|
+
|
|
111
|
+
const blocks = this.blocks;
|
|
112
|
+
const blockHeadersHash = await computeBlockHeadersHash(blocks.map(block => block.header));
|
|
113
|
+
|
|
114
|
+
const newArchive = this.lastArchives[this.lastArchives.length - 1];
|
|
115
|
+
|
|
116
|
+
const blobs = getBlobsPerL1Block(this.blobFields);
|
|
117
|
+
const blobsHash = computeBlobsHashFromBlobs(blobs);
|
|
118
|
+
|
|
119
|
+
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
|
|
120
|
+
|
|
121
|
+
const outHash = computeCheckpointOutHash(blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)));
|
|
122
|
+
|
|
123
|
+
const constants = this.constants!;
|
|
124
|
+
|
|
125
|
+
// timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
|
|
126
|
+
const timestamp = blocks[blocks.length - 1].timestamp;
|
|
127
|
+
|
|
128
|
+
const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
|
|
129
|
+
|
|
130
|
+
const header = CheckpointHeader.from({
|
|
131
|
+
lastArchiveRoot: this.lastArchives[0].root,
|
|
132
|
+
blockHeadersHash,
|
|
133
|
+
contentCommitment: new ContentCommitment(blobsHash, inHash, outHash),
|
|
134
|
+
slotNumber: constants.slotNumber,
|
|
135
|
+
timestamp,
|
|
136
|
+
coinbase: constants.coinbase,
|
|
137
|
+
feeRecipient: constants.feeRecipient,
|
|
138
|
+
gasFees: constants.gasFees,
|
|
139
|
+
totalManaUsed,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
6
5
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
6
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
8
7
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
@@ -11,10 +10,7 @@ import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
|
11
10
|
import { type CircuitSimulator, NativeACVMSimulator, WASMSimulatorWithBlobs } from '@aztec/simulator/server';
|
|
12
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
14
|
-
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
15
13
|
import { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
16
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
17
|
-
import type { ProcessedTx } from '@aztec/stdlib/tx';
|
|
18
14
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
19
15
|
|
|
20
16
|
import { promises as fs } from 'fs';
|
|
@@ -88,25 +84,6 @@ export async function getSimulator(
|
|
|
88
84
|
return new WASMSimulatorWithBlobs();
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
// Updates the expectedDb trees based on the new note hashes, contracts, and nullifiers from these txs
|
|
92
|
-
export const updateExpectedTreesFromTxs = async (db: MerkleTreeWriteOperations, txs: ProcessedTx[]) => {
|
|
93
|
-
await db.appendLeaves(
|
|
94
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
95
|
-
txs.flatMap(tx => padArrayEnd(tx.txEffect.noteHashes, Fr.zero(), MAX_NOTE_HASHES_PER_TX)),
|
|
96
|
-
);
|
|
97
|
-
await db.batchInsert(
|
|
98
|
-
MerkleTreeId.NULLIFIER_TREE,
|
|
99
|
-
txs.flatMap(tx => padArrayEnd(tx.txEffect.nullifiers, Fr.zero(), MAX_NULLIFIERS_PER_TX).map(x => x.toBuffer())),
|
|
100
|
-
NULLIFIER_TREE_HEIGHT,
|
|
101
|
-
);
|
|
102
|
-
for (const tx of txs) {
|
|
103
|
-
await db.sequentialInsert(
|
|
104
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
105
|
-
tx.txEffect.publicDataWrites.map(write => write.toBuffer()),
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
87
|
export const makeGlobals = (
|
|
111
88
|
blockNumber: number,
|
|
112
89
|
slotNumber = blockNumber,
|
|
@@ -116,9 +93,9 @@ export const makeGlobals = (
|
|
|
116
93
|
return GlobalVariables.from({
|
|
117
94
|
chainId: checkpointConstants.chainId,
|
|
118
95
|
version: checkpointConstants.version,
|
|
119
|
-
blockNumber /** block number */,
|
|
120
|
-
slotNumber:
|
|
121
|
-
timestamp: BigInt(blockNumber) /** block number as pseudo-timestamp for testing */,
|
|
96
|
+
blockNumber: BlockNumber(blockNumber) /** block number */,
|
|
97
|
+
slotNumber: SlotNumber(slotNumber) /** slot number */,
|
|
98
|
+
timestamp: BigInt(blockNumber * 123) /** block number * 123 as pseudo-timestamp for testing */,
|
|
122
99
|
coinbase: checkpointConstants.coinbase,
|
|
123
100
|
feeRecipient: checkpointConstants.feeRecipient,
|
|
124
101
|
gasFees: checkpointConstants.gasFees,
|
|
@@ -136,7 +113,7 @@ export const makeCheckpointConstants = (
|
|
|
136
113
|
vkTreeRoot: getVKTreeRoot(),
|
|
137
114
|
protocolContractsHash,
|
|
138
115
|
proverId: Fr.ZERO,
|
|
139
|
-
slotNumber:
|
|
116
|
+
slotNumber: SlotNumber(slotNumber),
|
|
140
117
|
coinbase: EthAddress.ZERO,
|
|
141
118
|
feeRecipient: AztecAddress.ZERO,
|
|
142
119
|
gasFees: GasFees.empty(),
|