@aztec/sequencer-client 0.27.2 → 0.28.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 +3 -1
- package/dest/block_builder/index.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.d.ts +10 -5
- package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.js +119 -52
- package/dest/prover/empty.d.ts +13 -1
- package/dest/prover/empty.d.ts.map +1 -1
- package/dest/prover/empty.js +19 -1
- package/dest/prover/index.d.ts +14 -2
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/sequencer/abstract_phase_manager.d.ts +0 -2
- package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/abstract_phase_manager.js +30 -7
- package/dest/sequencer/app_logic_phase_manager.d.ts +0 -2
- package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/app_logic_phase_manager.js +10 -15
- package/dest/sequencer/sequencer.d.ts +4 -1
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +8 -4
- package/dest/sequencer/setup_phase_manager.d.ts +0 -2
- package/dest/sequencer/setup_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/setup_phase_manager.js +8 -12
- package/dest/sequencer/tail_phase_manager.d.ts +0 -2
- package/dest/sequencer/tail_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/tail_phase_manager.js +7 -11
- package/dest/sequencer/teardown_phase_manager.d.ts +0 -2
- package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/teardown_phase_manager.js +8 -12
- package/dest/sequencer/utils.d.ts +8 -0
- package/dest/sequencer/utils.d.ts.map +1 -0
- package/dest/sequencer/utils.js +28 -0
- package/dest/simulator/index.d.ts +13 -1
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/index.js +1 -1
- package/dest/simulator/public_executor.d.ts +6 -3
- package/dest/simulator/public_executor.d.ts.map +1 -1
- package/dest/simulator/public_executor.js +36 -15
- package/dest/simulator/rollup.d.ts +13 -1
- package/dest/simulator/rollup.d.ts.map +1 -1
- package/dest/simulator/rollup.js +24 -2
- package/package.json +13 -13
- package/src/block_builder/index.ts +3 -1
- package/src/block_builder/solo_block_builder.ts +150 -52
- package/src/prover/empty.ts +23 -0
- package/src/prover/index.ts +18 -1
- package/src/sequencer/abstract_phase_manager.ts +37 -8
- package/src/sequencer/app_logic_phase_manager.ts +10 -16
- package/src/sequencer/sequencer.ts +12 -3
- package/src/sequencer/setup_phase_manager.ts +8 -15
- package/src/sequencer/tail_phase_manager.ts +6 -11
- package/src/sequencer/teardown_phase_manager.ts +8 -15
- package/src/sequencer/utils.ts +30 -0
- package/src/simulator/index.ts +15 -0
- package/src/simulator/public_executor.ts +37 -14
- package/src/simulator/rollup.ts +39 -0
|
@@ -7,7 +7,6 @@ import { PublicProver } from '../prover/index.js';
|
|
|
7
7
|
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
8
8
|
import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
9
9
|
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
10
|
-
import { FailedTx } from './processed_tx.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* The phase manager responsible for performing the fee preparation phase.
|
|
@@ -34,21 +33,15 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
|
34
33
|
) {
|
|
35
34
|
this.log(`Processing tx ${tx.getTxHash()}`);
|
|
36
35
|
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
|
|
37
|
-
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof)
|
|
36
|
+
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
|
|
37
|
+
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
38
|
+
async err => {
|
|
39
|
+
await this.publicStateDB.rollbackToCommit();
|
|
40
|
+
throw err;
|
|
41
|
+
},
|
|
42
|
+
);
|
|
38
43
|
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
39
|
-
|
|
40
|
-
// commit the state updates from this transaction
|
|
41
|
-
await this.publicStateDB.commit();
|
|
42
|
-
|
|
44
|
+
await this.publicStateDB.checkpoint();
|
|
43
45
|
return { publicKernelOutput, publicKernelProof, revertReason };
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
async rollback(tx: Tx, err: unknown): Promise<FailedTx> {
|
|
47
|
-
this.log.warn(`Error processing tx ${tx.getTxHash()}: ${err}`);
|
|
48
|
-
await this.publicStateDB.rollback();
|
|
49
|
-
return {
|
|
50
|
-
tx,
|
|
51
|
-
error: err instanceof Error ? err : new Error('Unknown error'),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
47
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Tx } from '@aztec/circuit-types';
|
|
2
|
+
import { CallRequest } from '@aztec/circuits.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Looks at the side effects of a transaction and returns the highest counter
|
|
6
|
+
* @param tx - A transaction
|
|
7
|
+
* @returns The highest side effect counter in the transaction so far
|
|
8
|
+
*/
|
|
9
|
+
export function lastSideEffectCounter(tx: Tx): number {
|
|
10
|
+
const sideEffectCounters = [
|
|
11
|
+
...tx.data.endNonRevertibleData.newNoteHashes,
|
|
12
|
+
...tx.data.endNonRevertibleData.newNullifiers,
|
|
13
|
+
...tx.data.endNonRevertibleData.publicCallStack,
|
|
14
|
+
...tx.data.end.newNoteHashes,
|
|
15
|
+
...tx.data.end.newNullifiers,
|
|
16
|
+
...tx.data.end.publicCallStack,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
let max = 0;
|
|
20
|
+
for (const sideEffect of sideEffectCounters) {
|
|
21
|
+
if (sideEffect instanceof CallRequest) {
|
|
22
|
+
// look at both start and end counters because for enqueued public calls start > 0 while end === 0
|
|
23
|
+
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
|
|
24
|
+
} else {
|
|
25
|
+
max = Math.max(max, sideEffect.counter.toNumber());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return max;
|
|
30
|
+
}
|
package/src/simulator/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseOrMergeRollupPublicInputs,
|
|
3
|
+
BaseParityInputs,
|
|
3
4
|
BaseRollupInputs,
|
|
4
5
|
MergeRollupInputs,
|
|
6
|
+
ParityPublicInputs,
|
|
5
7
|
PublicKernelCircuitPrivateInputs,
|
|
6
8
|
PublicKernelCircuitPublicInputs,
|
|
7
9
|
PublicKernelTailCircuitPrivateInputs,
|
|
10
|
+
RootParityInputs,
|
|
8
11
|
RootRollupInputs,
|
|
9
12
|
RootRollupPublicInputs,
|
|
10
13
|
} from '@aztec/circuits.js';
|
|
@@ -13,6 +16,18 @@ import {
|
|
|
13
16
|
* Circuit simulator for the rollup circuits.
|
|
14
17
|
*/
|
|
15
18
|
export interface RollupSimulator {
|
|
19
|
+
/**
|
|
20
|
+
* Simulates the base parity circuit from its inputs.
|
|
21
|
+
* @param inputs - Inputs to the circuit.
|
|
22
|
+
* @returns The public inputs of the parity circuit.
|
|
23
|
+
*/
|
|
24
|
+
baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs>;
|
|
25
|
+
/**
|
|
26
|
+
* Simulates the root parity circuit from its inputs.
|
|
27
|
+
* @param inputs - Inputs to the circuit.
|
|
28
|
+
* @returns The public inputs of the parity circuit.
|
|
29
|
+
*/
|
|
30
|
+
rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs>;
|
|
16
31
|
/**
|
|
17
32
|
* Simulates the base rollup circuit from its inputs.
|
|
18
33
|
* @param input - Inputs to the circuit.
|
|
@@ -130,8 +130,9 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
130
130
|
* Implements the PublicStateDB using a world-state database.
|
|
131
131
|
*/
|
|
132
132
|
export class WorldStatePublicDB implements PublicStateDB {
|
|
133
|
-
private
|
|
134
|
-
private
|
|
133
|
+
private committedWriteCache: Map<bigint, Fr> = new Map();
|
|
134
|
+
private checkpointedWriteCache: Map<bigint, Fr> = new Map();
|
|
135
|
+
private uncommittedWriteCache: Map<bigint, Fr> = new Map();
|
|
135
136
|
|
|
136
137
|
constructor(private db: MerkleTreeOperations) {}
|
|
137
138
|
|
|
@@ -143,13 +144,17 @@ export class WorldStatePublicDB implements PublicStateDB {
|
|
|
143
144
|
*/
|
|
144
145
|
public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
145
146
|
const leafSlot = computePublicDataTreeLeafSlot(contract, slot).value;
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
return
|
|
147
|
+
const uncommitted = this.uncommittedWriteCache.get(leafSlot);
|
|
148
|
+
if (uncommitted !== undefined) {
|
|
149
|
+
return uncommitted;
|
|
149
150
|
}
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
return
|
|
151
|
+
const checkpointed = this.checkpointedWriteCache.get(leafSlot);
|
|
152
|
+
if (checkpointed !== undefined) {
|
|
153
|
+
return checkpointed;
|
|
154
|
+
}
|
|
155
|
+
const committed = this.committedWriteCache.get(leafSlot);
|
|
156
|
+
if (committed !== undefined) {
|
|
157
|
+
return committed;
|
|
153
158
|
}
|
|
154
159
|
|
|
155
160
|
const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
@@ -173,7 +178,7 @@ export class WorldStatePublicDB implements PublicStateDB {
|
|
|
173
178
|
*/
|
|
174
179
|
public storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<void> {
|
|
175
180
|
const index = computePublicDataTreeLeafSlot(contract, slot).value;
|
|
176
|
-
this.
|
|
181
|
+
this.uncommittedWriteCache.set(index, newValue);
|
|
177
182
|
return Promise.resolve();
|
|
178
183
|
}
|
|
179
184
|
|
|
@@ -182,18 +187,36 @@ export class WorldStatePublicDB implements PublicStateDB {
|
|
|
182
187
|
* @returns Nothing.
|
|
183
188
|
*/
|
|
184
189
|
commit(): Promise<void> {
|
|
185
|
-
for (const [k, v] of this.
|
|
186
|
-
this.
|
|
190
|
+
for (const [k, v] of this.checkpointedWriteCache) {
|
|
191
|
+
this.committedWriteCache.set(k, v);
|
|
192
|
+
}
|
|
193
|
+
// uncommitted writes take precedence over checkpointed writes
|
|
194
|
+
// since they are the most recent
|
|
195
|
+
for (const [k, v] of this.uncommittedWriteCache) {
|
|
196
|
+
this.committedWriteCache.set(k, v);
|
|
187
197
|
}
|
|
188
|
-
return this.
|
|
198
|
+
return this.rollbackToCommit();
|
|
189
199
|
}
|
|
190
200
|
|
|
191
201
|
/**
|
|
192
202
|
* Rollback the pending changes.
|
|
193
203
|
* @returns Nothing.
|
|
194
204
|
*/
|
|
195
|
-
|
|
196
|
-
this.
|
|
205
|
+
async rollbackToCommit(): Promise<void> {
|
|
206
|
+
await this.rollbackToCheckpoint();
|
|
207
|
+
this.checkpointedWriteCache = new Map<bigint, Fr>();
|
|
208
|
+
return Promise.resolve();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
checkpoint(): Promise<void> {
|
|
212
|
+
for (const [k, v] of this.uncommittedWriteCache) {
|
|
213
|
+
this.checkpointedWriteCache.set(k, v);
|
|
214
|
+
}
|
|
215
|
+
return this.rollbackToCheckpoint();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
rollbackToCheckpoint(): Promise<void> {
|
|
219
|
+
this.uncommittedWriteCache = new Map<bigint, Fr>();
|
|
197
220
|
return Promise.resolve();
|
|
198
221
|
}
|
|
199
222
|
}
|
package/src/simulator/rollup.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { CircuitSimulationStats } from '@aztec/circuit-types/stats';
|
|
2
2
|
import {
|
|
3
3
|
BaseOrMergeRollupPublicInputs,
|
|
4
|
+
BaseParityInputs,
|
|
4
5
|
BaseRollupInputs,
|
|
5
6
|
MergeRollupInputs,
|
|
7
|
+
ParityPublicInputs,
|
|
8
|
+
RootParityInputs,
|
|
6
9
|
RootRollupInputs,
|
|
7
10
|
RootRollupPublicInputs,
|
|
8
11
|
} from '@aztec/circuits.js';
|
|
9
12
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
10
13
|
import { elapsed } from '@aztec/foundation/timer';
|
|
11
14
|
import {
|
|
15
|
+
BaseParityArtifact,
|
|
12
16
|
BaseRollupArtifact,
|
|
13
17
|
MergeRollupArtifact,
|
|
18
|
+
RootParityArtifact,
|
|
14
19
|
RootRollupArtifact,
|
|
20
|
+
convertBaseParityInputsToWitnessMap,
|
|
21
|
+
convertBaseParityOutputsFromWitnessMap,
|
|
15
22
|
convertBaseRollupInputsToWitnessMap,
|
|
16
23
|
convertBaseRollupOutputsFromWitnessMap,
|
|
17
24
|
convertMergeRollupInputsToWitnessMap,
|
|
18
25
|
convertMergeRollupOutputsFromWitnessMap,
|
|
26
|
+
convertRootParityInputsToWitnessMap,
|
|
27
|
+
convertRootParityOutputsFromWitnessMap,
|
|
19
28
|
convertRootRollupInputsToWitnessMap,
|
|
20
29
|
convertRootRollupOutputsFromWitnessMap,
|
|
21
30
|
} from '@aztec/noir-protocol-circuits-types';
|
|
@@ -34,6 +43,36 @@ export class RealRollupCircuitSimulator implements RollupSimulator {
|
|
|
34
43
|
|
|
35
44
|
constructor(private simulationProvider: SimulationProvider) {}
|
|
36
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Simulates the base parity circuit from its inputs.
|
|
48
|
+
* @param inputs - Inputs to the circuit.
|
|
49
|
+
* @returns The public inputs of the parity circuit.
|
|
50
|
+
*/
|
|
51
|
+
public async baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs> {
|
|
52
|
+
const witnessMap = convertBaseParityInputsToWitnessMap(inputs);
|
|
53
|
+
|
|
54
|
+
const witness = await this.simulationProvider.simulateCircuit(witnessMap, BaseParityArtifact);
|
|
55
|
+
|
|
56
|
+
const result = convertBaseParityOutputsFromWitnessMap(witness);
|
|
57
|
+
|
|
58
|
+
return Promise.resolve(result);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Simulates the root parity circuit from its inputs.
|
|
63
|
+
* @param inputs - Inputs to the circuit.
|
|
64
|
+
* @returns The public inputs of the parity circuit.
|
|
65
|
+
*/
|
|
66
|
+
public async rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs> {
|
|
67
|
+
const witnessMap = convertRootParityInputsToWitnessMap(inputs);
|
|
68
|
+
|
|
69
|
+
const witness = await this.simulationProvider.simulateCircuit(witnessMap, RootParityArtifact);
|
|
70
|
+
|
|
71
|
+
const result = convertRootParityOutputsFromWitnessMap(witness);
|
|
72
|
+
|
|
73
|
+
return Promise.resolve(result);
|
|
74
|
+
}
|
|
75
|
+
|
|
37
76
|
/**
|
|
38
77
|
* Simulates the base rollup circuit from its inputs.
|
|
39
78
|
* @param input - Inputs to the circuit.
|