@aztec/sequencer-client 0.48.0 → 0.50.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/index.d.ts +26 -0
- package/dest/block_builder/index.d.ts.map +1 -0
- package/dest/block_builder/index.js +40 -0
- package/dest/client/sequencer-client.d.ts +6 -2
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +14 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -6
- package/dest/global_variable_builder/global_builder.d.ts +6 -54
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +24 -12
- package/dest/global_variable_builder/index.d.ts +0 -9
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -12
- package/dest/publisher/index.d.ts +0 -8
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +1 -10
- package/dest/publisher/l1-publisher.d.ts +26 -70
- package/dest/publisher/l1-publisher.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.js +168 -19
- package/dest/sequencer/sequencer.d.ts +25 -11
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +90 -36
- package/package.json +18 -15
- package/src/block_builder/index.ts +51 -0
- package/src/client/sequencer-client.ts +15 -7
- package/src/config.ts +0 -5
- package/src/global_variable_builder/global_builder.ts +38 -62
- package/src/global_variable_builder/index.ts +0 -15
- package/src/publisher/index.ts +0 -14
- package/src/publisher/l1-publisher.ts +217 -95
- package/src/sequencer/sequencer.ts +113 -45
- package/dest/global_variable_builder/viem-reader.d.ts +0 -17
- package/dest/global_variable_builder/viem-reader.d.ts.map +0 -1
- package/dest/global_variable_builder/viem-reader.js +0 -40
- package/dest/publisher/viem-tx-sender.d.ts +0 -59
- package/dest/publisher/viem-tx-sender.d.ts.map +0 -1
- package/dest/publisher/viem-tx-sender.js +0 -236
- package/dest/receiver.d.ts +0 -10
- package/dest/receiver.d.ts.map +0 -1
- package/dest/receiver.js +0 -2
- package/src/global_variable_builder/viem-reader.ts +0 -64
- package/src/publisher/viem-tx-sender.ts +0 -296
- package/src/receiver.ts +0 -11
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { ETHEREUM_SLOT_DURATION, EthAddress } from '@aztec/circuits.js';
|
|
2
|
-
import { createEthereumChain } from '@aztec/ethereum';
|
|
3
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { AvailabilityOracleAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
5
|
-
import { createPublicClient, createWalletClient, getAddress, getContract, hexToBytes, http, parseSignature, } from 'viem';
|
|
6
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
7
|
-
import * as chains from 'viem/chains';
|
|
8
|
-
/**
|
|
9
|
-
* Pushes transactions to the L1 rollup contract using viem.
|
|
10
|
-
*/
|
|
11
|
-
export class ViemTxSender {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.log = createDebugLogger('aztec:sequencer:viem-tx-sender');
|
|
14
|
-
const { l1RpcUrl: rpcUrl, l1ChainId: chainId, publisherPrivateKey, l1Contracts } = config;
|
|
15
|
-
const chain = createEthereumChain(rpcUrl, chainId);
|
|
16
|
-
this.account = privateKeyToAccount(publisherPrivateKey);
|
|
17
|
-
const walletClient = createWalletClient({
|
|
18
|
-
account: this.account,
|
|
19
|
-
chain: chain.chainInfo,
|
|
20
|
-
transport: http(chain.rpcUrl),
|
|
21
|
-
});
|
|
22
|
-
this.publicClient = createPublicClient({
|
|
23
|
-
chain: chain.chainInfo,
|
|
24
|
-
transport: http(chain.rpcUrl),
|
|
25
|
-
});
|
|
26
|
-
this.availabilityOracleContract = getContract({
|
|
27
|
-
address: getAddress(l1Contracts.availabilityOracleAddress.toString()),
|
|
28
|
-
abi: AvailabilityOracleAbi,
|
|
29
|
-
client: walletClient,
|
|
30
|
-
});
|
|
31
|
-
this.rollupContract = getContract({
|
|
32
|
-
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
33
|
-
abi: RollupAbi,
|
|
34
|
-
client: walletClient,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
async attest(archive) {
|
|
38
|
-
// @note Something seems slightly off in viem, think it should be Hex instead of Hash
|
|
39
|
-
// but as they both are just `0x${string}` it should be fine anyways.
|
|
40
|
-
const signature = await this.account.signMessage({ message: { raw: archive } });
|
|
41
|
-
const { r, s, v } = parseSignature(signature);
|
|
42
|
-
return {
|
|
43
|
-
isEmpty: false,
|
|
44
|
-
v: v ? Number(v) : 0,
|
|
45
|
-
r: r,
|
|
46
|
-
s: s,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
getSenderAddress() {
|
|
50
|
-
return Promise.resolve(EthAddress.fromString(this.account.address));
|
|
51
|
-
}
|
|
52
|
-
// Computes who will be the L2 proposer at the next Ethereum block
|
|
53
|
-
// Using next Ethereum block so we do NOT need to wait for it being mined before seeing the effect
|
|
54
|
-
// @note Assumes that all ethereum slots have blocks
|
|
55
|
-
async getProposerAtNextEthBlock() {
|
|
56
|
-
try {
|
|
57
|
-
const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION));
|
|
58
|
-
const submitter = await this.rollupContract.read.getProposerAt([ts]);
|
|
59
|
-
return EthAddress.fromString(submitter);
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
this.log.warn(`Failed to get submitter: ${err}`);
|
|
63
|
-
return EthAddress.ZERO;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async getCurrentArchive() {
|
|
67
|
-
const archive = await this.rollupContract.read.archive();
|
|
68
|
-
return Buffer.from(archive.replace('0x', ''), 'hex');
|
|
69
|
-
}
|
|
70
|
-
checkIfTxsAreAvailable(block) {
|
|
71
|
-
const args = [`0x${block.body.getTxsEffectsHash().toString('hex').padStart(64, '0')}`];
|
|
72
|
-
return this.availabilityOracleContract.read.isAvailable(args);
|
|
73
|
-
}
|
|
74
|
-
async getTransactionStats(txHash) {
|
|
75
|
-
const tx = await this.publicClient.getTransaction({ hash: txHash });
|
|
76
|
-
if (!tx) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
const calldata = hexToBytes(tx.input);
|
|
80
|
-
return {
|
|
81
|
-
transactionHash: tx.hash,
|
|
82
|
-
calldataSize: calldata.length,
|
|
83
|
-
calldataGas: getCalldataGasUsage(calldata),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns a tx receipt if the tx has been mined.
|
|
88
|
-
* @param txHash - Hash of the tx to look for.
|
|
89
|
-
* @returns Undefined if the tx hasn't been mined yet, the receipt otherwise.
|
|
90
|
-
*/
|
|
91
|
-
async getTransactionReceipt(txHash) {
|
|
92
|
-
const receipt = await this.publicClient.getTransactionReceipt({
|
|
93
|
-
hash: txHash,
|
|
94
|
-
});
|
|
95
|
-
if (receipt) {
|
|
96
|
-
return {
|
|
97
|
-
status: receipt.status === 'success',
|
|
98
|
-
transactionHash: txHash,
|
|
99
|
-
gasUsed: receipt.gasUsed,
|
|
100
|
-
gasPrice: receipt.effectiveGasPrice,
|
|
101
|
-
logs: receipt.logs,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
this.log.debug(`Receipt not found for tx hash ${txHash}`);
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Publishes tx effects to Availability Oracle.
|
|
109
|
-
* @param encodedBody - Encoded block body.
|
|
110
|
-
* @returns The hash of the mined tx.
|
|
111
|
-
*/
|
|
112
|
-
async sendPublishTx(encodedBody) {
|
|
113
|
-
const args = [`0x${encodedBody.toString('hex')}`];
|
|
114
|
-
const gas = await this.availabilityOracleContract.estimateGas.publish(args, {
|
|
115
|
-
account: this.account,
|
|
116
|
-
});
|
|
117
|
-
const hash = await this.availabilityOracleContract.write.publish(args, {
|
|
118
|
-
gas,
|
|
119
|
-
account: this.account,
|
|
120
|
-
});
|
|
121
|
-
return hash;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Sends a tx to the L1 rollup contract with a new L2 block. Returns once the tx has been mined.
|
|
125
|
-
* @param encodedData - Serialized data for processing the new L2 block.
|
|
126
|
-
* @returns The hash of the mined tx.
|
|
127
|
-
*/
|
|
128
|
-
async sendProcessTx(encodedData) {
|
|
129
|
-
if (encodedData.attestations) {
|
|
130
|
-
const args = [
|
|
131
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
132
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
133
|
-
encodedData.attestations,
|
|
134
|
-
];
|
|
135
|
-
const gas = await this.rollupContract.estimateGas.process(args, {
|
|
136
|
-
account: this.account,
|
|
137
|
-
});
|
|
138
|
-
return await this.rollupContract.write.process(args, {
|
|
139
|
-
gas,
|
|
140
|
-
account: this.account,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const args = [`0x${encodedData.header.toString('hex')}`, `0x${encodedData.archive.toString('hex')}`];
|
|
145
|
-
const gas = await this.rollupContract.estimateGas.process(args, {
|
|
146
|
-
account: this.account,
|
|
147
|
-
});
|
|
148
|
-
return await this.rollupContract.write.process(args, {
|
|
149
|
-
gas,
|
|
150
|
-
account: this.account,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @notice Publishes the body AND process the block in one transaction
|
|
156
|
-
* @param encodedData - Serialized data for processing the new L2 block.
|
|
157
|
-
* @returns The hash of the transaction
|
|
158
|
-
*/
|
|
159
|
-
async sendPublishAndProcessTx(encodedData) {
|
|
160
|
-
// @note This is quite a sin, but I'm committing war crimes in this code already.
|
|
161
|
-
if (encodedData.attestations) {
|
|
162
|
-
const args = [
|
|
163
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
164
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
165
|
-
encodedData.attestations,
|
|
166
|
-
`0x${encodedData.body.toString('hex')}`,
|
|
167
|
-
];
|
|
168
|
-
const gas = await this.rollupContract.estimateGas.publishAndProcess(args, {
|
|
169
|
-
account: this.account,
|
|
170
|
-
});
|
|
171
|
-
return await this.rollupContract.write.publishAndProcess(args, {
|
|
172
|
-
gas,
|
|
173
|
-
account: this.account,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
const args = [
|
|
178
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
179
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
180
|
-
`0x${encodedData.body.toString('hex')}`,
|
|
181
|
-
];
|
|
182
|
-
const gas = await this.rollupContract.estimateGas.publishAndProcess(args, {
|
|
183
|
-
account: this.account,
|
|
184
|
-
});
|
|
185
|
-
return await this.rollupContract.write.publishAndProcess(args, {
|
|
186
|
-
gas,
|
|
187
|
-
account: this.account,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Sends a tx to the L1 rollup contract with a proof. Returns once the tx has been mined.
|
|
193
|
-
* @param encodedData - Serialized data for the proof.
|
|
194
|
-
* @returns The hash of the mined tx.
|
|
195
|
-
*/
|
|
196
|
-
async sendSubmitProofTx(submitProofArgs) {
|
|
197
|
-
const { header, archive, proverId, aggregationObject, proof } = submitProofArgs;
|
|
198
|
-
const args = [
|
|
199
|
-
`0x${header.toString('hex')}`,
|
|
200
|
-
`0x${archive.toString('hex')}`,
|
|
201
|
-
`0x${proverId.toString('hex')}`,
|
|
202
|
-
`0x${aggregationObject.toString('hex')}`,
|
|
203
|
-
`0x${proof.toString('hex')}`,
|
|
204
|
-
];
|
|
205
|
-
const gas = await this.rollupContract.estimateGas.submitProof(args, {
|
|
206
|
-
account: this.account,
|
|
207
|
-
});
|
|
208
|
-
const hash = await this.rollupContract.write.submitProof(args, {
|
|
209
|
-
gas,
|
|
210
|
-
account: this.account,
|
|
211
|
-
});
|
|
212
|
-
return hash;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Gets the chain object for the given chain id.
|
|
216
|
-
* @param chainId - Chain id of the target EVM chain.
|
|
217
|
-
* @returns Viem's chain object.
|
|
218
|
-
*/
|
|
219
|
-
getChain(chainId) {
|
|
220
|
-
for (const chain of Object.values(chains)) {
|
|
221
|
-
if ('id' in chain && chain.id === chainId) {
|
|
222
|
-
return chain;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
throw new Error(`Chain with id ${chainId} not found`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Returns cost of calldata usage in Ethereum.
|
|
230
|
-
* @param data - Calldata.
|
|
231
|
-
* @returns 4 for each zero byte, 16 for each nonzero.
|
|
232
|
-
*/
|
|
233
|
-
function getCalldataGasUsage(data) {
|
|
234
|
-
return data.filter(byte => byte === 0).length * 4 + data.filter(byte => byte !== 0).length * 16;
|
|
235
|
-
}
|
|
236
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmllbS10eC1zZW5kZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGlzaGVyL3ZpZW0tdHgtc2VuZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxzQkFBc0IsRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN4RSxPQUFPLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUN0RCxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUMxRCxPQUFPLEVBQUUscUJBQXFCLEVBQUUsU0FBUyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFdkUsT0FBTyxFQU1MLGtCQUFrQixFQUNsQixrQkFBa0IsRUFDbEIsVUFBVSxFQUNWLFd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UFDLFdBQVcsQ0FBQyxJQUFJLEVBQUU7WUFDN0QsR0FBRztZQUNILE9BQU8sRUFBRSxJQUFJLENBQUMsT0FBTztTQUN0QixDQUFDLENBQUM7UUFFSCxPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ssUUFBUSxDQUFDLE9BQWU7UUFDOUIsS0FBSyxNQUFNLEtBQUssSUFBSSxNQUFNLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUM7WUFDMUMsSUFBSSxJQUFJLElBQUksS0FBSyxJQUFJLEtBQUssQ0FBQyxFQUFFLEtBQUssT0FBTyxFQUFFLENBQUM7Z0JBQzFDLE9BQU8sS0FBSyxDQUFDO1lBQ2YsQ0FBQztRQUNILENBQUM7UUFFRCxNQUFNLElBQUksS0FBSyxDQUFDLGlCQUFpQixPQUFPLFlBQVksQ0FBQyxDQUFDO0lBQ3hELENBQUM7Q0FDRjtBQUVEOzs7O0dBSUc7QUFDSCxTQUFTLG1CQUFtQixDQUFDLElBQWdCO0lBQzNDLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsRUFBRSxDQUFDLElBQUksS0FBSyxDQUFDLENBQUMsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxHQUFHLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxJQUFJLEtBQUssQ0FBQyxDQUFDLENBQUMsTUFBTSxHQUFHLEVBQUUsQ0FBQztBQUNsRyxDQUFDIn0=
|
package/dest/receiver.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type L2Block } from '@aztec/circuit-types';
|
|
2
|
-
import { type Attestation } from './publisher/l1-publisher.js';
|
|
3
|
-
/**
|
|
4
|
-
* Given the necessary rollup data, verifies it, and updates the underlying state accordingly to advance the state of the system.
|
|
5
|
-
* See https://hackmd.io/ouVCnacHQRq2o1oRc5ksNA#RollupReceiver.
|
|
6
|
-
*/
|
|
7
|
-
export interface L2BlockReceiver {
|
|
8
|
-
processL2Block(block: L2Block, attestations?: Attestation[]): Promise<boolean>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=receiver.d.ts.map
|
package/dest/receiver.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"receiver.d.ts","sourceRoot":"","sources":["../src/receiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChF"}
|
package/dest/receiver.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { type L1ReaderConfig, createEthereumChain } from '@aztec/ethereum';
|
|
2
|
-
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
type GetContractReturnType,
|
|
6
|
-
type HttpTransport,
|
|
7
|
-
type PublicClient,
|
|
8
|
-
createPublicClient,
|
|
9
|
-
getAddress,
|
|
10
|
-
getContract,
|
|
11
|
-
http,
|
|
12
|
-
} from 'viem';
|
|
13
|
-
import type * as chains from 'viem/chains';
|
|
14
|
-
|
|
15
|
-
import { type L1GlobalReader } from './global_builder.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Reads values from L1 state using viem.
|
|
19
|
-
*/
|
|
20
|
-
export class ViemReader implements L1GlobalReader {
|
|
21
|
-
private rollupContract: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;
|
|
22
|
-
private publicClient: PublicClient<HttpTransport, chains.Chain>;
|
|
23
|
-
|
|
24
|
-
constructor(config: L1ReaderConfig) {
|
|
25
|
-
const { l1RpcUrl, l1ChainId: chainId, l1Contracts } = config;
|
|
26
|
-
|
|
27
|
-
const chain = createEthereumChain(l1RpcUrl, chainId);
|
|
28
|
-
|
|
29
|
-
this.publicClient = createPublicClient({
|
|
30
|
-
chain: chain.chainInfo,
|
|
31
|
-
transport: http(chain.rpcUrl),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this.rollupContract = getContract({
|
|
35
|
-
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
36
|
-
abi: RollupAbi,
|
|
37
|
-
client: this.publicClient,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public async getVersion(): Promise<bigint> {
|
|
42
|
-
return BigInt(await this.rollupContract.read.VERSION());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public async getChainId(): Promise<bigint> {
|
|
46
|
-
return await Promise.resolve(BigInt(this.publicClient.chain.id));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public async getL1CurrentTime(): Promise<bigint> {
|
|
50
|
-
return await Promise.resolve((await this.publicClient.getBlock()).timestamp);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public async getCurrentSlot(): Promise<bigint> {
|
|
54
|
-
return BigInt(await this.rollupContract.read.getCurrentSlot());
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public async getSlotAt(timestamp: readonly [bigint]): Promise<bigint> {
|
|
58
|
-
return BigInt(await this.rollupContract.read.getSlotAt(timestamp));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public async getTimestampForSlot(slot: readonly [bigint]): Promise<bigint> {
|
|
62
|
-
return BigInt(await this.rollupContract.read.getTimestampForSlot(slot));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { type L2Block } from '@aztec/circuit-types';
|
|
2
|
-
import { ETHEREUM_SLOT_DURATION, EthAddress } from '@aztec/circuits.js';
|
|
3
|
-
import { createEthereumChain } from '@aztec/ethereum';
|
|
4
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
import { AvailabilityOracleAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
type GetContractReturnType,
|
|
9
|
-
type Hex,
|
|
10
|
-
type HttpTransport,
|
|
11
|
-
type PublicClient,
|
|
12
|
-
type WalletClient,
|
|
13
|
-
createPublicClient,
|
|
14
|
-
createWalletClient,
|
|
15
|
-
getAddress,
|
|
16
|
-
getContract,
|
|
17
|
-
hexToBytes,
|
|
18
|
-
http,
|
|
19
|
-
parseSignature,
|
|
20
|
-
} from 'viem';
|
|
21
|
-
import { type PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts';
|
|
22
|
-
import * as chains from 'viem/chains';
|
|
23
|
-
|
|
24
|
-
import { type TxSenderConfig } from './config.js';
|
|
25
|
-
import {
|
|
26
|
-
type Attestation,
|
|
27
|
-
type L1PublisherTxSender,
|
|
28
|
-
type L1SubmitProofArgs,
|
|
29
|
-
type MinimalTransactionReceipt,
|
|
30
|
-
type L1ProcessArgs as ProcessTxArgs,
|
|
31
|
-
type TransactionStats,
|
|
32
|
-
} from './l1-publisher.js';
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Pushes transactions to the L1 rollup contract using viem.
|
|
36
|
-
*/
|
|
37
|
-
export class ViemTxSender implements L1PublisherTxSender {
|
|
38
|
-
private availabilityOracleContract: GetContractReturnType<
|
|
39
|
-
typeof AvailabilityOracleAbi,
|
|
40
|
-
WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
|
|
41
|
-
>;
|
|
42
|
-
private rollupContract: GetContractReturnType<
|
|
43
|
-
typeof RollupAbi,
|
|
44
|
-
WalletClient<HttpTransport, chains.Chain, PrivateKeyAccount>
|
|
45
|
-
>;
|
|
46
|
-
|
|
47
|
-
private log = createDebugLogger('aztec:sequencer:viem-tx-sender');
|
|
48
|
-
private publicClient: PublicClient<HttpTransport, chains.Chain>;
|
|
49
|
-
private account: PrivateKeyAccount;
|
|
50
|
-
|
|
51
|
-
constructor(config: TxSenderConfig) {
|
|
52
|
-
const { l1RpcUrl: rpcUrl, l1ChainId: chainId, publisherPrivateKey, l1Contracts } = config;
|
|
53
|
-
const chain = createEthereumChain(rpcUrl, chainId);
|
|
54
|
-
this.account = privateKeyToAccount(publisherPrivateKey);
|
|
55
|
-
const walletClient = createWalletClient({
|
|
56
|
-
account: this.account,
|
|
57
|
-
chain: chain.chainInfo,
|
|
58
|
-
transport: http(chain.rpcUrl),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.publicClient = createPublicClient({
|
|
62
|
-
chain: chain.chainInfo,
|
|
63
|
-
transport: http(chain.rpcUrl),
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this.availabilityOracleContract = getContract({
|
|
67
|
-
address: getAddress(l1Contracts.availabilityOracleAddress.toString()),
|
|
68
|
-
abi: AvailabilityOracleAbi,
|
|
69
|
-
client: walletClient,
|
|
70
|
-
});
|
|
71
|
-
this.rollupContract = getContract({
|
|
72
|
-
address: getAddress(l1Contracts.rollupAddress.toString()),
|
|
73
|
-
abi: RollupAbi,
|
|
74
|
-
client: walletClient,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async attest(archive: `0x{string}`): Promise<Attestation> {
|
|
79
|
-
// @note Something seems slightly off in viem, think it should be Hex instead of Hash
|
|
80
|
-
// but as they both are just `0x${string}` it should be fine anyways.
|
|
81
|
-
const signature = await this.account.signMessage({ message: { raw: archive } });
|
|
82
|
-
const { r, s, v } = parseSignature(signature as `0x${string}`);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
isEmpty: false,
|
|
86
|
-
v: v ? Number(v) : 0,
|
|
87
|
-
r: r,
|
|
88
|
-
s: s,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getSenderAddress(): Promise<EthAddress> {
|
|
93
|
-
return Promise.resolve(EthAddress.fromString(this.account.address));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Computes who will be the L2 proposer at the next Ethereum block
|
|
97
|
-
// Using next Ethereum block so we do NOT need to wait for it being mined before seeing the effect
|
|
98
|
-
// @note Assumes that all ethereum slots have blocks
|
|
99
|
-
async getProposerAtNextEthBlock(): Promise<EthAddress> {
|
|
100
|
-
try {
|
|
101
|
-
const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION));
|
|
102
|
-
const submitter = await this.rollupContract.read.getProposerAt([ts]);
|
|
103
|
-
return EthAddress.fromString(submitter);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
this.log.warn(`Failed to get submitter: ${err}`);
|
|
106
|
-
return EthAddress.ZERO;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async getCurrentArchive(): Promise<Buffer> {
|
|
111
|
-
const archive = await this.rollupContract.read.archive();
|
|
112
|
-
return Buffer.from(archive.replace('0x', ''), 'hex');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
checkIfTxsAreAvailable(block: L2Block): Promise<boolean> {
|
|
116
|
-
const args = [`0x${block.body.getTxsEffectsHash().toString('hex').padStart(64, '0')}`] as const;
|
|
117
|
-
return this.availabilityOracleContract.read.isAvailable(args);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async getTransactionStats(txHash: string): Promise<TransactionStats | undefined> {
|
|
121
|
-
const tx = await this.publicClient.getTransaction({ hash: txHash as Hex });
|
|
122
|
-
if (!tx) {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
const calldata = hexToBytes(tx.input);
|
|
126
|
-
return {
|
|
127
|
-
transactionHash: tx.hash,
|
|
128
|
-
calldataSize: calldata.length,
|
|
129
|
-
calldataGas: getCalldataGasUsage(calldata),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Returns a tx receipt if the tx has been mined.
|
|
135
|
-
* @param txHash - Hash of the tx to look for.
|
|
136
|
-
* @returns Undefined if the tx hasn't been mined yet, the receipt otherwise.
|
|
137
|
-
*/
|
|
138
|
-
async getTransactionReceipt(txHash: string): Promise<MinimalTransactionReceipt | undefined> {
|
|
139
|
-
const receipt = await this.publicClient.getTransactionReceipt({
|
|
140
|
-
hash: txHash as Hex,
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
if (receipt) {
|
|
144
|
-
return {
|
|
145
|
-
status: receipt.status === 'success',
|
|
146
|
-
transactionHash: txHash,
|
|
147
|
-
gasUsed: receipt.gasUsed,
|
|
148
|
-
gasPrice: receipt.effectiveGasPrice,
|
|
149
|
-
logs: receipt.logs,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
this.log.debug(`Receipt not found for tx hash ${txHash}`);
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Publishes tx effects to Availability Oracle.
|
|
159
|
-
* @param encodedBody - Encoded block body.
|
|
160
|
-
* @returns The hash of the mined tx.
|
|
161
|
-
*/
|
|
162
|
-
async sendPublishTx(encodedBody: Buffer): Promise<string | undefined> {
|
|
163
|
-
const args = [`0x${encodedBody.toString('hex')}`] as const;
|
|
164
|
-
|
|
165
|
-
const gas = await this.availabilityOracleContract.estimateGas.publish(args, {
|
|
166
|
-
account: this.account,
|
|
167
|
-
});
|
|
168
|
-
const hash = await this.availabilityOracleContract.write.publish(args, {
|
|
169
|
-
gas,
|
|
170
|
-
account: this.account,
|
|
171
|
-
});
|
|
172
|
-
return hash;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Sends a tx to the L1 rollup contract with a new L2 block. Returns once the tx has been mined.
|
|
177
|
-
* @param encodedData - Serialized data for processing the new L2 block.
|
|
178
|
-
* @returns The hash of the mined tx.
|
|
179
|
-
*/
|
|
180
|
-
async sendProcessTx(encodedData: ProcessTxArgs): Promise<string | undefined> {
|
|
181
|
-
if (encodedData.attestations) {
|
|
182
|
-
const args = [
|
|
183
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
184
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
185
|
-
encodedData.attestations,
|
|
186
|
-
] as const;
|
|
187
|
-
|
|
188
|
-
const gas = await this.rollupContract.estimateGas.process(args, {
|
|
189
|
-
account: this.account,
|
|
190
|
-
});
|
|
191
|
-
return await this.rollupContract.write.process(args, {
|
|
192
|
-
gas,
|
|
193
|
-
account: this.account,
|
|
194
|
-
});
|
|
195
|
-
} else {
|
|
196
|
-
const args = [`0x${encodedData.header.toString('hex')}`, `0x${encodedData.archive.toString('hex')}`] as const;
|
|
197
|
-
|
|
198
|
-
const gas = await this.rollupContract.estimateGas.process(args, {
|
|
199
|
-
account: this.account,
|
|
200
|
-
});
|
|
201
|
-
return await this.rollupContract.write.process(args, {
|
|
202
|
-
gas,
|
|
203
|
-
account: this.account,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @notice Publishes the body AND process the block in one transaction
|
|
210
|
-
* @param encodedData - Serialized data for processing the new L2 block.
|
|
211
|
-
* @returns The hash of the transaction
|
|
212
|
-
*/
|
|
213
|
-
async sendPublishAndProcessTx(encodedData: ProcessTxArgs): Promise<string | undefined> {
|
|
214
|
-
// @note This is quite a sin, but I'm committing war crimes in this code already.
|
|
215
|
-
if (encodedData.attestations) {
|
|
216
|
-
const args = [
|
|
217
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
218
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
219
|
-
encodedData.attestations,
|
|
220
|
-
`0x${encodedData.body.toString('hex')}`,
|
|
221
|
-
] as const;
|
|
222
|
-
|
|
223
|
-
const gas = await this.rollupContract.estimateGas.publishAndProcess(args, {
|
|
224
|
-
account: this.account,
|
|
225
|
-
});
|
|
226
|
-
return await this.rollupContract.write.publishAndProcess(args, {
|
|
227
|
-
gas,
|
|
228
|
-
account: this.account,
|
|
229
|
-
});
|
|
230
|
-
} else {
|
|
231
|
-
const args = [
|
|
232
|
-
`0x${encodedData.header.toString('hex')}`,
|
|
233
|
-
`0x${encodedData.archive.toString('hex')}`,
|
|
234
|
-
`0x${encodedData.body.toString('hex')}`,
|
|
235
|
-
] as const;
|
|
236
|
-
|
|
237
|
-
const gas = await this.rollupContract.estimateGas.publishAndProcess(args, {
|
|
238
|
-
account: this.account,
|
|
239
|
-
});
|
|
240
|
-
return await this.rollupContract.write.publishAndProcess(args, {
|
|
241
|
-
gas,
|
|
242
|
-
account: this.account,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Sends a tx to the L1 rollup contract with a proof. Returns once the tx has been mined.
|
|
249
|
-
* @param encodedData - Serialized data for the proof.
|
|
250
|
-
* @returns The hash of the mined tx.
|
|
251
|
-
*/
|
|
252
|
-
async sendSubmitProofTx(submitProofArgs: L1SubmitProofArgs): Promise<string | undefined> {
|
|
253
|
-
const { header, archive, proverId, aggregationObject, proof } = submitProofArgs;
|
|
254
|
-
const args = [
|
|
255
|
-
`0x${header.toString('hex')}`,
|
|
256
|
-
`0x${archive.toString('hex')}`,
|
|
257
|
-
`0x${proverId.toString('hex')}`,
|
|
258
|
-
`0x${aggregationObject.toString('hex')}`,
|
|
259
|
-
`0x${proof.toString('hex')}`,
|
|
260
|
-
] as const;
|
|
261
|
-
|
|
262
|
-
const gas = await this.rollupContract.estimateGas.submitProof(args, {
|
|
263
|
-
account: this.account,
|
|
264
|
-
});
|
|
265
|
-
const hash = await this.rollupContract.write.submitProof(args, {
|
|
266
|
-
gas,
|
|
267
|
-
account: this.account,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
return hash;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Gets the chain object for the given chain id.
|
|
275
|
-
* @param chainId - Chain id of the target EVM chain.
|
|
276
|
-
* @returns Viem's chain object.
|
|
277
|
-
*/
|
|
278
|
-
private getChain(chainId: number) {
|
|
279
|
-
for (const chain of Object.values(chains)) {
|
|
280
|
-
if ('id' in chain && chain.id === chainId) {
|
|
281
|
-
return chain;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
throw new Error(`Chain with id ${chainId} not found`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Returns cost of calldata usage in Ethereum.
|
|
291
|
-
* @param data - Calldata.
|
|
292
|
-
* @returns 4 for each zero byte, 16 for each nonzero.
|
|
293
|
-
*/
|
|
294
|
-
function getCalldataGasUsage(data: Uint8Array) {
|
|
295
|
-
return data.filter(byte => byte === 0).length * 4 + data.filter(byte => byte !== 0).length * 16;
|
|
296
|
-
}
|
package/src/receiver.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type L2Block } from '@aztec/circuit-types';
|
|
2
|
-
|
|
3
|
-
import { type Attestation } from './publisher/l1-publisher.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Given the necessary rollup data, verifies it, and updates the underlying state accordingly to advance the state of the system.
|
|
7
|
-
* See https://hackmd.io/ouVCnacHQRq2o1oRc5ksNA#RollupReceiver.
|
|
8
|
-
*/
|
|
9
|
-
export interface L2BlockReceiver {
|
|
10
|
-
processL2Block(block: L2Block, attestations?: Attestation[]): Promise<boolean>;
|
|
11
|
-
}
|