@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +2 -0
- package/dest/block-factory/index.d.ts.map +1 -0
- package/dest/block-factory/light.d.ts +38 -0
- package/dest/block-factory/light.d.ts.map +1 -0
- package/dest/block-factory/light.js +106 -0
- package/dest/config.d.ts +8 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -2
- package/dest/index.d.ts +1 -1
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +43 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +183 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +34 -16
- package/dest/mocks/test_context.d.ts +42 -32
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +144 -87
- package/dest/orchestrator/block-building-helpers.d.ts +37 -30
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +170 -189
- package/dest/orchestrator/block-proving-state.d.ts +70 -48
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +282 -177
- package/dest/orchestrator/checkpoint-proving-state.d.ts +63 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +210 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +41 -27
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +143 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +37 -34
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +788 -277
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- package/dest/orchestrator/tx-proving-state.d.ts +15 -12
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +27 -44
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +6 -5
- package/dest/prover-client/server-epoch-prover.d.ts +16 -12
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +11 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +25 -17
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +59 -40
- package/dest/proving_broker/config.d.ts +19 -10
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +23 -6
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -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/factory.js +1 -1
- 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/gcs_proof_store.js +1 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- 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 +6 -11
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +84 -63
- package/dest/proving_broker/proving_broker.d.ts +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +40 -33
- 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/memory.js +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +401 -11
- 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_broker_instrumentation.js +11 -35
- package/dest/proving_broker/proving_job_controller.d.ts +9 -9
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +87 -60
- package/dest/proving_broker/rpc.d.ts +4 -6
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +1 -4
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +23 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +34 -31
- package/src/block-factory/index.ts +1 -0
- package/src/block-factory/light.ts +136 -0
- package/src/config.ts +25 -9
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +249 -0
- package/src/mocks/fixtures.ts +44 -39
- package/src/mocks/test_context.ts +218 -116
- package/src/orchestrator/block-building-helpers.ts +258 -334
- package/src/orchestrator/block-proving-state.ts +325 -231
- package/src/orchestrator/checkpoint-proving-state.ts +303 -0
- package/src/orchestrator/epoch-proving-state.ts +191 -113
- package/src/orchestrator/orchestrator.ts +587 -318
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- package/src/orchestrator/tx-proving-state.ts +48 -66
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +20 -25
- package/src/prover-client/server-epoch-prover.ts +40 -22
- package/src/proving_broker/broker_prover_facade.ts +206 -128
- package/src/proving_broker/config.ts +25 -7
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +1 -1
- package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
- package/src/proving_broker/proving_agent.ts +90 -64
- package/src/proving_broker/proving_broker.ts +57 -41
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +29 -13
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +10 -35
- package/src/proving_broker/proving_job_controller.ts +92 -81
- package/src/proving_broker/rpc.ts +1 -6
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +156 -64
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/dest/block_builder/index.d.ts +0 -6
- package/dest/block_builder/index.d.ts.map +0 -1
- package/dest/block_builder/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/bin/get-proof-inputs.ts +0 -59
- package/src/block_builder/index.ts +0 -6
- package/src/block_builder/light.ts +0 -101
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
- /package/dest/{block_builder → block-factory}/index.js +0 -0
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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';
|
|
6
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
7
7
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
8
|
-
import {
|
|
8
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
9
|
+
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
10
|
+
import { type CircuitSimulator, NativeACVMSimulator, WASMSimulatorWithBlobs } from '@aztec/simulator/server';
|
|
9
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
11
|
-
import
|
|
12
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
|
-
import type { ProcessedTx } from '@aztec/stdlib/tx';
|
|
13
|
+
import { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
14
14
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
15
|
|
|
16
16
|
import { promises as fs } from 'fs';
|
|
@@ -32,7 +32,7 @@ export const getEnvironmentConfig = async (logger: Logger) => {
|
|
|
32
32
|
try {
|
|
33
33
|
const expectedBBPath = BB_BINARY_PATH
|
|
34
34
|
? BB_BINARY_PATH
|
|
35
|
-
: `${path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/', BB_RELEASE_DIR)}/bb`;
|
|
35
|
+
: `${path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/', BB_RELEASE_DIR)}/bb-avm`;
|
|
36
36
|
await fs.access(expectedBBPath, fs.constants.R_OK);
|
|
37
37
|
const tempWorkingDirectory = `${TEMP_DIR}/${randomBytes(4).toString('hex')}`;
|
|
38
38
|
const bbWorkingDirectory = BB_WORKING_DIRECTORY ? BB_WORKING_DIRECTORY : `${tempWorkingDirectory}/bb`;
|
|
@@ -64,10 +64,10 @@ export const getEnvironmentConfig = async (logger: Logger) => {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export async function
|
|
67
|
+
export async function getSimulator(
|
|
68
68
|
config: { acvmWorkingDirectory: string | undefined; acvmBinaryPath: string | undefined },
|
|
69
69
|
logger?: Logger,
|
|
70
|
-
): Promise<
|
|
70
|
+
): Promise<CircuitSimulator> {
|
|
71
71
|
if (config.acvmBinaryPath && config.acvmWorkingDirectory) {
|
|
72
72
|
try {
|
|
73
73
|
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
|
|
@@ -84,34 +84,39 @@ export async function getSimulationProvider(
|
|
|
84
84
|
return new WASMSimulatorWithBlobs();
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
87
|
+
export const makeGlobals = (
|
|
88
|
+
blockNumber: number,
|
|
89
|
+
slotNumber = blockNumber,
|
|
90
|
+
overrides: Partial<FieldsOf<GlobalVariables> & FieldsOf<CheckpointConstantData>> = {},
|
|
91
|
+
) => {
|
|
92
|
+
const checkpointConstants = makeCheckpointConstants(slotNumber, overrides);
|
|
93
|
+
return GlobalVariables.from({
|
|
94
|
+
chainId: checkpointConstants.chainId,
|
|
95
|
+
version: checkpointConstants.version,
|
|
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 */,
|
|
99
|
+
coinbase: checkpointConstants.coinbase,
|
|
100
|
+
feeRecipient: checkpointConstants.feeRecipient,
|
|
101
|
+
gasFees: checkpointConstants.gasFees,
|
|
102
|
+
...overrides,
|
|
103
|
+
});
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
export const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
export const makeCheckpointConstants = (
|
|
107
|
+
slotNumber: number,
|
|
108
|
+
overrides: Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
109
|
+
) => {
|
|
110
|
+
return CheckpointConstantData.from({
|
|
111
|
+
chainId: Fr.ZERO,
|
|
112
|
+
version: Fr.ZERO,
|
|
113
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
114
|
+
protocolContractsHash,
|
|
115
|
+
proverId: Fr.ZERO,
|
|
116
|
+
slotNumber: SlotNumber(slotNumber),
|
|
117
|
+
coinbase: EthAddress.ZERO,
|
|
118
|
+
feeRecipient: AztecAddress.ZERO,
|
|
119
|
+
gasFees: GasFees.empty(),
|
|
120
|
+
...overrides,
|
|
121
|
+
});
|
|
117
122
|
};
|
|
@@ -1,56 +1,65 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
3
|
+
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
4
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { padArrayEnd, times, timesAsync } from '@aztec/foundation/collection';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
8
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
6
9
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
7
|
-
import {
|
|
10
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
8
11
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
9
|
-
import {
|
|
10
|
-
PublicProcessor,
|
|
11
|
-
PublicTxSimulationTester,
|
|
12
|
-
PublicTxSimulator,
|
|
13
|
-
SimpleContractDataSource,
|
|
14
|
-
WorldStateDB,
|
|
15
|
-
} from '@aztec/simulator/server';
|
|
16
12
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
17
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
18
|
-
import
|
|
19
|
-
import type {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
14
|
+
import { EthAddress } from '@aztec/stdlib/block';
|
|
15
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
16
|
+
import type { MerkleTreeWriteOperations, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
17
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
18
|
+
import { mockProcessedTx } from '@aztec/stdlib/testing';
|
|
19
|
+
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
20
|
+
import {
|
|
21
|
+
type BlockHeader,
|
|
22
|
+
type GlobalVariables,
|
|
23
|
+
type ProcessedTx,
|
|
24
|
+
StateReference,
|
|
25
|
+
TreeSnapshots,
|
|
26
|
+
} from '@aztec/stdlib/tx';
|
|
23
27
|
import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
|
|
24
28
|
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
25
29
|
|
|
26
30
|
import { promises as fs } from 'fs';
|
|
27
31
|
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
32
|
+
import { LightweightCheckpointBuilder } from '../light/lightweight_checkpoint_builder.js';
|
|
33
|
+
import {
|
|
34
|
+
buildFinalBlobChallenges,
|
|
35
|
+
getTreeSnapshot,
|
|
36
|
+
insertSideEffects,
|
|
37
|
+
} from '../orchestrator/block-building-helpers.js';
|
|
38
|
+
import type { BlockProvingState } from '../orchestrator/block-proving-state.js';
|
|
30
39
|
import { ProvingOrchestrator } from '../orchestrator/index.js';
|
|
31
40
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
32
41
|
import { TestBroker } from '../test/mock_prover.js';
|
|
33
|
-
import { getEnvironmentConfig,
|
|
42
|
+
import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobals } from './fixtures.js';
|
|
34
43
|
|
|
35
44
|
export class TestContext {
|
|
36
45
|
private headers: Map<number, BlockHeader> = new Map();
|
|
46
|
+
private checkpoints: Checkpoint[] = [];
|
|
47
|
+
private nextCheckpointIndex = 0;
|
|
48
|
+
private nextCheckpointNumber = CheckpointNumber(1);
|
|
49
|
+
private nextBlockNumber = 1;
|
|
50
|
+
private epochNumber = 1;
|
|
37
51
|
private feePayerBalance: Fr;
|
|
38
52
|
|
|
39
53
|
constructor(
|
|
40
|
-
public publicTxSimulator: PublicTxSimulator,
|
|
41
54
|
public worldState: MerkleTreeAdminDatabase,
|
|
42
|
-
public publicProcessor: PublicProcessor,
|
|
43
|
-
public globalVariables: GlobalVariables,
|
|
44
55
|
public prover: ServerCircuitProver,
|
|
45
56
|
public broker: TestBroker,
|
|
46
57
|
public brokerProverFacade: BrokerCircuitProverFacade,
|
|
47
58
|
public orchestrator: TestProvingOrchestrator,
|
|
48
|
-
|
|
49
|
-
public feePayer: AztecAddress,
|
|
59
|
+
private feePayer: AztecAddress,
|
|
50
60
|
initialFeePayerBalance: Fr,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
public logger: Logger,
|
|
61
|
+
private directoriesToCleanup: string[],
|
|
62
|
+
private logger: Logger,
|
|
54
63
|
) {
|
|
55
64
|
this.feePayerBalance = initialFeePayerBalance;
|
|
56
65
|
}
|
|
@@ -61,13 +70,15 @@ export class TestContext {
|
|
|
61
70
|
|
|
62
71
|
static async new(
|
|
63
72
|
logger: Logger,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
new TestCircuitProver(await
|
|
67
|
-
|
|
73
|
+
{
|
|
74
|
+
proverCount = 4,
|
|
75
|
+
createProver = async (bbConfig: BBProverConfig) => new TestCircuitProver(await getSimulator(bbConfig, logger)),
|
|
76
|
+
}: {
|
|
77
|
+
proverCount?: number;
|
|
78
|
+
createProver?: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver>;
|
|
79
|
+
} = {},
|
|
68
80
|
) {
|
|
69
81
|
const directoriesToCleanup: string[] = [];
|
|
70
|
-
const globalVariables = makeGlobals(blockNumber);
|
|
71
82
|
|
|
72
83
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
73
84
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
@@ -76,25 +87,10 @@ export class TestContext {
|
|
|
76
87
|
|
|
77
88
|
// Separated dbs for public processor and prover - see public_processor for context
|
|
78
89
|
const ws = await NativeWorldStateService.tmp(
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
/*rollupAddress=*/ undefined,
|
|
91
|
+
/*cleanupTmpDir=*/ true,
|
|
81
92
|
prefilledPublicData,
|
|
82
93
|
);
|
|
83
|
-
const publicDb = await ws.fork();
|
|
84
|
-
|
|
85
|
-
const contractDataSource = new SimpleContractDataSource();
|
|
86
|
-
const worldStateDB = new WorldStateDB(publicDb, contractDataSource);
|
|
87
|
-
|
|
88
|
-
const tester = new PublicTxSimulationTester(worldStateDB, contractDataSource, publicDb);
|
|
89
|
-
|
|
90
|
-
const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, globalVariables, true);
|
|
91
|
-
const processor = new PublicProcessor(
|
|
92
|
-
publicDb,
|
|
93
|
-
globalVariables,
|
|
94
|
-
worldStateDB,
|
|
95
|
-
publicTxSimulator,
|
|
96
|
-
new TestDateProvider(),
|
|
97
|
-
);
|
|
98
94
|
|
|
99
95
|
let localProver: ServerCircuitProver;
|
|
100
96
|
const config = await getEnvironmentConfig(logger);
|
|
@@ -107,6 +103,8 @@ export class TestContext {
|
|
|
107
103
|
bbBinaryPath: config.expectedBBPath,
|
|
108
104
|
bbWorkingDirectory: config.bbWorkingDirectory,
|
|
109
105
|
bbSkipCleanup: config.bbSkipCleanup,
|
|
106
|
+
numConcurrentIVCVerifiers: 2,
|
|
107
|
+
bbIVCConcurrency: 1,
|
|
110
108
|
};
|
|
111
109
|
localProver = await createProver(bbConfig);
|
|
112
110
|
}
|
|
@@ -117,25 +115,20 @@ export class TestContext {
|
|
|
117
115
|
|
|
118
116
|
const broker = new TestBroker(proverCount, localProver);
|
|
119
117
|
const facade = new BrokerCircuitProverFacade(broker);
|
|
120
|
-
const orchestrator = new TestProvingOrchestrator(ws, facade,
|
|
118
|
+
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
|
|
121
119
|
|
|
122
120
|
await broker.start();
|
|
123
121
|
facade.start();
|
|
124
122
|
|
|
125
123
|
return new this(
|
|
126
|
-
publicTxSimulator,
|
|
127
124
|
ws,
|
|
128
|
-
processor,
|
|
129
|
-
globalVariables,
|
|
130
125
|
localProver,
|
|
131
126
|
broker,
|
|
132
127
|
facade,
|
|
133
128
|
orchestrator,
|
|
134
|
-
blockNumber,
|
|
135
129
|
feePayer,
|
|
136
130
|
initialFeePayerBalance,
|
|
137
131
|
directoriesToCleanup,
|
|
138
|
-
tester,
|
|
139
132
|
logger,
|
|
140
133
|
);
|
|
141
134
|
}
|
|
@@ -144,16 +137,6 @@ export class TestContext {
|
|
|
144
137
|
return this.worldState.fork();
|
|
145
138
|
}
|
|
146
139
|
|
|
147
|
-
public getBlockHeader(blockNumber: 0): BlockHeader;
|
|
148
|
-
public getBlockHeader(blockNumber: number): BlockHeader | undefined;
|
|
149
|
-
public getBlockHeader(blockNumber = 0) {
|
|
150
|
-
return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public getPreviousBlockHeader(currentBlockNumber = this.blockNumber): BlockHeader {
|
|
154
|
-
return this.getBlockHeader(currentBlockNumber - 1)!;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
140
|
async cleanup() {
|
|
158
141
|
await this.brokerProverFacade.stop();
|
|
159
142
|
await this.broker.stop();
|
|
@@ -166,77 +149,199 @@ export class TestContext {
|
|
|
166
149
|
}
|
|
167
150
|
}
|
|
168
151
|
|
|
169
|
-
public
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
152
|
+
public startNewEpoch() {
|
|
153
|
+
this.checkpoints = [];
|
|
154
|
+
this.nextCheckpointIndex = 0;
|
|
155
|
+
this.epochNumber++;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Return blob fields of all checkpoints in the epoch.
|
|
159
|
+
public getBlobFields() {
|
|
160
|
+
return this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public async getFinalBlobChallenges() {
|
|
164
|
+
const blobFields = this.getBlobFields();
|
|
165
|
+
return await buildFinalBlobChallenges(blobFields);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public async makeCheckpoint(
|
|
169
|
+
numBlocks: number,
|
|
170
|
+
{
|
|
171
|
+
numTxsPerBlock = 0,
|
|
172
|
+
numL1ToL2Messages = 0,
|
|
173
|
+
makeProcessedTxOpts = () => ({}),
|
|
174
|
+
...constantOpts
|
|
175
|
+
}: {
|
|
176
|
+
numTxsPerBlock?: number | number[];
|
|
177
|
+
numL1ToL2Messages?: number;
|
|
178
|
+
makeProcessedTxOpts?: (
|
|
179
|
+
blockGlobalVariables: GlobalVariables,
|
|
180
|
+
txIndex: number,
|
|
181
|
+
) => Partial<Parameters<typeof mockProcessedTx>[0]>;
|
|
182
|
+
} & Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
183
|
+
) {
|
|
184
|
+
if (numBlocks === 0) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
'Cannot make a checkpoint with 0 blocks. Crate an empty block (numTxsPerBlock = 0) if there are no txs.',
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const checkpointIndex = this.nextCheckpointIndex++;
|
|
191
|
+
const checkpointNumber = this.nextCheckpointNumber;
|
|
192
|
+
this.nextCheckpointNumber++;
|
|
193
|
+
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
194
|
+
|
|
195
|
+
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
196
|
+
|
|
197
|
+
const fork = await this.worldState.fork();
|
|
198
|
+
|
|
199
|
+
// Build l1 to l2 messages.
|
|
200
|
+
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
201
|
+
await fork.appendLeaves(
|
|
202
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
203
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
204
|
+
);
|
|
205
|
+
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
|
|
206
|
+
|
|
207
|
+
const startBlockNumber = this.nextBlockNumber;
|
|
208
|
+
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
209
|
+
// All blocks in the same slot/checkpoint share the same timestamp.
|
|
210
|
+
const timestamp = BigInt(slotNumber * 26);
|
|
211
|
+
|
|
212
|
+
// Build global variables.
|
|
213
|
+
const blockGlobalVariables = times(numBlocks, i =>
|
|
214
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
215
|
+
coinbase: constants.coinbase,
|
|
216
|
+
feeRecipient: constants.feeRecipient,
|
|
217
|
+
gasFees: constants.gasFees,
|
|
218
|
+
timestamp,
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
this.nextBlockNumber += numBlocks;
|
|
222
|
+
|
|
223
|
+
// Build txs.
|
|
224
|
+
let totalTxs = 0;
|
|
225
|
+
const blockEndStates: StateReference[] = [];
|
|
226
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
227
|
+
const txIndexOffset = totalTxs;
|
|
228
|
+
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
229
|
+
totalTxs += numTxs;
|
|
230
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
231
|
+
this.makeProcessedTx({
|
|
232
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
233
|
+
globalVariables: blockGlobalVariables[blockIndex],
|
|
234
|
+
anchorBlockHeader: previousBlockHeader,
|
|
235
|
+
newL1ToL2Snapshot,
|
|
236
|
+
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// Insert side effects into the trees.
|
|
241
|
+
const endState = await this.updateTrees(txs, fork);
|
|
242
|
+
blockEndStates.push(endState);
|
|
243
|
+
|
|
244
|
+
return txs;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const cleanFork = await this.worldState.fork();
|
|
248
|
+
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
249
|
+
checkpointNumber,
|
|
250
|
+
constants,
|
|
251
|
+
l1ToL2Messages,
|
|
252
|
+
cleanFork,
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Add tx effects to db and build block headers.
|
|
256
|
+
const blocks = [];
|
|
257
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
258
|
+
const txs = blockTxs[i];
|
|
259
|
+
const state = blockEndStates[i];
|
|
260
|
+
|
|
261
|
+
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
262
|
+
expectedEndState: state,
|
|
263
|
+
insertTxsEffects: true,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const header = block.header;
|
|
267
|
+
this.headers.set(block.number, header);
|
|
268
|
+
|
|
269
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
270
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
271
|
+
|
|
272
|
+
blocks.push({ header, txs });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
276
|
+
this.checkpoints.push(checkpoint);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
constants,
|
|
280
|
+
header: checkpoint.header,
|
|
281
|
+
blocks,
|
|
282
|
+
l1ToL2Messages,
|
|
283
|
+
previousBlockHeader,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
288
|
+
const tx = await mockProcessedTx({
|
|
179
289
|
vkTreeRoot: getVKTreeRoot(),
|
|
180
|
-
|
|
181
|
-
globalVariables: this.globalVariables,
|
|
290
|
+
protocolContracts: ProtocolContractsList,
|
|
182
291
|
feePayer: this.feePayer,
|
|
183
292
|
...opts,
|
|
184
293
|
});
|
|
294
|
+
|
|
185
295
|
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
186
|
-
if (opts?.privateOnly) {
|
|
187
|
-
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
188
|
-
tx.txEffect.publicDataWrites[0] = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
189
|
-
}
|
|
190
|
-
return tx;
|
|
191
|
-
}
|
|
192
296
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
) {
|
|
200
|
-
const globalVariables = typeof blockNumOrGlobals === 'number' ? makeGlobals(blockNumOrGlobals) : blockNumOrGlobals;
|
|
201
|
-
const blockNum = globalVariables.blockNumber.toNumber();
|
|
202
|
-
const db = await this.worldState.fork();
|
|
203
|
-
const msgs = times(numMsgs, i => new Fr(blockNum * 100 + i));
|
|
204
|
-
const txs = await timesParallel(numTxs, i =>
|
|
205
|
-
this.makeProcessedTx({ seed: i + blockNum * 1000, globalVariables, ...makeProcessedTxOpts(i) }),
|
|
206
|
-
);
|
|
207
|
-
await this.setTreeRoots(txs);
|
|
297
|
+
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
298
|
+
const feePaymentPublicDataWrite = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
299
|
+
tx.txEffect.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
300
|
+
if (tx.avmProvingRequest) {
|
|
301
|
+
tx.avmProvingRequest.inputs.publicInputs.accumulatedData.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
302
|
+
}
|
|
208
303
|
|
|
209
|
-
|
|
210
|
-
this.headers.set(blockNum, block.header);
|
|
211
|
-
await this.worldState.handleL2BlockAndMessages(block, msgs);
|
|
212
|
-
return { block, txs, msgs };
|
|
304
|
+
return tx;
|
|
213
305
|
}
|
|
214
306
|
|
|
215
|
-
|
|
216
|
-
|
|
307
|
+
private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
|
|
308
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
309
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
310
|
+
}
|
|
311
|
+
return Number(blockNumber) === 0
|
|
312
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
313
|
+
: this.headers.get(Number(blockNumber))!;
|
|
217
314
|
}
|
|
218
315
|
|
|
219
|
-
|
|
220
|
-
|
|
316
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
317
|
+
let startStateReference = await fork.getStateReference();
|
|
318
|
+
let endStateReference = startStateReference;
|
|
221
319
|
for (const tx of txs) {
|
|
222
|
-
|
|
223
|
-
await
|
|
224
|
-
|
|
320
|
+
await insertSideEffects(tx, fork);
|
|
321
|
+
endStateReference = await fork.getStateReference();
|
|
322
|
+
|
|
225
323
|
if (tx.avmProvingRequest) {
|
|
324
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
325
|
+
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
226
326
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
227
|
-
|
|
327
|
+
l1ToL2MessageTree,
|
|
228
328
|
startStateReference.partial.noteHashTree,
|
|
229
329
|
startStateReference.partial.nullifierTree,
|
|
230
330
|
startStateReference.partial.publicDataTree,
|
|
231
331
|
);
|
|
332
|
+
|
|
232
333
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
233
|
-
|
|
334
|
+
l1ToL2MessageTree,
|
|
234
335
|
endStateReference.partial.noteHashTree,
|
|
235
336
|
endStateReference.partial.nullifierTree,
|
|
236
337
|
endStateReference.partial.publicDataTree,
|
|
237
338
|
);
|
|
238
339
|
}
|
|
340
|
+
|
|
341
|
+
startStateReference = endStateReference;
|
|
239
342
|
}
|
|
343
|
+
|
|
344
|
+
return endStateReference;
|
|
240
345
|
}
|
|
241
346
|
}
|
|
242
347
|
|
|
@@ -245,12 +350,9 @@ class TestProvingOrchestrator extends ProvingOrchestrator {
|
|
|
245
350
|
|
|
246
351
|
// Disable this check by default, since it requires seeding world state with the block being built
|
|
247
352
|
// This is only enabled in some tests with multiple blocks that populate the pending chain via makePendingBlock
|
|
248
|
-
protected override verifyBuiltBlockAgainstSyncedState(
|
|
249
|
-
l2Block: L2Block,
|
|
250
|
-
newArchive: AppendOnlyTreeSnapshot,
|
|
251
|
-
): Promise<void> {
|
|
353
|
+
protected override verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState): Promise<void> {
|
|
252
354
|
if (this.isVerifyBuiltBlockAgainstSyncedStateEnabled) {
|
|
253
|
-
return super.verifyBuiltBlockAgainstSyncedState(
|
|
355
|
+
return super.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
254
356
|
}
|
|
255
357
|
return Promise.resolve();
|
|
256
358
|
}
|