@aztec/sequencer-client 0.23.0 → 0.26.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_builder/solo_block_builder.d.ts +9 -9
- package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.js +26 -48
- package/dest/global_variable_builder/viem-reader.js +2 -2
- package/dest/prover/empty.d.ts +2 -2
- package/dest/prover/empty.d.ts.map +1 -1
- package/dest/prover/empty.js +1 -1
- package/dest/prover/index.d.ts +2 -2
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.d.ts +0 -2
- package/dest/publisher/l1-publisher.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.js +2 -3
- package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
- package/dest/publisher/viem-tx-sender.js +6 -10
- package/dest/sequencer/abstract_phase_manager.d.ts +23 -30
- package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/abstract_phase_manager.js +151 -98
- package/dest/sequencer/{fee_distribution_phase_manager.d.ts → app_logic_phase_manager.d.ts} +9 -11
- package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -0
- package/dest/sequencer/app_logic_phase_manager.js +44 -0
- package/dest/sequencer/phase_manager_factory.d.ts +19 -0
- package/dest/sequencer/phase_manager_factory.d.ts.map +1 -0
- package/dest/sequencer/phase_manager_factory.js +51 -0
- package/dest/sequencer/processed_tx.d.ts +4 -4
- package/dest/sequencer/processed_tx.d.ts.map +1 -1
- package/dest/sequencer/processed_tx.js +8 -8
- package/dest/sequencer/public_processor.d.ts +1 -1
- package/dest/sequencer/public_processor.d.ts.map +1 -1
- package/dest/sequencer/public_processor.js +13 -11
- package/dest/sequencer/sequencer.d.ts +3 -3
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +23 -16
- package/dest/sequencer/{fee_preparation_phase_manager.d.ts → setup_phase_manager.d.ts} +9 -11
- package/dest/sequencer/setup_phase_manager.d.ts.map +1 -0
- package/dest/sequencer/setup_phase_manager.js +37 -0
- package/dest/sequencer/{application_logic_phase_manager.d.ts → teardown_phase_manager.d.ts} +9 -12
- package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -0
- package/dest/sequencer/teardown_phase_manager.js +36 -0
- package/dest/simulator/index.d.ts +11 -5
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/public_executor.d.ts +8 -3
- package/dest/simulator/public_executor.d.ts.map +1 -1
- package/dest/simulator/public_executor.js +64 -11
- package/dest/simulator/public_kernel.d.ts +11 -5
- package/dest/simulator/public_kernel.d.ts.map +1 -1
- package/dest/simulator/public_kernel.js +35 -16
- package/dest/simulator/rollup.js +2 -2
- package/package.json +14 -24
- package/src/block_builder/index.ts +24 -0
- package/src/block_builder/solo_block_builder.ts +726 -0
- package/src/block_builder/types.ts +8 -0
- package/src/client/index.ts +1 -0
- package/src/client/sequencer-client.ts +97 -0
- package/src/config.ts +86 -0
- package/src/global_variable_builder/config.ts +20 -0
- package/src/global_variable_builder/global_builder.ts +95 -0
- package/src/global_variable_builder/index.ts +16 -0
- package/src/global_variable_builder/viem-reader.ts +61 -0
- package/src/index.ts +15 -0
- package/src/mocks/verification_keys.ts +36 -0
- package/src/prover/empty.ts +74 -0
- package/src/prover/index.ts +53 -0
- package/src/publisher/config.ts +41 -0
- package/src/publisher/index.ts +14 -0
- package/src/publisher/l1-publisher.ts +362 -0
- package/src/publisher/viem-tx-sender.ts +235 -0
- package/src/receiver.ts +13 -0
- package/src/sequencer/abstract_phase_manager.ts +489 -0
- package/src/sequencer/app_logic_phase_manager.ts +75 -0
- package/src/sequencer/config.ts +1 -0
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/phase_manager_factory.ts +122 -0
- package/src/sequencer/processed_tx.ts +94 -0
- package/src/sequencer/public_processor.ts +153 -0
- package/src/sequencer/sequencer.ts +469 -0
- package/src/sequencer/setup_phase_manager.ts +68 -0
- package/src/sequencer/teardown_phase_manager.ts +67 -0
- package/src/simulator/index.ts +57 -0
- package/src/simulator/public_executor.ts +267 -0
- package/src/simulator/public_kernel.ts +84 -0
- package/src/simulator/rollup.ts +76 -0
- package/src/utils.ts +16 -0
- package/dest/sequencer/application_logic_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/application_logic_phase_manager.js +0 -64
- package/dest/sequencer/fee_distribution_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/fee_distribution_phase_manager.js +0 -42
- package/dest/sequencer/fee_preparation_phase_manager.d.ts.map +0 -1
- package/dest/sequencer/fee_preparation_phase_manager.js +0 -43
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing the names of the trees for the base rollup.
|
|
3
|
+
*/
|
|
4
|
+
type BaseTreeNames = 'NoteHashTree' | 'ContractTree' | 'NullifierTree' | 'PublicDataTree';
|
|
5
|
+
/**
|
|
6
|
+
* Type representing the names of the trees.
|
|
7
|
+
*/
|
|
8
|
+
export type TreeNames = BaseTreeNames | 'L1ToL2MessageTree' | 'Archive';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sequencer-client.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ContractDataSource, L1ToL2MessageSource, L2BlockSource } from '@aztec/circuit-types';
|
|
2
|
+
import { P2P } from '@aztec/p2p';
|
|
3
|
+
import { WorldStateSynchronizer } from '@aztec/world-state';
|
|
4
|
+
|
|
5
|
+
import { SoloBlockBuilder } from '../block_builder/solo_block_builder.js';
|
|
6
|
+
import { SequencerClientConfig } from '../config.js';
|
|
7
|
+
import { getGlobalVariableBuilder } from '../global_variable_builder/index.js';
|
|
8
|
+
import { getVerificationKeys } from '../mocks/verification_keys.js';
|
|
9
|
+
import { EmptyRollupProver } from '../prover/empty.js';
|
|
10
|
+
import { getL1Publisher } from '../publisher/index.js';
|
|
11
|
+
import { Sequencer, SequencerConfig } from '../sequencer/index.js';
|
|
12
|
+
import { PublicProcessorFactory } from '../sequencer/public_processor.js';
|
|
13
|
+
import { RealRollupCircuitSimulator } from '../simulator/rollup.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Encapsulates the full sequencer and publisher.
|
|
17
|
+
*/
|
|
18
|
+
export class SequencerClient {
|
|
19
|
+
constructor(private sequencer: Sequencer) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Initializes and starts a new instance.
|
|
23
|
+
* @param config - Configuration for the sequencer, publisher, and L1 tx sender.
|
|
24
|
+
* @param p2pClient - P2P client that provides the txs to be sequenced.
|
|
25
|
+
* @param worldStateSynchronizer - Provides access to world state.
|
|
26
|
+
* @param contractDataSource - Provides access to contract bytecode for public executions.
|
|
27
|
+
* @param l2BlockSource - Provides information about the previously published blocks.
|
|
28
|
+
* @param l1ToL2MessageSource - Provides access to L1 to L2 messages.
|
|
29
|
+
* @returns A new running instance.
|
|
30
|
+
*/
|
|
31
|
+
public static async new(
|
|
32
|
+
config: SequencerClientConfig,
|
|
33
|
+
p2pClient: P2P,
|
|
34
|
+
worldStateSynchronizer: WorldStateSynchronizer,
|
|
35
|
+
contractDataSource: ContractDataSource,
|
|
36
|
+
l2BlockSource: L2BlockSource,
|
|
37
|
+
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
38
|
+
) {
|
|
39
|
+
const publisher = getL1Publisher(config);
|
|
40
|
+
const globalsBuilder = getGlobalVariableBuilder(config);
|
|
41
|
+
const merkleTreeDb = worldStateSynchronizer.getLatest();
|
|
42
|
+
|
|
43
|
+
const blockBuilder = new SoloBlockBuilder(
|
|
44
|
+
merkleTreeDb,
|
|
45
|
+
getVerificationKeys(),
|
|
46
|
+
new RealRollupCircuitSimulator(),
|
|
47
|
+
new EmptyRollupProver(),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const publicProcessorFactory = new PublicProcessorFactory(merkleTreeDb, contractDataSource, l1ToL2MessageSource);
|
|
51
|
+
|
|
52
|
+
const sequencer = new Sequencer(
|
|
53
|
+
publisher,
|
|
54
|
+
globalsBuilder,
|
|
55
|
+
p2pClient,
|
|
56
|
+
worldStateSynchronizer,
|
|
57
|
+
blockBuilder,
|
|
58
|
+
l2BlockSource,
|
|
59
|
+
l1ToL2MessageSource,
|
|
60
|
+
publicProcessorFactory,
|
|
61
|
+
config,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
await sequencer.start();
|
|
65
|
+
return new SequencerClient(sequencer);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Updates sequencer config.
|
|
70
|
+
* @param config - New parameters.
|
|
71
|
+
*/
|
|
72
|
+
public updateSequencerConfig(config: SequencerConfig) {
|
|
73
|
+
this.sequencer.updateConfig(config);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stops the sequencer from processing new txs.
|
|
78
|
+
*/
|
|
79
|
+
public async stop() {
|
|
80
|
+
await this.sequencer.stop();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Restarts the sequencer after being stopped.
|
|
85
|
+
*/
|
|
86
|
+
public restart() {
|
|
87
|
+
this.sequencer.restart();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get coinbase() {
|
|
91
|
+
return this.sequencer.coinbase;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get feeRecipient() {
|
|
95
|
+
return this.sequencer.feeRecipient;
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AztecAddress } from '@aztec/circuits.js';
|
|
2
|
+
import { L1ContractAddresses, NULL_KEY } from '@aztec/ethereum';
|
|
3
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
|
|
5
|
+
import { Hex } from 'viem';
|
|
6
|
+
|
|
7
|
+
import { GlobalReaderConfig } from './global_variable_builder/index.js';
|
|
8
|
+
import { PublisherConfig, TxSenderConfig } from './publisher/config.js';
|
|
9
|
+
import { SequencerConfig } from './sequencer/config.js';
|
|
10
|
+
|
|
11
|
+
/** Chain configuration. */
|
|
12
|
+
type ChainConfig = {
|
|
13
|
+
/** The chain id of the ethereum host. */
|
|
14
|
+
chainId: number;
|
|
15
|
+
/** The version of the rollup. */
|
|
16
|
+
version: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configuration settings for the SequencerClient.
|
|
21
|
+
*/
|
|
22
|
+
export type SequencerClientConfig = PublisherConfig &
|
|
23
|
+
TxSenderConfig &
|
|
24
|
+
SequencerConfig &
|
|
25
|
+
GlobalReaderConfig &
|
|
26
|
+
ChainConfig;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of SequencerClientConfig out of environment variables using sensible defaults for integration testing if not set.
|
|
30
|
+
*/
|
|
31
|
+
export function getConfigEnvVars(): SequencerClientConfig {
|
|
32
|
+
const {
|
|
33
|
+
SEQ_PUBLISHER_PRIVATE_KEY,
|
|
34
|
+
ETHEREUM_HOST,
|
|
35
|
+
CHAIN_ID,
|
|
36
|
+
VERSION,
|
|
37
|
+
API_KEY,
|
|
38
|
+
SEQ_REQUIRED_CONFIRMATIONS,
|
|
39
|
+
SEQ_PUBLISH_RETRY_INTERVAL_MS,
|
|
40
|
+
SEQ_TX_POLLING_INTERVAL_MS,
|
|
41
|
+
SEQ_MAX_TX_PER_BLOCK,
|
|
42
|
+
SEQ_MIN_TX_PER_BLOCK,
|
|
43
|
+
AVAILABILITY_ORACLE_CONTRACT_ADDRESS,
|
|
44
|
+
ROLLUP_CONTRACT_ADDRESS,
|
|
45
|
+
REGISTRY_CONTRACT_ADDRESS,
|
|
46
|
+
INBOX_CONTRACT_ADDRESS,
|
|
47
|
+
CONTRACT_DEPLOYMENT_EMITTER_ADDRESS,
|
|
48
|
+
OUTBOX_CONTRACT_ADDRESS,
|
|
49
|
+
COINBASE,
|
|
50
|
+
FEE_RECIPIENT,
|
|
51
|
+
} = process.env;
|
|
52
|
+
|
|
53
|
+
const publisherPrivateKey: Hex = SEQ_PUBLISHER_PRIVATE_KEY
|
|
54
|
+
? `0x${SEQ_PUBLISHER_PRIVATE_KEY.replace('0x', '')}`
|
|
55
|
+
: NULL_KEY;
|
|
56
|
+
// Populate the relevant addresses for use by the sequencer
|
|
57
|
+
const addresses: L1ContractAddresses = {
|
|
58
|
+
availabilityOracleAddress: AVAILABILITY_ORACLE_CONTRACT_ADDRESS
|
|
59
|
+
? EthAddress.fromString(AVAILABILITY_ORACLE_CONTRACT_ADDRESS)
|
|
60
|
+
: EthAddress.ZERO,
|
|
61
|
+
rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
62
|
+
registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
63
|
+
inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
64
|
+
outboxAddress: OUTBOX_CONTRACT_ADDRESS ? EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS) : EthAddress.ZERO,
|
|
65
|
+
contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS
|
|
66
|
+
? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS)
|
|
67
|
+
: EthAddress.ZERO,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
rpcUrl: ETHEREUM_HOST ? ETHEREUM_HOST : '',
|
|
72
|
+
chainId: CHAIN_ID ? +CHAIN_ID : 31337, // 31337 is the default chain id for anvil
|
|
73
|
+
version: VERSION ? +VERSION : 1, // 1 is our default version
|
|
74
|
+
apiKey: API_KEY,
|
|
75
|
+
requiredConfirmations: SEQ_REQUIRED_CONFIRMATIONS ? +SEQ_REQUIRED_CONFIRMATIONS : 1,
|
|
76
|
+
l1BlockPublishRetryIntervalMS: SEQ_PUBLISH_RETRY_INTERVAL_MS ? +SEQ_PUBLISH_RETRY_INTERVAL_MS : 1_000,
|
|
77
|
+
transactionPollingIntervalMS: SEQ_TX_POLLING_INTERVAL_MS ? +SEQ_TX_POLLING_INTERVAL_MS : 1_000,
|
|
78
|
+
l1Contracts: addresses,
|
|
79
|
+
publisherPrivateKey,
|
|
80
|
+
maxTxsPerBlock: SEQ_MAX_TX_PER_BLOCK ? +SEQ_MAX_TX_PER_BLOCK : 32,
|
|
81
|
+
minTxsPerBlock: SEQ_MIN_TX_PER_BLOCK ? +SEQ_MIN_TX_PER_BLOCK : 1,
|
|
82
|
+
// TODO: undefined should not be allowed for the following 2 values in PROD
|
|
83
|
+
coinbase: COINBASE ? EthAddress.fromString(COINBASE) : undefined,
|
|
84
|
+
feeRecipient: FEE_RECIPIENT ? AztecAddress.fromString(FEE_RECIPIENT) : undefined,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { L1ContractAddresses } from '@aztec/ethereum';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration of the L1GlobalReader.
|
|
5
|
+
*/
|
|
6
|
+
export interface GlobalReaderConfig {
|
|
7
|
+
/**
|
|
8
|
+
* The RPC Url of the ethereum host.
|
|
9
|
+
*/
|
|
10
|
+
rpcUrl: string;
|
|
11
|
+
/**
|
|
12
|
+
* The API key of the ethereum host.
|
|
13
|
+
*/
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The deployed l1 contract addresses
|
|
18
|
+
*/
|
|
19
|
+
l1Contracts: L1ContractAddresses;
|
|
20
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { AztecAddress, EthAddress, GlobalVariables } from '@aztec/circuits.js';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reads values from L1 state that is used for the global values.
|
|
7
|
+
*/
|
|
8
|
+
export interface L1GlobalReader {
|
|
9
|
+
/**
|
|
10
|
+
* Fetches the last timestamp that a block was processed by the contract.
|
|
11
|
+
* @returns The last timestamp that a block was processed by the contract.
|
|
12
|
+
*/
|
|
13
|
+
getLastTimestamp(): Promise<bigint>;
|
|
14
|
+
/**
|
|
15
|
+
* Fetches the version of the rollup contract.
|
|
16
|
+
* @returns The version of the rollup contract.
|
|
17
|
+
*/
|
|
18
|
+
getVersion(): Promise<bigint>;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the chain id.
|
|
21
|
+
* @returns The chain id.
|
|
22
|
+
*/
|
|
23
|
+
getChainId(): Promise<bigint>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the current L1 time.
|
|
27
|
+
* @returns The current L1 time.
|
|
28
|
+
*/
|
|
29
|
+
getL1CurrentTime(): Promise<bigint>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Gets the last time L2 was warped as tracked by the rollup contract.
|
|
33
|
+
* @returns The warped time.
|
|
34
|
+
*/
|
|
35
|
+
getLastWarpedBlockTs(): Promise<bigint>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Builds global variables from L1 state.
|
|
40
|
+
*/
|
|
41
|
+
export interface GlobalVariableBuilder {
|
|
42
|
+
/**
|
|
43
|
+
* Builds global variables.
|
|
44
|
+
* @param blockNumber - The block number to build global variables for.
|
|
45
|
+
* @param coinbase - The address to receive block reward.
|
|
46
|
+
* @param feeRecipient - The address to receive fees.
|
|
47
|
+
* @returns The global variables for the given block number.
|
|
48
|
+
*/
|
|
49
|
+
buildGlobalVariables(blockNumber: Fr, coinbase: EthAddress, feeRecipient: AztecAddress): Promise<GlobalVariables>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Simple test implementation of a builder that uses the minimum time possible for the global variables.
|
|
54
|
+
* Also uses a "hack" to make use of the warp cheatcode that manipulates time on Aztec.
|
|
55
|
+
*/
|
|
56
|
+
export class SimpleTestGlobalVariableBuilder implements GlobalVariableBuilder {
|
|
57
|
+
private log = createDebugLogger('aztec:sequencer:simple_test_global_variable_builder');
|
|
58
|
+
constructor(private readonly reader: L1GlobalReader) {}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Simple builder of global variables that use the minimum time possible.
|
|
62
|
+
* @param blockNumber - The block number to build global variables for.
|
|
63
|
+
* @param coinbase - The address to receive block reward.
|
|
64
|
+
* @param feeRecipient - The address to receive fees.
|
|
65
|
+
* @returns The global variables for the given block number.
|
|
66
|
+
*/
|
|
67
|
+
public async buildGlobalVariables(
|
|
68
|
+
blockNumber: Fr,
|
|
69
|
+
coinbase: EthAddress,
|
|
70
|
+
feeRecipient: AztecAddress,
|
|
71
|
+
): Promise<GlobalVariables> {
|
|
72
|
+
let lastTimestamp = new Fr(await this.reader.getLastTimestamp());
|
|
73
|
+
const version = new Fr(await this.reader.getVersion());
|
|
74
|
+
const chainId = new Fr(await this.reader.getChainId());
|
|
75
|
+
|
|
76
|
+
// TODO(rahul) - fix #1614. By using the cheatcode warp to modify L2 time,
|
|
77
|
+
// txs in the next rollup would have same time as the txs in the current rollup (i.e. the rollup that was warped).
|
|
78
|
+
// So, for now you check if L2 time was warped and if so, serve warpedTime + 1 to txs in the new rollup.
|
|
79
|
+
// Check if L2 time was warped in the last rollup by checking if current L1 time is same as the warpedTime (stored on the rollup contract).
|
|
80
|
+
// more details at https://github.com/AztecProtocol/aztec-packages/issues/1614
|
|
81
|
+
|
|
82
|
+
const currTimestamp = await this.reader.getL1CurrentTime();
|
|
83
|
+
const rollupWarpTime = await this.reader.getLastWarpedBlockTs();
|
|
84
|
+
const isLastBlockWarped = rollupWarpTime === currTimestamp;
|
|
85
|
+
if (isLastBlockWarped) {
|
|
86
|
+
lastTimestamp = new Fr(lastTimestamp.value + 1n);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.log(
|
|
90
|
+
`Built global variables for block ${blockNumber}: (${chainId}, ${version}, ${blockNumber}, ${lastTimestamp}, ${coinbase}, ${feeRecipient})`,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return new GlobalVariables(chainId, version, blockNumber, lastTimestamp, coinbase, feeRecipient);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GlobalReaderConfig } from './config.js';
|
|
2
|
+
import { GlobalVariableBuilder, SimpleTestGlobalVariableBuilder } from './global_builder.js';
|
|
3
|
+
import { ViemReader } from './viem-reader.js';
|
|
4
|
+
|
|
5
|
+
export { SimpleTestGlobalVariableBuilder as SimpleGlobalVariableBuilder } from './global_builder.js';
|
|
6
|
+
export { GlobalReaderConfig } from './config.js';
|
|
7
|
+
export { GlobalVariableBuilder } from './global_builder.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a new instance of the global variable builder.
|
|
11
|
+
* @param config - Configuration to initialize the builder.
|
|
12
|
+
* @returns A new instance of the global variable builder.
|
|
13
|
+
*/
|
|
14
|
+
export function getGlobalVariableBuilder(config: GlobalReaderConfig): GlobalVariableBuilder {
|
|
15
|
+
return new SimpleTestGlobalVariableBuilder(new ViemReader(config));
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createEthereumChain } from '@aztec/ethereum';
|
|
2
|
+
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
GetContractReturnType,
|
|
6
|
+
HttpTransport,
|
|
7
|
+
PublicClient,
|
|
8
|
+
createPublicClient,
|
|
9
|
+
getAddress,
|
|
10
|
+
getContract,
|
|
11
|
+
http,
|
|
12
|
+
} from 'viem';
|
|
13
|
+
import * as chains from 'viem/chains';
|
|
14
|
+
|
|
15
|
+
import { GlobalReaderConfig } from './config.js';
|
|
16
|
+
import { L1GlobalReader } from './global_builder.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Reads values from L1 state using viem.
|
|
20
|
+
*/
|
|
21
|
+
export class ViemReader implements L1GlobalReader {
|
|
22
|
+
private rollupContract: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;
|
|
23
|
+
private publicClient: PublicClient<HttpTransport, chains.Chain>;
|
|
24
|
+
|
|
25
|
+
constructor(config: GlobalReaderConfig) {
|
|
26
|
+
const { rpcUrl, apiKey, l1Contracts } = config;
|
|
27
|
+
|
|
28
|
+
const chain = createEthereumChain(rpcUrl, apiKey);
|
|
29
|
+
|
|
30
|
+
this.publicClient = createPublicClient({
|
|
31
|
+
chain: chain.chainInfo,
|
|
32
|
+
transport: http(chain.rpcUrl),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.rollupContract = getContract({
|
|
36
|
+
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
37
|
+
abi: RollupAbi,
|
|
38
|
+
client: this.publicClient,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async getLastTimestamp(): Promise<bigint> {
|
|
43
|
+
return BigInt(await this.rollupContract.read.lastBlockTs());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async getVersion(): Promise<bigint> {
|
|
47
|
+
return BigInt(await this.rollupContract.read.VERSION());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async getChainId(): Promise<bigint> {
|
|
51
|
+
return await Promise.resolve(BigInt(this.publicClient.chain.id));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async getL1CurrentTime(): Promise<bigint> {
|
|
55
|
+
return await Promise.resolve((await this.publicClient.getBlock()).timestamp);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async getLastWarpedBlockTs(): Promise<bigint> {
|
|
59
|
+
return BigInt(await this.rollupContract.read.lastWarpedBlockTs());
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './sequencer/index.js';
|
|
2
|
+
export * from './config.js';
|
|
3
|
+
export * from './publisher/index.js';
|
|
4
|
+
export * from './client/index.js';
|
|
5
|
+
export * from './mocks/verification_keys.js';
|
|
6
|
+
|
|
7
|
+
// Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
|
|
8
|
+
export * from './sequencer/public_processor.js';
|
|
9
|
+
export * from './global_variable_builder/index.js';
|
|
10
|
+
|
|
11
|
+
// Used by publisher test in e2e
|
|
12
|
+
export { RealRollupCircuitSimulator } from './simulator/rollup.js';
|
|
13
|
+
export { EmptyRollupProver } from './prover/empty.js';
|
|
14
|
+
export { SoloBlockBuilder } from './block_builder/solo_block_builder.js';
|
|
15
|
+
export { makeProcessedTx, makeEmptyProcessedTx } from './sequencer/processed_tx.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VerificationKey } from '@aztec/circuits.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Well-known verification keys.
|
|
5
|
+
*/
|
|
6
|
+
export interface VerificationKeys {
|
|
7
|
+
/**
|
|
8
|
+
* Verification key for the default public kernel circuit.
|
|
9
|
+
*/
|
|
10
|
+
publicKernelCircuit: VerificationKey;
|
|
11
|
+
/**
|
|
12
|
+
* Verification key for the default private kernel circuit.
|
|
13
|
+
*/
|
|
14
|
+
privateKernelCircuit: VerificationKey;
|
|
15
|
+
/**
|
|
16
|
+
* Verification key for the default base rollup circuit.
|
|
17
|
+
*/
|
|
18
|
+
baseRollupCircuit: VerificationKey;
|
|
19
|
+
/**
|
|
20
|
+
* Verification key for the default merge rollup circuit.
|
|
21
|
+
*/
|
|
22
|
+
mergeRollupCircuit: VerificationKey;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns mock verification keys for each well known circuit.
|
|
27
|
+
* @returns A VerificationKeys object with fake values.
|
|
28
|
+
*/
|
|
29
|
+
export function getVerificationKeys(): VerificationKeys {
|
|
30
|
+
return {
|
|
31
|
+
privateKernelCircuit: VerificationKey.makeFake(),
|
|
32
|
+
baseRollupCircuit: VerificationKey.makeFake(),
|
|
33
|
+
mergeRollupCircuit: VerificationKey.makeFake(),
|
|
34
|
+
publicKernelCircuit: VerificationKey.makeFake(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* eslint-disable require-await */
|
|
2
|
+
import {
|
|
3
|
+
AggregationObject,
|
|
4
|
+
BaseOrMergeRollupPublicInputs,
|
|
5
|
+
BaseRollupInputs,
|
|
6
|
+
MergeRollupInputs,
|
|
7
|
+
Proof,
|
|
8
|
+
PublicCircuitPublicInputs,
|
|
9
|
+
PublicKernelCircuitPublicInputs,
|
|
10
|
+
RootRollupInputs,
|
|
11
|
+
RootRollupPublicInputs,
|
|
12
|
+
} from '@aztec/circuits.js';
|
|
13
|
+
|
|
14
|
+
import { PublicProver, RollupProver } from './index.js';
|
|
15
|
+
|
|
16
|
+
const EMPTY_PROOF_SIZE = 42;
|
|
17
|
+
|
|
18
|
+
// TODO: Silently modifying one of the inputs to inject the aggregation object is horrible.
|
|
19
|
+
// We should rethink these interfaces.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Prover implementation that returns empty proofs and overrides aggregation objects.
|
|
23
|
+
*/
|
|
24
|
+
export class EmptyRollupProver implements RollupProver {
|
|
25
|
+
/**
|
|
26
|
+
* Creates an empty proof for the given input.
|
|
27
|
+
* @param _input - Input to the circuit.
|
|
28
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
29
|
+
*/
|
|
30
|
+
async getBaseRollupProof(_input: BaseRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise<Proof> {
|
|
31
|
+
publicInputs.aggregationObject = AggregationObject.makeFake();
|
|
32
|
+
return new Proof(Buffer.alloc(EMPTY_PROOF_SIZE, 0));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates an empty proof for the given input.
|
|
37
|
+
* @param _input - Input to the circuit.
|
|
38
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
39
|
+
*/
|
|
40
|
+
async getMergeRollupProof(_input: MergeRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise<Proof> {
|
|
41
|
+
publicInputs.aggregationObject = AggregationObject.makeFake();
|
|
42
|
+
return new Proof(Buffer.alloc(EMPTY_PROOF_SIZE, 0));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates an empty proof for the given input.
|
|
46
|
+
* @param _input - Input to the circuit.
|
|
47
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
48
|
+
*/
|
|
49
|
+
async getRootRollupProof(_input: RootRollupInputs, publicInputs: RootRollupPublicInputs): Promise<Proof> {
|
|
50
|
+
publicInputs.aggregationObject = AggregationObject.makeFake();
|
|
51
|
+
return new Proof(Buffer.alloc(EMPTY_PROOF_SIZE, 0));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Prover implementation that returns empty proofs.
|
|
57
|
+
*/
|
|
58
|
+
export class EmptyPublicProver implements PublicProver {
|
|
59
|
+
/**
|
|
60
|
+
* Creates an empty proof for the given input.
|
|
61
|
+
* @param _publicInputs - Public inputs obtained via simulation.
|
|
62
|
+
*/
|
|
63
|
+
async getPublicCircuitProof(_publicInputs: PublicCircuitPublicInputs): Promise<Proof> {
|
|
64
|
+
return new Proof(Buffer.alloc(EMPTY_PROOF_SIZE, 0));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Creates an empty proof for the given input.
|
|
69
|
+
* @param _publicInputs - Public inputs obtained via simulation.
|
|
70
|
+
*/
|
|
71
|
+
async getPublicKernelCircuitProof(_publicInputs: PublicKernelCircuitPublicInputs): Promise<Proof> {
|
|
72
|
+
return new Proof(Buffer.alloc(EMPTY_PROOF_SIZE, 0));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseOrMergeRollupPublicInputs,
|
|
3
|
+
BaseRollupInputs,
|
|
4
|
+
MergeRollupInputs,
|
|
5
|
+
Proof,
|
|
6
|
+
PublicCircuitPublicInputs,
|
|
7
|
+
PublicKernelCircuitPublicInputs,
|
|
8
|
+
RootRollupInputs,
|
|
9
|
+
RootRollupPublicInputs,
|
|
10
|
+
} from '@aztec/circuits.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates proofs for the base, merge, and root rollup circuits.
|
|
14
|
+
*/
|
|
15
|
+
export interface RollupProver {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a proof for the given input.
|
|
18
|
+
* @param input - Input to the circuit.
|
|
19
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
20
|
+
*/
|
|
21
|
+
getBaseRollupProof(input: BaseRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise<Proof>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a proof for the given input.
|
|
25
|
+
* @param input - Input to the circuit.
|
|
26
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
27
|
+
*/
|
|
28
|
+
getMergeRollupProof(input: MergeRollupInputs, publicInputs: BaseOrMergeRollupPublicInputs): Promise<Proof>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a proof for the given input.
|
|
32
|
+
* @param input - Input to the circuit.
|
|
33
|
+
* @param publicInputs - Public inputs of the circuit obtained via simulation, modified by this call.
|
|
34
|
+
*/
|
|
35
|
+
getRootRollupProof(input: RootRollupInputs, publicInputs: RootRollupPublicInputs): Promise<Proof>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generates proofs for the public and public kernel circuits.
|
|
40
|
+
*/
|
|
41
|
+
export interface PublicProver {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a proof for the given input.
|
|
44
|
+
* @param publicInputs - Public inputs obtained via simulation.
|
|
45
|
+
*/
|
|
46
|
+
getPublicCircuitProof(publicInputs: PublicCircuitPublicInputs): Promise<Proof>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a proof for the given input.
|
|
50
|
+
* @param publicInputs - Public inputs obtained via simulation.
|
|
51
|
+
*/
|
|
52
|
+
getPublicKernelCircuitProof(publicInputs: PublicKernelCircuitPublicInputs): Promise<Proof>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { L1ContractAddresses } from '@aztec/ethereum';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The configuration of the rollup transaction publisher.
|
|
5
|
+
*/
|
|
6
|
+
export interface TxSenderConfig {
|
|
7
|
+
/**
|
|
8
|
+
* The private key to be used by the publisher.
|
|
9
|
+
*/
|
|
10
|
+
publisherPrivateKey: `0x${string}`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The RPC Url of the ethereum host.
|
|
14
|
+
*/
|
|
15
|
+
rpcUrl: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The API key of the ethereum host.
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The number of confirmations required.
|
|
24
|
+
*/
|
|
25
|
+
requiredConfirmations: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The deployed l1 contract addresses
|
|
29
|
+
*/
|
|
30
|
+
l1Contracts: L1ContractAddresses;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration of the L1Publisher.
|
|
35
|
+
*/
|
|
36
|
+
export interface PublisherConfig {
|
|
37
|
+
/**
|
|
38
|
+
* The interval to wait between publish retries.
|
|
39
|
+
*/
|
|
40
|
+
l1BlockPublishRetryIntervalMS: number;
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PublisherConfig, TxSenderConfig } from './config.js';
|
|
2
|
+
import { L1Publisher } from './l1-publisher.js';
|
|
3
|
+
import { ViemTxSender } from './viem-tx-sender.js';
|
|
4
|
+
|
|
5
|
+
export { L1Publisher } from './l1-publisher.js';
|
|
6
|
+
export { PublisherConfig } from './config.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a new instance of the L1Publisher.
|
|
10
|
+
* @param config - Configuration to initialize the new instance.
|
|
11
|
+
*/
|
|
12
|
+
export function getL1Publisher(config: PublisherConfig & TxSenderConfig): L1Publisher {
|
|
13
|
+
return new L1Publisher(new ViemTxSender(config), config);
|
|
14
|
+
}
|