@aztec/txe 0.0.1-commit.6d3c34e → 0.0.1-commit.7ac86ea28
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/constants.d.ts +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +82 -50
- package/dest/oracle/interfaces.d.ts +4 -4
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +108 -41
- package/dest/rpc_translator.d.ts +21 -15
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +78 -53
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +36 -178
- package/dest/state_machine/dummy_p2p_client.d.ts +15 -11
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +27 -15
- package/dest/state_machine/index.d.ts +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +35 -12
- package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +11 -7
- package/dest/state_machine/synchronizer.d.ts +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/txe_session.d.ts +6 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +93 -25
- package/dest/util/encoding.d.ts +17 -17
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/dest/utils/block_creation.d.ts +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +83 -49
- package/src/oracle/interfaces.ts +3 -3
- package/src/oracle/txe_oracle_public_context.ts +6 -8
- package/src/oracle/txe_oracle_top_level_context.ts +132 -94
- package/src/rpc_translator.ts +81 -55
- package/src/state_machine/archiver.ts +37 -234
- package/src/state_machine/dummy_p2p_client.ts +39 -21
- package/src/state_machine/index.ts +49 -11
- package/src/state_machine/mock_epoch_cache.ts +11 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +100 -84
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
7
|
P2PCheckpointReceivedCallback,
|
|
8
8
|
P2PConfig,
|
|
9
|
+
P2PDuplicateAttestationCallback,
|
|
10
|
+
P2PDuplicateProposalCallback,
|
|
9
11
|
P2PSyncState,
|
|
10
12
|
PeerId,
|
|
11
13
|
ReqRespSubProtocol,
|
|
@@ -14,9 +16,9 @@ import type {
|
|
|
14
16
|
StatusMessage,
|
|
15
17
|
} from '@aztec/p2p';
|
|
16
18
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
17
|
-
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
18
|
-
import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
19
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
19
|
+
import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
|
|
21
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
20
22
|
|
|
21
23
|
export class DummyP2P implements P2P {
|
|
22
24
|
public validate(_txs: Tx[]): Promise<void> {
|
|
@@ -39,6 +41,10 @@ export class DummyP2P implements P2P {
|
|
|
39
41
|
throw new Error('DummyP2P does not implement "getPeers"');
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
|
|
45
|
+
return Promise.resolve(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
public broadcastProposal(_proposal: BlockProposal): Promise<void> {
|
|
43
49
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
44
50
|
}
|
|
@@ -71,8 +77,8 @@ export class DummyP2P implements P2P {
|
|
|
71
77
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
public
|
|
75
|
-
throw new Error('DummyP2P does not implement "
|
|
80
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
81
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -97,6 +103,10 @@ export class DummyP2P implements P2P {
|
|
|
97
103
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
107
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
public getPendingTxCount(): Promise<number> {
|
|
101
111
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
102
112
|
}
|
|
@@ -125,6 +135,10 @@ export class DummyP2P implements P2P {
|
|
|
125
135
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
public getTxProvider(): ITxProvider {
|
|
139
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
129
143
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
130
144
|
}
|
|
@@ -133,8 +147,8 @@ export class DummyP2P implements P2P {
|
|
|
133
147
|
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
134
148
|
}
|
|
135
149
|
|
|
136
|
-
public
|
|
137
|
-
throw new Error('DummyP2P does not implement "
|
|
150
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -157,14 +171,6 @@ export class DummyP2P implements P2P {
|
|
|
157
171
|
throw new Error('DummyP2P does not implement "sync"');
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
161
|
-
throw new Error('DummyP2P does not implement "requestTxsByHash"');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
165
|
-
throw new Error('DummyP2P does not implement "getTxs"');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
174
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
169
175
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
170
176
|
}
|
|
@@ -173,10 +179,6 @@ export class DummyP2P implements P2P {
|
|
|
173
179
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
174
180
|
}
|
|
175
181
|
|
|
176
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
177
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
182
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
181
183
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
182
184
|
}
|
|
@@ -189,8 +191,12 @@ export class DummyP2P implements P2P {
|
|
|
189
191
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
190
192
|
}
|
|
191
193
|
|
|
192
|
-
|
|
193
|
-
throw new Error('DummyP2P does not implement "
|
|
194
|
+
protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
195
|
+
throw new Error('DummyP2P does not implement "protectTxs".');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
199
|
+
return Promise.resolve();
|
|
194
200
|
}
|
|
195
201
|
|
|
196
202
|
addReqRespSubProtocol(
|
|
@@ -206,4 +212,16 @@ export class DummyP2P implements P2P {
|
|
|
206
212
|
|
|
207
213
|
//This is no-op
|
|
208
214
|
public registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
215
|
+
|
|
216
|
+
public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
|
|
217
|
+
throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
|
|
221
|
+
throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
|
|
226
|
+
}
|
|
209
227
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
|
|
2
2
|
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import type
|
|
5
|
-
import { AnchorBlockStore } from '@aztec/pxe/server';
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
6
7
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
|
-
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
9
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
9
11
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
10
12
|
|
|
11
13
|
import { TXEArchiver } from './archiver.js';
|
|
@@ -23,13 +25,16 @@ export class TXEStateMachine {
|
|
|
23
25
|
public synchronizer: TXESynchronizer,
|
|
24
26
|
public archiver: TXEArchiver,
|
|
25
27
|
public anchorBlockStore: AnchorBlockStore,
|
|
28
|
+
public contractSyncService: ContractSyncService,
|
|
26
29
|
) {}
|
|
27
30
|
|
|
28
|
-
public static async create(
|
|
29
|
-
|
|
31
|
+
public static async create(
|
|
32
|
+
archiver: TXEArchiver,
|
|
33
|
+
anchorBlockStore: AnchorBlockStore,
|
|
34
|
+
contractStore: ContractStore,
|
|
35
|
+
noteStore: NoteStore,
|
|
36
|
+
) {
|
|
30
37
|
const synchronizer = await TXESynchronizer.create();
|
|
31
|
-
const anchorBlockStore = new AnchorBlockStore(db);
|
|
32
|
-
|
|
33
38
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
34
39
|
|
|
35
40
|
const log = createLogger('txe_node');
|
|
@@ -45,6 +50,7 @@ export class TXEStateMachine {
|
|
|
45
50
|
undefined,
|
|
46
51
|
undefined,
|
|
47
52
|
undefined,
|
|
53
|
+
undefined,
|
|
48
54
|
VERSION,
|
|
49
55
|
CHAIN_ID,
|
|
50
56
|
new TXEGlobalVariablesBuilder(),
|
|
@@ -55,11 +61,40 @@ export class TXEStateMachine {
|
|
|
55
61
|
log,
|
|
56
62
|
);
|
|
57
63
|
|
|
58
|
-
|
|
64
|
+
const contractSyncService = new ContractSyncService(
|
|
65
|
+
node,
|
|
66
|
+
contractStore,
|
|
67
|
+
noteStore,
|
|
68
|
+
createLogger('txe:contract_sync'),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
public async handleL2Block(block: L2Block) {
|
|
62
|
-
|
|
75
|
+
// Create a checkpoint from the block manually.
|
|
76
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
77
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
78
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
79
|
+
const checkpoint = new Checkpoint(
|
|
80
|
+
block.archive,
|
|
81
|
+
CheckpointHeader.from({
|
|
82
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
83
|
+
inHash: Fr.ZERO,
|
|
84
|
+
blobsHash: Fr.ZERO,
|
|
85
|
+
blockHeadersHash: Fr.ZERO,
|
|
86
|
+
epochOutHash: Fr.ZERO,
|
|
87
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
88
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
89
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
90
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
91
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
92
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
93
|
+
}),
|
|
94
|
+
[block],
|
|
95
|
+
checkpointNumber,
|
|
96
|
+
);
|
|
97
|
+
|
|
63
98
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
64
99
|
checkpoint,
|
|
65
100
|
new L1PublishedData(
|
|
@@ -69,10 +104,13 @@ export class TXEStateMachine {
|
|
|
69
104
|
),
|
|
70
105
|
[],
|
|
71
106
|
);
|
|
107
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
108
|
+
this.contractSyncService.wipe();
|
|
109
|
+
|
|
72
110
|
await Promise.all([
|
|
73
|
-
this.synchronizer.handleL2Block(block
|
|
111
|
+
this.synchronizer.handleL2Block(block),
|
|
74
112
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
75
|
-
this.anchorBlockStore.setHeader(block.
|
|
113
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
76
114
|
]);
|
|
77
115
|
}
|
|
78
116
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
|
|
2
2
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
|
|
@@ -12,14 +13,16 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
12
13
|
committee: undefined,
|
|
13
14
|
seed: 0n,
|
|
14
15
|
epoch: EpochNumber.ZERO,
|
|
16
|
+
isEscapeHatchOpen: false,
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
getEpochAndSlotNow(): EpochAndSlot {
|
|
20
|
+
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
19
21
|
return {
|
|
20
22
|
epoch: EpochNumber.ZERO,
|
|
21
23
|
slot: SlotNumber(0),
|
|
22
24
|
ts: 0n,
|
|
25
|
+
nowMs: 0n,
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -40,18 +43,11 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
40
43
|
return 0n;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
nextProposer: EthAddress | undefined;
|
|
46
|
-
currentSlot: SlotNumber;
|
|
47
|
-
nextSlot: SlotNumber;
|
|
48
|
-
}> {
|
|
49
|
-
return Promise.resolve({
|
|
50
|
-
currentProposer: undefined,
|
|
51
|
-
nextProposer: undefined,
|
|
46
|
+
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
47
|
+
return {
|
|
52
48
|
currentSlot: SlotNumber(0),
|
|
53
49
|
nextSlot: SlotNumber(0),
|
|
54
|
-
}
|
|
50
|
+
};
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
|
|
@@ -69,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
69
65
|
filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
|
|
70
66
|
return Promise.resolve([]);
|
|
71
67
|
}
|
|
68
|
+
|
|
69
|
+
getL1Constants(): L1RollupConstants {
|
|
70
|
+
return EmptyL1RollupConstants;
|
|
71
|
+
}
|
|
72
72
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import type {
|
|
4
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import type {
|
|
6
6
|
MerkleTreeReadOperations,
|
|
7
7
|
MerkleTreeWriteOperations,
|
|
@@ -23,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
|
|
|
23
23
|
return new this(nativeWorldStateService);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public async handleL2Block(block:
|
|
26
|
+
public async handleL2Block(block: L2Block) {
|
|
27
27
|
await this.nativeWorldStateService.handleL2BlockAndMessages(
|
|
28
28
|
block,
|
|
29
29
|
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
|
package/src/txe_session.ts
CHANGED
|
@@ -3,10 +3,13 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
7
7
|
import {
|
|
8
8
|
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
9
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
|
+
JobCoordinator,
|
|
10
13
|
NoteService,
|
|
11
14
|
NoteStore,
|
|
12
15
|
PrivateEventStore,
|
|
@@ -43,15 +46,15 @@ import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
|
43
46
|
|
|
44
47
|
import { z } from 'zod';
|
|
45
48
|
|
|
46
|
-
import { DEFAULT_ADDRESS
|
|
49
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
47
50
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
48
51
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
49
52
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
50
53
|
import { RPCTranslator } from './rpc_translator.js';
|
|
54
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
51
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
52
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
53
57
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
54
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
55
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
56
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
57
60
|
|
|
@@ -74,7 +77,6 @@ type SessionState =
|
|
|
74
77
|
| {
|
|
75
78
|
name: 'PRIVATE';
|
|
76
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
77
|
-
protocolNullifier: Fr;
|
|
78
80
|
noteCache: ExecutionNoteCache;
|
|
79
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
80
82
|
}
|
|
@@ -129,7 +131,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
131
|
| IPrivateExecutionOracle
|
|
130
132
|
| IAvmExecutionOracle
|
|
131
133
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
134
|
+
private contractStore: ContractStore,
|
|
133
135
|
private noteStore: NoteStore,
|
|
134
136
|
private keyStore: KeyStore,
|
|
135
137
|
private addressStore: AddressStore,
|
|
@@ -139,18 +141,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
139
141
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
140
142
|
private capsuleStore: CapsuleStore,
|
|
141
143
|
private privateEventStore: PrivateEventStore,
|
|
144
|
+
private jobCoordinator: JobCoordinator,
|
|
145
|
+
private currentJobId: string,
|
|
142
146
|
private chainId: Fr,
|
|
143
147
|
private version: Fr,
|
|
144
148
|
private nextBlockTimestamp: bigint,
|
|
145
149
|
) {}
|
|
146
150
|
|
|
147
|
-
static async init(
|
|
151
|
+
static async init(contractStore: ContractStore) {
|
|
148
152
|
const store = await openTmpStore('txe-session');
|
|
149
153
|
|
|
150
154
|
const addressStore = new AddressStore(store);
|
|
151
155
|
const privateEventStore = new PrivateEventStore(store);
|
|
152
|
-
const
|
|
153
|
-
const noteStore = await NoteStore.create(store);
|
|
156
|
+
const noteStore = new NoteStore(store);
|
|
154
157
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
155
158
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
156
159
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -158,18 +161,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
158
161
|
const keyStore = new KeyStore(store);
|
|
159
162
|
const accountStore = new TXEAccountStore(store);
|
|
160
163
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
// Create job coordinator and register staged stores
|
|
165
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
166
|
+
jobCoordinator.registerStores([
|
|
167
|
+
capsuleStore,
|
|
168
|
+
senderTaggingStore,
|
|
169
|
+
recipientTaggingStore,
|
|
170
|
+
privateEventStore,
|
|
171
|
+
noteStore,
|
|
172
|
+
]);
|
|
166
173
|
|
|
167
|
-
const
|
|
174
|
+
const archiver = new TXEArchiver(store);
|
|
175
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
176
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
168
177
|
|
|
169
178
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
170
179
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
171
180
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
172
181
|
|
|
182
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
183
|
+
|
|
173
184
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
185
|
stateMachine,
|
|
175
186
|
contractStore,
|
|
@@ -182,6 +193,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
182
193
|
senderAddressBookStore,
|
|
183
194
|
capsuleStore,
|
|
184
195
|
privateEventStore,
|
|
196
|
+
initialJobId,
|
|
185
197
|
nextBlockTimestamp,
|
|
186
198
|
version,
|
|
187
199
|
chainId,
|
|
@@ -203,6 +215,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
203
215
|
senderAddressBookStore,
|
|
204
216
|
capsuleStore,
|
|
205
217
|
privateEventStore,
|
|
218
|
+
jobCoordinator,
|
|
219
|
+
initialJobId,
|
|
206
220
|
version,
|
|
207
221
|
chainId,
|
|
208
222
|
nextBlockTimestamp,
|
|
@@ -262,6 +276,10 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
278
|
|
|
279
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
280
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
281
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
282
|
+
|
|
265
283
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
266
284
|
this.stateMachine,
|
|
267
285
|
this.contractStore,
|
|
@@ -274,6 +292,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
274
292
|
this.senderAddressBookStore,
|
|
275
293
|
this.capsuleStore,
|
|
276
294
|
this.privateEventStore,
|
|
295
|
+
this.currentJobId,
|
|
277
296
|
this.nextBlockTimestamp,
|
|
278
297
|
this.version,
|
|
279
298
|
this.chainId,
|
|
@@ -290,16 +309,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
290
309
|
): Promise<PrivateContextInputs> {
|
|
291
310
|
this.exitTopLevelState();
|
|
292
311
|
|
|
293
|
-
await new NoteService(
|
|
294
|
-
this.noteStore,
|
|
295
|
-
this.stateMachine.node,
|
|
296
|
-
this.stateMachine.anchorBlockStore,
|
|
297
|
-
).syncNoteNullifiers(contractAddress);
|
|
298
|
-
|
|
299
312
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
300
313
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
301
314
|
// a single transaction with the effects of what was done in the test.
|
|
302
315
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
316
|
+
|
|
317
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
318
|
+
contractAddress,
|
|
319
|
+
'ALL_SCOPES',
|
|
320
|
+
);
|
|
303
321
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
304
322
|
|
|
305
323
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -315,37 +333,38 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
315
333
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
316
334
|
|
|
317
335
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
318
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
319
|
-
Fr.ZERO,
|
|
320
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
321
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
322
|
-
anchorBlock!,
|
|
336
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
337
|
+
argsHash: Fr.ZERO,
|
|
338
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
339
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
340
|
+
anchorBlockHeader: anchorBlock!,
|
|
323
341
|
utilityExecutor,
|
|
324
|
-
[],
|
|
325
|
-
[],
|
|
326
|
-
new HashedValuesCache(),
|
|
342
|
+
authWitnesses: [],
|
|
343
|
+
capsules: [],
|
|
344
|
+
executionCache: new HashedValuesCache(),
|
|
327
345
|
noteCache,
|
|
328
346
|
taggingIndexCache,
|
|
329
|
-
this.contractStore,
|
|
330
|
-
this.noteStore,
|
|
331
|
-
this.keyStore,
|
|
332
|
-
this.addressStore,
|
|
333
|
-
this.stateMachine.node,
|
|
334
|
-
this.
|
|
335
|
-
this.
|
|
336
|
-
this.
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
340
|
-
|
|
341
|
-
|
|
347
|
+
contractStore: this.contractStore,
|
|
348
|
+
noteStore: this.noteStore,
|
|
349
|
+
keyStore: this.keyStore,
|
|
350
|
+
addressStore: this.addressStore,
|
|
351
|
+
aztecNode: this.stateMachine.node,
|
|
352
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
353
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
354
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
355
|
+
capsuleStore: this.capsuleStore,
|
|
356
|
+
privateEventStore: this.privateEventStore,
|
|
357
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
358
|
+
jobId: this.currentJobId,
|
|
359
|
+
scopes: 'ALL_SCOPES',
|
|
360
|
+
});
|
|
342
361
|
|
|
343
362
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
344
363
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
345
364
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
346
365
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
347
366
|
// execution finishes.
|
|
348
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
367
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
349
368
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
350
369
|
|
|
351
370
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -378,6 +397,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
378
397
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
379
398
|
this.exitTopLevelState();
|
|
380
399
|
|
|
400
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
401
|
+
|
|
381
402
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
382
403
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
383
404
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
@@ -386,28 +407,27 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
386
407
|
await new NoteService(
|
|
387
408
|
this.noteStore,
|
|
388
409
|
this.stateMachine.node,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
410
|
+
anchorBlockHeader,
|
|
411
|
+
this.currentJobId,
|
|
412
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
393
413
|
|
|
394
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
414
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
395
415
|
contractAddress,
|
|
396
|
-
[],
|
|
397
|
-
[],
|
|
416
|
+
authWitnesses: [],
|
|
417
|
+
capsules: [],
|
|
398
418
|
anchorBlockHeader,
|
|
399
|
-
this.contractStore,
|
|
400
|
-
this.noteStore,
|
|
401
|
-
this.keyStore,
|
|
402
|
-
this.addressStore,
|
|
403
|
-
this.stateMachine.node,
|
|
404
|
-
this.
|
|
405
|
-
this.
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
);
|
|
419
|
+
contractStore: this.contractStore,
|
|
420
|
+
noteStore: this.noteStore,
|
|
421
|
+
keyStore: this.keyStore,
|
|
422
|
+
addressStore: this.addressStore,
|
|
423
|
+
aztecNode: this.stateMachine.node,
|
|
424
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
425
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
426
|
+
capsuleStore: this.capsuleStore,
|
|
427
|
+
privateEventStore: this.privateEventStore,
|
|
428
|
+
jobId: this.currentJobId,
|
|
429
|
+
scopes: 'ALL_SCOPES',
|
|
430
|
+
});
|
|
411
431
|
|
|
412
432
|
this.state = { name: 'UTILITY' };
|
|
413
433
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -442,11 +462,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
442
462
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
443
463
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
444
464
|
|
|
445
|
-
const txEffect = await makeTxEffect(
|
|
446
|
-
this.state.noteCache,
|
|
447
|
-
this.state.protocolNullifier,
|
|
448
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
449
|
-
);
|
|
465
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
450
466
|
|
|
451
467
|
// We build a block holding just this transaction
|
|
452
468
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
@@ -479,30 +495,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
479
495
|
}
|
|
480
496
|
|
|
481
497
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
482
|
-
return async (call: FunctionCall) => {
|
|
498
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
483
499
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
484
500
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
485
501
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
486
502
|
}
|
|
487
503
|
|
|
488
504
|
try {
|
|
489
|
-
const oracle = new UtilityExecutionOracle(
|
|
490
|
-
call.to,
|
|
491
|
-
[],
|
|
492
|
-
[],
|
|
493
|
-
anchorBlock!,
|
|
494
|
-
this.contractStore,
|
|
495
|
-
this.noteStore,
|
|
496
|
-
this.keyStore,
|
|
497
|
-
this.addressStore,
|
|
498
|
-
this.stateMachine.node,
|
|
499
|
-
this.
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
this.
|
|
503
|
-
this.
|
|
504
|
-
|
|
505
|
-
);
|
|
505
|
+
const oracle = new UtilityExecutionOracle({
|
|
506
|
+
contractAddress: call.to,
|
|
507
|
+
authWitnesses: [],
|
|
508
|
+
capsules: [],
|
|
509
|
+
anchorBlockHeader: anchorBlock!,
|
|
510
|
+
contractStore: this.contractStore,
|
|
511
|
+
noteStore: this.noteStore,
|
|
512
|
+
keyStore: this.keyStore,
|
|
513
|
+
addressStore: this.addressStore,
|
|
514
|
+
aztecNode: this.stateMachine.node,
|
|
515
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
516
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
517
|
+
capsuleStore: this.capsuleStore,
|
|
518
|
+
privateEventStore: this.privateEventStore,
|
|
519
|
+
jobId: this.currentJobId,
|
|
520
|
+
scopes,
|
|
521
|
+
});
|
|
506
522
|
await new WASMSimulator()
|
|
507
523
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
508
524
|
.catch((err: Error) => {
|