@aztec/txe 0.86.0 → 0.87.0
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/oracle/txe_oracle.d.ts +11 -6
- package/dest/oracle/txe_oracle.d.ts.map +1 -1
- package/dest/oracle/txe_oracle.js +209 -38
- package/dest/state_machine/archiver.d.ts +53 -0
- package/dest/state_machine/archiver.d.ts.map +1 -0
- package/dest/state_machine/archiver.js +100 -0
- package/dest/state_machine/dummy_p2p_client.d.ts +48 -0
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
- package/dest/state_machine/dummy_p2p_client.js +122 -0
- package/dest/state_machine/global_variable_builder.d.ts +23 -0
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
- package/dest/state_machine/global_variable_builder.js +29 -0
- package/dest/state_machine/index.d.ts +16 -0
- package/dest/state_machine/index.d.ts.map +1 -0
- package/dest/state_machine/index.js +48 -0
- package/dest/state_machine/synchronizer.d.ts +32 -0
- package/dest/state_machine/synchronizer.d.ts.map +1 -0
- package/dest/state_machine/synchronizer.js +58 -0
- package/dest/txe_service/txe_service.d.ts +12 -3
- package/dest/txe_service/txe_service.d.ts.map +1 -1
- package/dest/txe_service/txe_service.js +221 -37
- package/dest/util/encoding.d.ts +11 -4
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +38 -2
- package/package.json +18 -15
- package/src/oracle/txe_oracle.ts +387 -40
- package/src/state_machine/archiver.ts +132 -0
- package/src/state_machine/dummy_p2p_client.ts +167 -0
- package/src/state_machine/global_variable_builder.ts +55 -0
- package/src/state_machine/index.ts +71 -0
- package/src/state_machine/synchronizer.ts +87 -0
- package/src/txe_service/txe_service.ts +427 -31
- package/src/util/encoding.ts +51 -2
- package/dest/node/txe_node.d.ts +0 -320
- package/dest/node/txe_node.d.ts.map +0 -1
- package/dest/node/txe_node.js +0 -481
- package/src/node/txe_node.ts +0 -703
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import { type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
4
2
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
5
3
|
import { type Logger } from '@aztec/foundation/log';
|
|
@@ -7,7 +5,7 @@ import { KeyStore } from '@aztec/key-store';
|
|
|
7
5
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
8
6
|
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
9
7
|
import { AddressDataProvider, ContractDataProvider } from '@aztec/pxe/server';
|
|
10
|
-
import { type MessageLoadOracleInputs, type NoteData, type TypedOracle } from '@aztec/simulator/client';
|
|
8
|
+
import { ExecutionNoteCache, type MessageLoadOracleInputs, type NoteData, type TypedOracle } from '@aztec/simulator/client';
|
|
11
9
|
import { type PublicTxResult } from '@aztec/simulator/server';
|
|
12
10
|
import { type ContractArtifact, EventSelector, type FunctionAbi, FunctionSelector, type NoteSelector } from '@aztec/stdlib/abi';
|
|
13
11
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
@@ -16,7 +14,7 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
16
14
|
import type { ContractInstance, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
17
15
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
18
16
|
import { type KeyValidationRequest, PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
19
|
-
import { ContractClassLog, IndexedTaggingSecret, LogWithTxData,
|
|
17
|
+
import { ContractClassLog, IndexedTaggingSecret, LogWithTxData, PrivateLog, type PublicLog } from '@aztec/stdlib/logs';
|
|
20
18
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
21
19
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
22
20
|
import { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
@@ -37,6 +35,7 @@ export declare class TXE implements TypedOracle {
|
|
|
37
35
|
private contractAddress;
|
|
38
36
|
private nativeWorldStateService;
|
|
39
37
|
private baseFork;
|
|
38
|
+
private stateMachine;
|
|
40
39
|
private blockNumber;
|
|
41
40
|
private sideEffectCounter;
|
|
42
41
|
private msgSender;
|
|
@@ -55,7 +54,7 @@ export declare class TXE implements TypedOracle {
|
|
|
55
54
|
private CHAIN_ID;
|
|
56
55
|
private node;
|
|
57
56
|
private simulationProvider;
|
|
58
|
-
|
|
57
|
+
noteCache: ExecutionNoteCache;
|
|
59
58
|
private authwits;
|
|
60
59
|
private constructor();
|
|
61
60
|
static create(logger: Logger, store: AztecAsyncKVStore, protocolContracts: ProtocolContract[]): Promise<TXE>;
|
|
@@ -110,7 +109,7 @@ export declare class TXE implements TypedOracle {
|
|
|
110
109
|
getCompleteAddress(account: AztecAddress): Promise<import("@aztec/aztec.js").CompleteAddress>;
|
|
111
110
|
getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
|
|
112
111
|
getNotes(storageSlot: Fr, numSelects: number, selectByIndexes: number[], selectByOffsets: number[], selectByLengths: number[], selectValues: Fr[], selectComparators: number[], sortByIndexes: number[], sortByOffsets: number[], sortByLengths: number[], sortOrder: number[], limit: number, offset: number, status: NoteStatus): Promise<NoteData[]>;
|
|
113
|
-
notifyCreatedNote(storageSlot: Fr, _noteTypeId: NoteSelector, noteItems: Fr[], noteHash: Fr, counter: number):
|
|
112
|
+
notifyCreatedNote(storageSlot: Fr, _noteTypeId: NoteSelector, noteItems: Fr[], noteHash: Fr, counter: number): void;
|
|
114
113
|
notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number): Promise<void>;
|
|
115
114
|
notifyCreatedNullifier(innerNullifier: Fr): Promise<void>;
|
|
116
115
|
checkNullifierExists(innerNullifier: Fr): Promise<boolean>;
|
|
@@ -120,6 +119,7 @@ export declare class TXE implements TypedOracle {
|
|
|
120
119
|
commitState(): Promise<void>;
|
|
121
120
|
getTxRequestHash(): Fr;
|
|
122
121
|
notifyCreatedContractClassLog(_log: ContractClassLog, _counter: number): Fr;
|
|
122
|
+
simulateUtilityFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, argsHash: Fr): Promise<Fr>;
|
|
123
123
|
callPrivateFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, argsHash: Fr, sideEffectCounter: number, isStaticCall: boolean): Promise<{
|
|
124
124
|
endSideEffectCounter: Fr;
|
|
125
125
|
returnsHash: Fr;
|
|
@@ -151,5 +151,10 @@ export declare class TXE implements TypedOracle {
|
|
|
151
151
|
aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
|
|
152
152
|
getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
|
|
153
153
|
storePrivateEventLog(contractAddress: AztecAddress, recipient: AztecAddress, eventSelector: EventSelector, logContent: Fr[], txHash: TxHash, logIndexInTx: number, txIndexInBlock: number): Promise<void>;
|
|
154
|
+
privateCallNewFlow(from: AztecAddress, targetContractAddress: AztecAddress | undefined, functionSelector: FunctionSelector | undefined, args: Fr[], argsHash?: Fr, isStaticCall?: boolean): Promise<{
|
|
155
|
+
endSideEffectCounter: Fr;
|
|
156
|
+
returnsHash: Fr;
|
|
157
|
+
txHash: Fr;
|
|
158
|
+
}>;
|
|
154
159
|
}
|
|
155
160
|
//# sourceMappingURL=txe_oracle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"txe_oracle.d.ts","sourceRoot":"","sources":["../../src/oracle/txe_oracle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"txe_oracle.d.ts","sourceRoot":"","sources":["../../src/oracle/txe_oracle.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,wBAAwB,EAa9B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACr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AAE,YAAY,EACvB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,EAAE,EAAE,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;IAYV,kBAAkB,CACtB,IAAI,EAAE,YAAY,EAClB,qBAAqB,EAAE,YAAY,YAAsB,EACzD,gBAAgB,EAAE,gBAAgB,YAA2B,EAC7D,IAAI,EAAE,EAAE,EAAE,EACV,QAAQ,GAAE,EAAc,EACxB,YAAY,GAAE,OAAe;;;;;CAyQhC"}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import { Body, L2Block, Note } from '@aztec/aztec.js';
|
|
2
|
-
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PRIVATE_CONTEXT_INPUTS_LENGTH } from '@aztec/constants';
|
|
2
|
+
import { DEFAULT_GAS_LIMIT, DEFAULT_TEARDOWN_GAS_LIMIT, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_GAS_PER_TX_PUBLIC_PORTION, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, PRIVATE_CONTEXT_INPUTS_LENGTH } from '@aztec/constants';
|
|
3
3
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
4
|
import { Aes128, Schnorr, poseidon2Hash } from '@aztec/foundation/crypto';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import { applyStringFormatting } from '@aztec/foundation/log';
|
|
7
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
7
|
+
import { TestDateProvider, Timer } from '@aztec/foundation/timer';
|
|
8
8
|
import { KeyStore } from '@aztec/key-store';
|
|
9
|
-
import { AddressDataProvider, CapsuleDataProvider, ContractDataProvider, NoteDataProvider, PXEOracleInterface, PrivateEventDataProvider,
|
|
10
|
-
import { ExecutionNoteCache, HashedValuesCache, Oracle, WASMSimulator, extractCallStack, extractPrivateCircuitPublicInputs, pickNotes, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
9
|
+
import { AddressDataProvider, CapsuleDataProvider, ContractDataProvider, NoteDataProvider, PXEOracleInterface, PrivateEventDataProvider, TaggingDataProvider, enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
10
|
+
import { ExecutionNoteCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle, WASMSimulator, executePrivateFunction, extractCallStack, extractPrivateCircuitPublicInputs, pickNotes, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
11
11
|
import { createTxForPublicCalls } from '@aztec/simulator/public/fixtures';
|
|
12
|
-
import { ExecutionError, PublicContractsDB, PublicTxSimulator, createSimulationError, resolveAssertionMessageFromError } from '@aztec/simulator/server';
|
|
13
|
-
import { FunctionSelector, countArgumentsSize } from '@aztec/stdlib/abi';
|
|
12
|
+
import { ExecutionError, PublicContractsDB, PublicProcessor, PublicTxSimulator, createSimulationError, resolveAssertionMessageFromError } from '@aztec/simulator/server';
|
|
13
|
+
import { FunctionSelector, FunctionType, countArgumentsSize } from '@aztec/stdlib/abi';
|
|
14
14
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
15
15
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
16
16
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
17
17
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
18
|
-
import { Gas, GasFees } from '@aztec/stdlib/gas';
|
|
19
|
-
import { computeNoteHashNonce, computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
20
|
-
import { PrivateContextInputs, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
18
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
19
|
+
import { computeNoteHashNonce, computePublicDataTreeLeafSlot, computeUniqueNoteHash, computeVarArgsHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
20
|
+
import { PartialPrivateTailPublicInputsForPublic, PartialPrivateTailPublicInputsForRollup, PrivateContextInputs, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PrivateToRollupAccumulatedData, PublicCallRequest, RollupValidationRequests, ScopedLogHash } from '@aztec/stdlib/kernel';
|
|
21
21
|
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
22
|
+
import { PrivateLog } from '@aztec/stdlib/logs';
|
|
23
|
+
import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
24
|
+
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
22
25
|
import { makeAppendOnlyTreeSnapshot, makeContentCommitment, makeGlobalVariables, makeHeader } from '@aztec/stdlib/testing';
|
|
23
26
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, NullifierMembershipWitness, PublicDataTreeLeaf, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
24
|
-
import { BlockHeader, CallContext, GlobalVariables, PublicCallRequestWithCalldata, TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
25
|
-
import { ForkCheckpoint
|
|
26
|
-
import {
|
|
27
|
+
import { BlockHeader, CallContext, GlobalVariables, HashedValues, PrivateExecutionResult, PublicCallRequestWithCalldata, Tx, TxConstantData, TxContext, TxEffect, TxHash, collectNested } from '@aztec/stdlib/tx';
|
|
28
|
+
import { ForkCheckpoint } from '@aztec/world-state/native';
|
|
29
|
+
import { TXEStateMachine } from '../state_machine/index.js';
|
|
27
30
|
import { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
|
|
28
31
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
29
32
|
export class TXE {
|
|
@@ -41,6 +44,7 @@ export class TXE {
|
|
|
41
44
|
contractAddress;
|
|
42
45
|
nativeWorldStateService;
|
|
43
46
|
baseFork;
|
|
47
|
+
stateMachine;
|
|
44
48
|
blockNumber;
|
|
45
49
|
sideEffectCounter;
|
|
46
50
|
msgSender;
|
|
@@ -62,7 +66,7 @@ export class TXE {
|
|
|
62
66
|
simulationProvider;
|
|
63
67
|
noteCache;
|
|
64
68
|
authwits;
|
|
65
|
-
constructor(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, accountDataProvider, executionCache, contractAddress, nativeWorldStateService, baseFork){
|
|
69
|
+
constructor(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, accountDataProvider, executionCache, contractAddress, nativeWorldStateService, baseFork, stateMachine){
|
|
66
70
|
this.logger = logger;
|
|
67
71
|
this.keyStore = keyStore;
|
|
68
72
|
this.contractDataProvider = contractDataProvider;
|
|
@@ -77,6 +81,7 @@ export class TXE {
|
|
|
77
81
|
this.contractAddress = contractAddress;
|
|
78
82
|
this.nativeWorldStateService = nativeWorldStateService;
|
|
79
83
|
this.baseFork = baseFork;
|
|
84
|
+
this.stateMachine = stateMachine;
|
|
80
85
|
this.blockNumber = 1;
|
|
81
86
|
this.sideEffectCounter = 0;
|
|
82
87
|
this.functionSelector = FunctionSelector.fromField(new Fr(0));
|
|
@@ -94,20 +99,21 @@ export class TXE {
|
|
|
94
99
|
this.simulationProvider = new WASMSimulator();
|
|
95
100
|
this.authwits = new Map();
|
|
96
101
|
this.noteCache = new ExecutionNoteCache(this.getTxRequestHash());
|
|
97
|
-
this.node =
|
|
102
|
+
this.node = stateMachine.node;
|
|
98
103
|
// Default msg_sender (for entrypoints) is now Fr.max_value rather than 0 addr (see #7190 & #7404)
|
|
99
104
|
this.msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE);
|
|
100
105
|
this.pxeOracleInterface = new PXEOracleInterface(this.node, this.keyStore, this.contractDataProvider, this.noteDataProvider, this.capsuleDataProvider, this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, this.privateEventDataProvider, this.logger);
|
|
101
106
|
}
|
|
102
107
|
static async create(logger, store, protocolContracts) {
|
|
103
108
|
const executionCache = new HashedValuesCache();
|
|
104
|
-
const
|
|
109
|
+
const stateMachine = await TXEStateMachine.create(store);
|
|
110
|
+
const syncDataProvider = stateMachine.syncDataProvider;
|
|
111
|
+
const nativeWorldStateService = stateMachine.synchronizer.nativeWorldStateService;
|
|
105
112
|
const baseFork = await nativeWorldStateService.fork();
|
|
106
113
|
const addressDataProvider = new AddressDataProvider(store);
|
|
107
114
|
const privateEventDataProvider = new PrivateEventDataProvider(store);
|
|
108
115
|
const contractDataProvider = new ContractDataProvider(store);
|
|
109
116
|
const noteDataProvider = await NoteDataProvider.create(store);
|
|
110
|
-
const syncDataProvider = new SyncDataProvider(store);
|
|
111
117
|
const taggingDataProvider = new TaggingDataProvider(store);
|
|
112
118
|
const capsuleDataProvider = new CapsuleDataProvider(store);
|
|
113
119
|
const keyStore = new KeyStore(store);
|
|
@@ -117,7 +123,7 @@ export class TXE {
|
|
|
117
123
|
await contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
118
124
|
await contractDataProvider.addContractInstance(instance);
|
|
119
125
|
}
|
|
120
|
-
return new TXE(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, accountDataProvider, executionCache, await AztecAddress.random(), nativeWorldStateService, baseFork);
|
|
126
|
+
return new TXE(logger, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, accountDataProvider, executionCache, await AztecAddress.random(), nativeWorldStateService, baseFork, stateMachine);
|
|
121
127
|
}
|
|
122
128
|
// Utils
|
|
123
129
|
getNativeWorldStateService() {
|
|
@@ -127,10 +133,10 @@ export class TXE {
|
|
|
127
133
|
return this.baseFork;
|
|
128
134
|
}
|
|
129
135
|
getChainId() {
|
|
130
|
-
return Promise.resolve(
|
|
136
|
+
return Promise.resolve(new Fr(this.CHAIN_ID));
|
|
131
137
|
}
|
|
132
138
|
getVersion() {
|
|
133
|
-
return Promise.resolve(
|
|
139
|
+
return Promise.resolve(new Fr(this.ROLLUP_VERSION));
|
|
134
140
|
}
|
|
135
141
|
getMsgSender() {
|
|
136
142
|
return this.msgSender;
|
|
@@ -155,7 +161,6 @@ export class TXE {
|
|
|
155
161
|
}
|
|
156
162
|
setBlockNumber(blockNumber) {
|
|
157
163
|
this.blockNumber = blockNumber;
|
|
158
|
-
this.node.setBlockNumber(blockNumber);
|
|
159
164
|
}
|
|
160
165
|
getContractDataProvider() {
|
|
161
166
|
return this.contractDataProvider;
|
|
@@ -186,8 +191,8 @@ export class TXE {
|
|
|
186
191
|
const previousBlockState = this.nativeWorldStateService.getSnapshot(blockNumber - 1);
|
|
187
192
|
const stateReference = await snap.getStateReference();
|
|
188
193
|
const inputs = PrivateContextInputs.empty();
|
|
189
|
-
inputs.txContext.chainId = new Fr(
|
|
190
|
-
inputs.txContext.version = new Fr(
|
|
194
|
+
inputs.txContext.chainId = new Fr(this.CHAIN_ID);
|
|
195
|
+
inputs.txContext.version = new Fr(this.ROLLUP_VERSION);
|
|
191
196
|
inputs.historicalHeader.globalVariables.blockNumber = new Fr(blockNumber);
|
|
192
197
|
inputs.historicalHeader.state = stateReference;
|
|
193
198
|
inputs.historicalHeader.lastArchive.root = Fr.fromBuffer((await previousBlockState.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
@@ -238,8 +243,7 @@ export class TXE {
|
|
|
238
243
|
addPublicLogs(logs) {
|
|
239
244
|
logs.forEach((log)=>{
|
|
240
245
|
try {
|
|
241
|
-
|
|
242
|
-
const tag = log.log[1];
|
|
246
|
+
const tag = log.fields[0];
|
|
243
247
|
this.logger.verbose(`Found tagged public log with tag ${tag.toString()} in block ${this.blockNumber}`);
|
|
244
248
|
this.publicLogs.push(log);
|
|
245
249
|
} catch (err) {
|
|
@@ -410,7 +414,6 @@ export class TXE {
|
|
|
410
414
|
noteHash
|
|
411
415
|
}, counter);
|
|
412
416
|
this.sideEffectCounter = counter + 1;
|
|
413
|
-
return Promise.resolve();
|
|
414
417
|
}
|
|
415
418
|
async notifyNullifiedNote(innerNullifier, noteHash, counter) {
|
|
416
419
|
await this.checkNullifiersNotInTree(this.contractAddress, [
|
|
@@ -494,6 +497,7 @@ export class TXE {
|
|
|
494
497
|
txEffect.publicDataWrites = this.publicDataWrites;
|
|
495
498
|
txEffect.privateLogs = this.privateLogs;
|
|
496
499
|
txEffect.publicLogs = this.publicLogs;
|
|
500
|
+
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
497
501
|
const body = new Body([
|
|
498
502
|
txEffect
|
|
499
503
|
]);
|
|
@@ -515,22 +519,13 @@ export class TXE {
|
|
|
515
519
|
await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
516
520
|
}
|
|
517
521
|
}
|
|
518
|
-
// At this point we always have a single tx in the block so we set the tx index to 0.
|
|
519
|
-
const txIndexInBlock = 0;
|
|
520
|
-
await this.node.processTxEffect(blockNumber, txIndexInBlock, new TxHash(new Fr(blockNumber)), txEffect);
|
|
521
522
|
const stateReference = await fork.getStateReference();
|
|
522
523
|
const archiveInfo = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
523
524
|
const header = new BlockHeader(new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, makeGlobalVariables(), Fr.ZERO, Fr.ZERO);
|
|
524
525
|
header.globalVariables.blockNumber = new Fr(blockNumber);
|
|
525
526
|
l2Block.header = header;
|
|
526
527
|
await fork.updateArchive(l2Block.header);
|
|
527
|
-
|
|
528
|
-
// Now emulate a "sync" to this block, by letting cpp reapply the block's
|
|
529
|
-
// changes to the underlying unforked world state and comparing the results
|
|
530
|
-
// against the block's state reference (which is this state reference here in the fork).
|
|
531
|
-
// This essentially commits the state updates to the unforked state and sanity checks the roots.
|
|
532
|
-
await this.nativeWorldStateService.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
|
|
533
|
-
await this.syncDataProvider.setHeader(header);
|
|
528
|
+
await this.stateMachine.handleL2Block(l2Block);
|
|
534
529
|
this.publicDataWrites = [];
|
|
535
530
|
this.privateLogs = [];
|
|
536
531
|
this.publicLogs = [];
|
|
@@ -545,6 +540,46 @@ export class TXE {
|
|
|
545
540
|
notifyCreatedContractClassLog(_log, _counter) {
|
|
546
541
|
throw new Error('Method not implemented.');
|
|
547
542
|
}
|
|
543
|
+
async simulateUtilityFunction(targetContractAddress, functionSelector, argsHash) {
|
|
544
|
+
const artifact = await this.contractDataProvider.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
545
|
+
if (!artifact) {
|
|
546
|
+
throw new Error(`Cannot call ${functionSelector} as there is artifact found at ${targetContractAddress}.`);
|
|
547
|
+
}
|
|
548
|
+
const call = {
|
|
549
|
+
name: artifact.name,
|
|
550
|
+
selector: functionSelector,
|
|
551
|
+
to: targetContractAddress
|
|
552
|
+
};
|
|
553
|
+
const entryPointArtifact = await this.pxeOracleInterface.getFunctionArtifact(call.to, call.selector);
|
|
554
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
555
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
556
|
+
}
|
|
557
|
+
const oracle = new UtilityExecutionOracle(call.to, [], [], this.pxeOracleInterface, undefined, undefined);
|
|
558
|
+
try {
|
|
559
|
+
this.logger.verbose(`Executing utility function ${entryPointArtifact.name}`, {
|
|
560
|
+
contract: call.to,
|
|
561
|
+
selector: call.selector
|
|
562
|
+
});
|
|
563
|
+
const args = await this.loadFromExecutionCache(argsHash);
|
|
564
|
+
const initialWitness = toACVMWitness(0, args);
|
|
565
|
+
const acirExecutionResult = await this.simulationProvider.executeUserCircuit(initialWitness, entryPointArtifact, new Oracle(oracle)).catch((err)=>{
|
|
566
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
567
|
+
throw new ExecutionError(err.message, {
|
|
568
|
+
contractAddress: call.to,
|
|
569
|
+
functionSelector: call.selector
|
|
570
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
571
|
+
cause: err
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
575
|
+
this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
|
|
576
|
+
const returnHash = await computeVarArgsHash(returnWitness);
|
|
577
|
+
this.storeInExecutionCache(returnWitness, returnHash);
|
|
578
|
+
return returnHash;
|
|
579
|
+
} catch (err) {
|
|
580
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
581
|
+
}
|
|
582
|
+
}
|
|
548
583
|
async callPrivateFunction(targetContractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall) {
|
|
549
584
|
this.logger.verbose(`Executing external function ${await this.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
550
585
|
// Store and modify env
|
|
@@ -620,8 +655,8 @@ export class TXE {
|
|
|
620
655
|
const executionRequest = new PublicCallRequestWithCalldata(callRequest, calldata);
|
|
621
656
|
const db = this.baseFork;
|
|
622
657
|
const globalVariables = GlobalVariables.empty();
|
|
623
|
-
globalVariables.chainId = new Fr(
|
|
624
|
-
globalVariables.version = new Fr(
|
|
658
|
+
globalVariables.chainId = new Fr(this.CHAIN_ID);
|
|
659
|
+
globalVariables.version = new Fr(this.ROLLUP_VERSION);
|
|
625
660
|
globalVariables.blockNumber = new Fr(this.blockNumber);
|
|
626
661
|
globalVariables.gasFees = new GasFees(1, 1);
|
|
627
662
|
let result;
|
|
@@ -630,7 +665,7 @@ export class TXE {
|
|
|
630
665
|
const checkpoint = await ForkCheckpoint.new(db);
|
|
631
666
|
try {
|
|
632
667
|
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(this));
|
|
633
|
-
const simulator = new PublicTxSimulator(this.baseFork, contractsDB, globalVariables, /*doMerkleOperations=*/ false);
|
|
668
|
+
const simulator = new PublicTxSimulator(this.baseFork, contractsDB, globalVariables, /*doMerkleOperations=*/ false, /*skipFeeEnforcement=*/ false, /*clientInitiatedSimulation=*/ true);
|
|
634
669
|
const { usedTxRequestHashForNonces } = this.noteCache.finish();
|
|
635
670
|
const firstNullifier = usedTxRequestHashForNonces ? this.getTxRequestHash() : this.noteCache.getAllNullifiers()[0];
|
|
636
671
|
// When setting up a teardown call, we tell it that
|
|
@@ -826,4 +861,140 @@ export class TXE {
|
|
|
826
861
|
storePrivateEventLog(contractAddress, recipient, eventSelector, logContent, txHash, logIndexInTx, txIndexInBlock) {
|
|
827
862
|
return this.pxeOracleInterface.storePrivateEventLog(contractAddress, recipient, eventSelector, logContent, txHash, logIndexInTx, txIndexInBlock);
|
|
828
863
|
}
|
|
864
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
|
|
865
|
+
this.logger.verbose(`Executing external function ${await this.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
866
|
+
const artifact = await this.contractDataProvider.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
867
|
+
if (artifact === undefined) {
|
|
868
|
+
throw new Error('Function Artifact does not exist');
|
|
869
|
+
}
|
|
870
|
+
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
871
|
+
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
872
|
+
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
873
|
+
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
874
|
+
const txContext = new TxContext(this.CHAIN_ID, this.ROLLUP_VERSION, gasSettings);
|
|
875
|
+
const blockHeader = await this.pxeOracleInterface.getBlockHeader();
|
|
876
|
+
const noteCache = new ExecutionNoteCache(this.getTxRequestHash());
|
|
877
|
+
const context = new PrivateExecutionOracle(argsHash, txContext, callContext, /** Header of a block whose state is used during private execution (not the block the transaction is included in). */ blockHeader, /** List of transient auth witnesses to be used during this simulation */ [], /** List of transient auth witnesses to be used during this simulation */ [], HashedValuesCache.create(), noteCache, this.pxeOracleInterface, this.simulationProvider, 0, 1);
|
|
878
|
+
context.storeInExecutionCache(args, argsHash);
|
|
879
|
+
// Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
|
|
880
|
+
let result;
|
|
881
|
+
try {
|
|
882
|
+
const executionResult = await executePrivateFunction(this.simulationProvider, context, artifact, targetContractAddress, functionSelector);
|
|
883
|
+
const { usedTxRequestHashForNonces } = noteCache.finish();
|
|
884
|
+
const firstNullifierHint = usedTxRequestHashForNonces ? Fr.ZERO : noteCache.getAllNullifiers()[0];
|
|
885
|
+
const publicCallRequests = collectNested([
|
|
886
|
+
executionResult
|
|
887
|
+
], (r)=>[
|
|
888
|
+
...r.publicInputs.publicCallRequests.map((r)=>r.inner),
|
|
889
|
+
r.publicInputs.publicTeardownCallRequest
|
|
890
|
+
]).filter((r)=>!r.isEmpty());
|
|
891
|
+
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
892
|
+
const calldata = await context.loadFromExecutionCache(r.calldataHash);
|
|
893
|
+
return new HashedValues(calldata, r.calldataHash);
|
|
894
|
+
}));
|
|
895
|
+
result = new PrivateExecutionResult(executionResult, firstNullifierHint, publicFunctionsCalldata);
|
|
896
|
+
} catch (err) {
|
|
897
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
898
|
+
}
|
|
899
|
+
const uniqueNoteHashes = [];
|
|
900
|
+
const taggedPrivateLogs = [];
|
|
901
|
+
const nullifiers = result.firstNullifier.equals(Fr.ZERO) ? [
|
|
902
|
+
this.getTxRequestHash()
|
|
903
|
+
] : noteCache.getAllNullifiers();
|
|
904
|
+
const l2ToL1Messages = [];
|
|
905
|
+
const contractClassLogsHashes = [];
|
|
906
|
+
const publicCallRequests = [];
|
|
907
|
+
const nonceGenerator = nullifiers[0];
|
|
908
|
+
let publicTeardownCallRequest;
|
|
909
|
+
let noteHashIndexInTx = 0;
|
|
910
|
+
const executions = [
|
|
911
|
+
result.entrypoint
|
|
912
|
+
];
|
|
913
|
+
while(executions.length !== 0){
|
|
914
|
+
const execution = executions.shift();
|
|
915
|
+
executions.unshift(...execution.nestedExecutions);
|
|
916
|
+
const { contractAddress } = execution.publicInputs.callContext;
|
|
917
|
+
const noteHashesFromExecution = await Promise.all(execution.publicInputs.noteHashes.filter((noteHash)=>!noteHash.isEmpty()).map(async (noteHash)=>{
|
|
918
|
+
const nonce = await computeNoteHashNonce(nonceGenerator, noteHashIndexInTx++);
|
|
919
|
+
const siloedNoteHash = await siloNoteHash(contractAddress, noteHash.value);
|
|
920
|
+
// We could defer this to the public processor, and pass this in as non-revertible.
|
|
921
|
+
return computeUniqueNoteHash(nonce, siloedNoteHash);
|
|
922
|
+
}));
|
|
923
|
+
const privateLogsFromExecution = await Promise.all(execution.publicInputs.privateLogs.filter((privateLog)=>!privateLog.isEmpty()).map(async (metadata)=>{
|
|
924
|
+
metadata.log.fields[0] = await poseidon2Hash([
|
|
925
|
+
contractAddress,
|
|
926
|
+
metadata.log.fields[0]
|
|
927
|
+
]);
|
|
928
|
+
return metadata.log;
|
|
929
|
+
}));
|
|
930
|
+
uniqueNoteHashes.push(...noteHashesFromExecution);
|
|
931
|
+
taggedPrivateLogs.push(...privateLogsFromExecution);
|
|
932
|
+
l2ToL1Messages.push(...execution.publicInputs.l2ToL1Msgs.filter((l2ToL1Message)=>!l2ToL1Message.isEmpty()).map((message)=>message.scope(contractAddress)));
|
|
933
|
+
contractClassLogsHashes.push(...execution.publicInputs.contractClassLogsHashes.filter((contractClassLogsHash)=>!contractClassLogsHash.isEmpty()).map((message)=>message.logHash.scope(contractAddress)));
|
|
934
|
+
publicCallRequests.push(...execution.publicInputs.publicCallRequests.filter((publicCallRequest)=>!publicCallRequest.isEmpty()).map((callRequest)=>callRequest.inner));
|
|
935
|
+
if (publicTeardownCallRequest !== undefined && !execution.publicInputs.publicTeardownCallRequest.isEmpty()) {
|
|
936
|
+
throw new Error('Trying to set multiple teardown requests');
|
|
937
|
+
}
|
|
938
|
+
publicTeardownCallRequest = execution.publicInputs.publicTeardownCallRequest.isEmpty() ? publicTeardownCallRequest : execution.publicInputs.publicTeardownCallRequest;
|
|
939
|
+
}
|
|
940
|
+
const globals = makeGlobalVariables();
|
|
941
|
+
globals.blockNumber = new Fr(this.blockNumber);
|
|
942
|
+
globals.gasFees = GasFees.empty();
|
|
943
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(this));
|
|
944
|
+
const simulator = new PublicTxSimulator(this.baseFork, contractsDB, globals, true, true);
|
|
945
|
+
const processor = new PublicProcessor(globals, this.baseFork, contractsDB, simulator, new TestDateProvider());
|
|
946
|
+
const constantData = new TxConstantData(blockHeader, txContext, Fr.zero(), Fr.zero());
|
|
947
|
+
const hasPublicCalls = result.publicFunctionCalldata.length !== 0;
|
|
948
|
+
let inputsForRollup;
|
|
949
|
+
let inputsForPublic;
|
|
950
|
+
// Private only
|
|
951
|
+
if (result.publicFunctionCalldata.length === 0) {
|
|
952
|
+
const accumulatedDataForRollup = new PrivateToRollupAccumulatedData(padArrayEnd(uniqueNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX), padArrayEnd(nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX), padArrayEnd(l2ToL1Messages, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), padArrayEnd(taggedPrivateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX), padArrayEnd(contractClassLogsHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX));
|
|
953
|
+
inputsForRollup = new PartialPrivateTailPublicInputsForRollup(accumulatedDataForRollup);
|
|
954
|
+
} else {
|
|
955
|
+
const accumulatedDataForPublic = new PrivateToPublicAccumulatedData(padArrayEnd(uniqueNoteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX), padArrayEnd(nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX), padArrayEnd(l2ToL1Messages, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), padArrayEnd(taggedPrivateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX), padArrayEnd(contractClassLogsHashes, ScopedLogHash.empty(), MAX_CONTRACT_CLASS_LOGS_PER_TX), padArrayEnd(publicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX));
|
|
956
|
+
inputsForPublic = new PartialPrivateTailPublicInputsForPublic(// We are using non-revertible because we set the first nullifier to be used as a nonce generator, otherwise the tx hash is manually calculated.
|
|
957
|
+
// nonrevertible
|
|
958
|
+
accumulatedDataForPublic, // revertible
|
|
959
|
+
PrivateToPublicAccumulatedData.empty(), publicTeardownCallRequest ?? PublicCallRequest.empty());
|
|
960
|
+
}
|
|
961
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, RollupValidationRequests.empty(), /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), hasPublicCalls ? inputsForPublic : undefined, !hasPublicCalls ? inputsForRollup : undefined);
|
|
962
|
+
const tx = new Tx(txData, ClientIvcProof.empty(), [], result.publicFunctionCalldata);
|
|
963
|
+
const results = await processor.process([
|
|
964
|
+
tx
|
|
965
|
+
]);
|
|
966
|
+
const processedTxs = results[0];
|
|
967
|
+
const failedTxs = results[1];
|
|
968
|
+
if (failedTxs.length !== 0) {
|
|
969
|
+
throw new Error('Public execution has failed');
|
|
970
|
+
}
|
|
971
|
+
const fork = this.baseFork;
|
|
972
|
+
const txEffect = TxEffect.empty();
|
|
973
|
+
txEffect.noteHashes = processedTxs[0].txEffect.noteHashes;
|
|
974
|
+
txEffect.nullifiers = processedTxs[0].txEffect.nullifiers;
|
|
975
|
+
txEffect.privateLogs = taggedPrivateLogs;
|
|
976
|
+
txEffect.publicLogs = processedTxs[0].txEffect.publicLogs;
|
|
977
|
+
txEffect.publicDataWrites = processedTxs[0].txEffect.publicDataWrites;
|
|
978
|
+
txEffect.txHash = new TxHash(new Fr(this.blockNumber));
|
|
979
|
+
const body = new Body([
|
|
980
|
+
txEffect
|
|
981
|
+
]);
|
|
982
|
+
const l2Block = new L2Block(makeAppendOnlyTreeSnapshot(this.blockNumber + 1), makeHeader(0, this.blockNumber, this.blockNumber), body);
|
|
983
|
+
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
984
|
+
await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
985
|
+
const stateReference = await fork.getStateReference();
|
|
986
|
+
const archiveInfo = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
987
|
+
const header = new BlockHeader(new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, globals, Fr.ZERO, Fr.ZERO);
|
|
988
|
+
header.globalVariables.blockNumber = new Fr(this.blockNumber);
|
|
989
|
+
l2Block.header = header;
|
|
990
|
+
await fork.updateArchive(l2Block.header);
|
|
991
|
+
await this.stateMachine.handleL2Block(l2Block);
|
|
992
|
+
const txRequestHash = this.getTxRequestHash();
|
|
993
|
+
this.setBlockNumber(this.blockNumber + 1);
|
|
994
|
+
return {
|
|
995
|
+
endSideEffectCounter: result.entrypoint.publicInputs.endSideEffectCounter,
|
|
996
|
+
returnsHash: result.entrypoint.publicInputs.returnsHash,
|
|
997
|
+
txHash: txRequestHash
|
|
998
|
+
};
|
|
999
|
+
}
|
|
829
1000
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ArchiverStoreHelper, type PublishedL2Block } from '@aztec/archiver';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { L2Block, L2Tips } from '@aztec/stdlib/block';
|
|
6
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
8
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
9
|
+
export declare class TXEArchiver extends ArchiverStoreHelper {
|
|
10
|
+
constructor(db: AztecAsyncKVStore);
|
|
11
|
+
addBlocks(blocks: PublishedL2Block[]): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
14
|
+
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
15
|
+
*/
|
|
16
|
+
getBlockNumber(): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the number of the latest L2 block proven seen by the block source implementation.
|
|
19
|
+
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
20
|
+
*/
|
|
21
|
+
getProvenBlockNumber(): Promise<number>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets a published l2 block. If a negative number is passed, the block returned is the most recent.
|
|
24
|
+
* @param number - The block number to return (inclusive).
|
|
25
|
+
* @returns The requested L2 block.
|
|
26
|
+
*/
|
|
27
|
+
getPublishedBlock(number: number): Promise<PublishedL2Block | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets an l2 block. If a negative number is passed, the block returned is the most recent.
|
|
30
|
+
* @param number - The block number to return (inclusive).
|
|
31
|
+
* @returns The requested L2 block.
|
|
32
|
+
*/
|
|
33
|
+
getBlock(number: number): Promise<L2Block | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets an l2 block header.
|
|
36
|
+
* @param number - The block number to return or 'latest' for the most recent one.
|
|
37
|
+
* @returns The requested L2 block header.
|
|
38
|
+
*/
|
|
39
|
+
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined>;
|
|
40
|
+
getBlocks(from: number, limit: number, _proven?: boolean): Promise<L2Block[]>;
|
|
41
|
+
getL2SlotNumber(): Promise<bigint>;
|
|
42
|
+
getL2EpochNumber(): Promise<bigint>;
|
|
43
|
+
getBlocksForEpoch(_epochNumber: bigint): Promise<L2Block[]>;
|
|
44
|
+
getBlockHeadersForEpoch(_epochNumber: bigint): Promise<BlockHeader[]>;
|
|
45
|
+
isEpochComplete(_epochNumber: bigint): Promise<boolean>;
|
|
46
|
+
getL2Tips(): Promise<L2Tips>;
|
|
47
|
+
getL1Constants(): Promise<L1RollupConstants>;
|
|
48
|
+
syncImmediate(): Promise<void>;
|
|
49
|
+
getContract(_address: AztecAddress, _blockNumber?: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
50
|
+
getRollupAddress(): Promise<EthAddress>;
|
|
51
|
+
getRegistryAddress(): Promise<EthAddress>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=archiver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archiver.d.ts","sourceRoot":"","sources":["../../src/state_machine/archiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAA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