@aztec/simulator 0.82.2-alpha-testnet.4 → 0.82.3
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/README.md +6 -0
- package/dest/private/acvm/oracle/oracle.d.ts +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +1 -3
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +9 -5
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -6
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
- package/dest/public/avm/fixtures/index.d.ts +1 -0
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +2 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +8 -10
- package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +23 -3
- package/dest/public/executor_metrics.d.ts +11 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +40 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
- package/dest/public/hinting_db_sources.d.ts +26 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +102 -1
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +26 -16
- package/dest/public/public_processor/public_processor.d.ts +1 -1
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +3 -3
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
- package/dest/public/public_tx_simulator/index.d.ts +3 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +9 -7
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +24 -64
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/test_executor_metrics.d.ts +43 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +158 -0
- package/package.json +14 -14
- package/src/private/acvm/oracle/oracle.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +15 -3
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_simulator.ts +18 -7
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
- package/src/public/avm/fixtures/index.ts +1 -1
- package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
- package/src/public/avm/opcodes/external_calls.ts +3 -0
- package/src/public/avm/opcodes/memory.ts +8 -10
- package/src/public/avm/serialization/instruction_serialization.ts +22 -5
- package/src/public/executor_metrics.ts +54 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
- package/src/public/hinting_db_sources.ts +184 -3
- package/src/public/index.ts +1 -1
- package/src/public/public_db_sources.ts +36 -23
- package/src/public/public_processor/public_processor.ts +4 -4
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +9 -13
- package/src/public/public_tx_simulator/public_tx_simulator.ts +31 -76
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
- package/src/public/test_executor_metrics.ts +222 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { strict as assert } from 'assert';
|
|
2
|
+
import { TaggedMemory } from '../avm_memory_types.js';
|
|
2
3
|
import { BufferCursor } from './buffer_cursor.js';
|
|
3
4
|
/**
|
|
4
5
|
* All AVM opcodes. (Keep in sync with cpp counterpart code avm_opcode.hpp and rs in opcodes.rs).
|
|
@@ -95,6 +96,7 @@ export var OperandType = /*#__PURE__*/ function(OperandType) {
|
|
|
95
96
|
OperandType[OperandType["UINT64"] = 3] = "UINT64";
|
|
96
97
|
OperandType[OperandType["UINT128"] = 4] = "UINT128";
|
|
97
98
|
OperandType[OperandType["FF"] = 5] = "FF";
|
|
99
|
+
OperandType[OperandType["TAG"] = 6] = "TAG";
|
|
98
100
|
return OperandType;
|
|
99
101
|
}({});
|
|
100
102
|
// Specifies how to read and write each operand type.
|
|
@@ -146,6 +148,14 @@ const OPERAND_SPEC = new Map([
|
|
|
146
148
|
readBigInt254BE,
|
|
147
149
|
writeBigInt254BE
|
|
148
150
|
]
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
6,
|
|
154
|
+
[
|
|
155
|
+
1,
|
|
156
|
+
Buffer.prototype.readUint8,
|
|
157
|
+
Buffer.prototype.writeUint8
|
|
158
|
+
]
|
|
149
159
|
]
|
|
150
160
|
]);
|
|
151
161
|
function readBigInt254BE(offset) {
|
|
@@ -190,12 +200,22 @@ function writeBigInt128BE(value) {
|
|
|
190
200
|
if (Buffer.isBuffer(cursor)) {
|
|
191
201
|
cursor = new BufferCursor(cursor);
|
|
192
202
|
}
|
|
193
|
-
for (const
|
|
194
|
-
const opType = op;
|
|
203
|
+
for (const opType of operands){
|
|
195
204
|
const [sizeBytes, reader, _writer] = OPERAND_SPEC.get(opType);
|
|
196
|
-
|
|
205
|
+
const value = reader.call(cursor.buffer(), cursor.position());
|
|
206
|
+
argValues.push(value);
|
|
197
207
|
cursor.advance(sizeBytes);
|
|
198
208
|
}
|
|
209
|
+
// We first want to detect other parsing errors (e.g., instruction size
|
|
210
|
+
// is longer than remaining bytes) first and therefore tag validation is done after completion
|
|
211
|
+
// of parsing above. Order of errors need to match with circuit.
|
|
212
|
+
for(let i = 0; i < operands.length; i++){
|
|
213
|
+
if (operands[i] === 6) {
|
|
214
|
+
// We parsed a single byte (readUInt8()) and therefore value is of number type (not bigint)
|
|
215
|
+
// We need to cast to number because checkIsValidTag expects a number.
|
|
216
|
+
TaggedMemory.checkIsValidTag(Number(argValues[i]) ?? 0);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
199
219
|
return argValues;
|
|
200
220
|
}
|
|
201
221
|
/**
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import type { RevertCode } from '@aztec/stdlib/avm';
|
|
1
2
|
import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
2
|
-
|
|
3
|
+
import type { ExecutorMetricsInterface } from './executor_metrics_interface.js';
|
|
4
|
+
export declare class ExecutorMetrics implements ExecutorMetricsInterface {
|
|
3
5
|
readonly tracer: Tracer;
|
|
4
6
|
private fnCount;
|
|
5
7
|
private fnDuration;
|
|
6
8
|
private manaPerSecond;
|
|
9
|
+
private manaUsed;
|
|
10
|
+
private totalInstructions;
|
|
11
|
+
private txHashing;
|
|
7
12
|
private privateEffectsInsertions;
|
|
8
13
|
constructor(client: TelemetryClient, name?: string);
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
startRecordingTxSimulation(_txLabel: string): void;
|
|
15
|
+
stopRecordingTxSimulation(_txLabel: string, _revertedCode?: RevertCode): void;
|
|
16
|
+
recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
|
|
17
|
+
recordEnqueuedCallSimulationFailure(_fnName: string, _durationMs: number, _manaUsed: number, _totalInstructions: number): void;
|
|
18
|
+
recordTxHashComputation(durationMs: number): void;
|
|
11
19
|
recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
|
|
12
20
|
}
|
|
13
21
|
//# sourceMappingURL=executor_metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,
|
|
1
|
+
{"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,qBAAa,eAAgB,YAAW,wBAAwB;IAC9D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,wBAAwB,CAAY;gBAEhC,MAAM,EAAE,eAAe,EAAE,IAAI,SAAmB;IA6C5D,0BAA0B,CAAC,QAAQ,EAAE,MAAM;IAI3C,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,UAAU;IAItE,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAsB5G,mCAAmC,CACjC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM;IAO5B,uBAAuB,CAAC,UAAU,EAAE,MAAM;IAI1C,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB;CAKxF"}
|
|
@@ -4,6 +4,9 @@ export class ExecutorMetrics {
|
|
|
4
4
|
fnCount;
|
|
5
5
|
fnDuration;
|
|
6
6
|
manaPerSecond;
|
|
7
|
+
manaUsed;
|
|
8
|
+
totalInstructions;
|
|
9
|
+
txHashing;
|
|
7
10
|
privateEffectsInsertions;
|
|
8
11
|
constructor(client, name = 'PublicExecutor'){
|
|
9
12
|
this.tracer = client.getTracer(name);
|
|
@@ -21,19 +24,47 @@ export class ExecutorMetrics {
|
|
|
21
24
|
unit: 'mana/s',
|
|
22
25
|
valueType: ValueType.INT
|
|
23
26
|
});
|
|
24
|
-
this.
|
|
27
|
+
this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED, {
|
|
28
|
+
description: 'Total mana used',
|
|
29
|
+
unit: 'mana',
|
|
30
|
+
valueType: ValueType.INT
|
|
31
|
+
});
|
|
32
|
+
this.totalInstructions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS, {
|
|
33
|
+
description: 'Total number of instructions executed',
|
|
34
|
+
unit: 'instructions',
|
|
35
|
+
valueType: ValueType.INT
|
|
36
|
+
});
|
|
37
|
+
this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING, {
|
|
38
|
+
description: 'Tx hashing time',
|
|
39
|
+
unit: 'ms',
|
|
40
|
+
valueType: ValueType.INT
|
|
41
|
+
});
|
|
42
|
+
this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION, {
|
|
25
43
|
description: 'Private effects insertion time',
|
|
26
44
|
unit: 'us',
|
|
27
45
|
valueType: ValueType.INT
|
|
28
46
|
});
|
|
29
47
|
}
|
|
30
|
-
|
|
48
|
+
startRecordingTxSimulation(_txLabel) {
|
|
49
|
+
// do nothing (unimplemented)
|
|
50
|
+
}
|
|
51
|
+
stopRecordingTxSimulation(_txLabel, _revertedCode) {
|
|
52
|
+
// do nothing (unimplemented)
|
|
53
|
+
}
|
|
54
|
+
recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions) {
|
|
31
55
|
this.fnCount.add(1, {
|
|
32
56
|
[Attributes.OK]: true,
|
|
33
|
-
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
34
|
-
|
|
57
|
+
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
58
|
+
});
|
|
59
|
+
this.manaUsed.record(Math.ceil(manaUsed), {
|
|
60
|
+
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
61
|
+
});
|
|
62
|
+
this.totalInstructions.record(Math.ceil(totalInstructions), {
|
|
63
|
+
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
64
|
+
});
|
|
65
|
+
this.fnDuration.record(Math.ceil(durationMs), {
|
|
66
|
+
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
35
67
|
});
|
|
36
|
-
this.fnDuration.record(Math.ceil(durationMs));
|
|
37
68
|
if (durationMs > 0 && manaUsed > 0) {
|
|
38
69
|
const manaPerSecond = Math.round(manaUsed * 1000 / durationMs);
|
|
39
70
|
this.manaPerSecond.record(manaPerSecond, {
|
|
@@ -41,11 +72,14 @@ export class ExecutorMetrics {
|
|
|
41
72
|
});
|
|
42
73
|
}
|
|
43
74
|
}
|
|
44
|
-
|
|
75
|
+
recordEnqueuedCallSimulationFailure(_fnName, _durationMs, _manaUsed, _totalInstructions) {
|
|
45
76
|
this.fnCount.add(1, {
|
|
46
77
|
[Attributes.OK]: false
|
|
47
78
|
});
|
|
48
79
|
}
|
|
80
|
+
recordTxHashComputation(durationMs) {
|
|
81
|
+
this.txHashing.record(Math.ceil(durationMs));
|
|
82
|
+
}
|
|
49
83
|
recordPrivateEffectsInsertion(durationUs, type) {
|
|
50
84
|
this.privateEffectsInsertions.record(Math.ceil(durationUs), {
|
|
51
85
|
[Attributes.REVERTIBILITY]: type
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RevertCode } from '@aztec/stdlib/avm';
|
|
2
|
+
export interface ExecutorMetricsInterface {
|
|
3
|
+
startRecordingTxSimulation(txLabel: string): void;
|
|
4
|
+
stopRecordingTxSimulation(txLabel: string, revertedCode?: RevertCode): void;
|
|
5
|
+
recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
|
|
6
|
+
recordEnqueuedCallSimulationFailure(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
|
|
7
|
+
recordTxHashComputation(durationMs: number): void;
|
|
8
|
+
recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=executor_metrics_interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor_metrics_interface.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,wBAAwB;IACvC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5E,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpH,mCAAmC,CACjC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,GACxB,IAAI,CAAC;IACR,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAChG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -5,9 +5,10 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server'
|
|
|
5
5
|
import { GlobalVariables, type Tx } from '@aztec/stdlib/tx';
|
|
6
6
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
7
7
|
import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
|
|
9
|
+
import { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
10
10
|
export type TestEnqueuedCall = {
|
|
11
|
+
sender?: AztecAddress;
|
|
11
12
|
address: AztecAddress;
|
|
12
13
|
fnName: string;
|
|
13
14
|
args: any[];
|
|
@@ -21,12 +22,17 @@ export type TestEnqueuedCall = {
|
|
|
21
22
|
*/
|
|
22
23
|
export declare class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
23
24
|
#private;
|
|
24
|
-
private
|
|
25
|
+
private metrics;
|
|
25
26
|
private txCount;
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
private simulator;
|
|
28
|
+
private metricsPrefix?;
|
|
29
|
+
constructor(merkleTree: MerkleTreeWriteOperations, contractDataSource: SimpleContractDataSource, globals?: GlobalVariables, metrics?: TestExecutorMetrics);
|
|
30
|
+
static create(globals?: GlobalVariables, metrics?: TestExecutorMetrics): Promise<PublicTxSimulationTester>;
|
|
31
|
+
setMetricsPrefix(prefix: string): void;
|
|
28
32
|
createTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr): Promise<Tx>;
|
|
29
|
-
simulateTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr,
|
|
33
|
+
simulateTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr, txLabel?: string): Promise<PublicTxResult>;
|
|
34
|
+
simulateTxWithLabel(txLabel: string, sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr): Promise<PublicTxResult>;
|
|
35
|
+
prettyPrintMetrics(): void;
|
|
30
36
|
}
|
|
31
37
|
export declare function defaultGlobals(): GlobalVariables;
|
|
32
38
|
//# sourceMappingURL=public_tx_simulation_tester.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_tx_simulation_tester.d.ts","sourceRoot":"","sources":["../../../src/public/fixtures/public_tx_simulation_tester.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAiC,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"public_tx_simulation_tester.d.ts","sourceR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CAAC,MAAM,EAAE,MAAM;IAIzB,QAAQ,CACnB,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,gBAAgB,EAAO,EACnC,QAAQ,GAAE,gBAAgB,EAAO,EACjC,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,GAC/C,OAAO,CAAC,EAAE,CAAC;IAcD,UAAU,CACrB,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,gBAAgB,EAAO,EACnC,QAAQ,GAAE,gBAAgB,EAAO,EACjC,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,EAChD,OAAO,GAAE,MAAsB,GAC9B,OAAO,CAAC,cAAc,CAAC;IAyBb,mBAAmB,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,EACpB,UAAU,CAAC,EAAE,gBAAgB,EAAE,EAC/B,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAC7B,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,CAAC,EAAE,YAAY,EACvB,cAAc,CAAC,EAAE,EAAE,GAClB,OAAO,CAAC,cAAc,CAAC;IAInB,kBAAkB;CAuB1B;AAED,wBAAgB,cAAc,oBAM7B"}
|
|
@@ -6,47 +6,67 @@ import { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
|
6
6
|
import { GlobalVariables, PublicCallRequestWithCalldata } from '@aztec/stdlib/tx';
|
|
7
7
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
8
8
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
9
|
-
import { getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
|
|
9
|
+
import { DEFAULT_BLOCK_NUMBER, getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
|
|
10
10
|
import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
|
|
11
11
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
12
|
-
import {
|
|
12
|
+
import { MeasuredPublicTxSimulator } from '../public_tx_simulator/measured_public_tx_simulator.js';
|
|
13
|
+
import { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
13
14
|
import { createTxForPublicCalls } from './utils.js';
|
|
14
15
|
const TIMESTAMP = new Fr(99833);
|
|
15
16
|
const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
16
|
-
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
17
17
|
/**
|
|
18
18
|
* A test class that extends the BaseAvmSimulationTester to enable real-app testing of the PublicTxSimulator.
|
|
19
19
|
* It provides an interface for simulating one transaction at a time and maintains state between subsequent
|
|
20
20
|
* transactions.
|
|
21
21
|
*/ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
22
|
-
|
|
22
|
+
metrics;
|
|
23
23
|
txCount;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
simulator;
|
|
25
|
+
metricsPrefix;
|
|
26
|
+
constructor(merkleTree, contractDataSource, globals = defaultGlobals(), metrics = new TestExecutorMetrics()){
|
|
27
|
+
super(contractDataSource, merkleTree), this.metrics = metrics, this.txCount = 0;
|
|
28
|
+
const treesDB = new PublicTreesDB(merkleTree);
|
|
29
|
+
const contractsDB = new PublicContractsDB(contractDataSource);
|
|
30
|
+
this.simulator = new MeasuredPublicTxSimulator(treesDB, contractsDB, globals, /*doMerkleOperations=*/ true, /*skipFeeEnforcement=*/ false, this.metrics);
|
|
26
31
|
}
|
|
27
|
-
static async create() {
|
|
32
|
+
static async create(globals = defaultGlobals(), metrics = new TestExecutorMetrics()) {
|
|
28
33
|
const contractDataSource = new SimpleContractDataSource();
|
|
29
34
|
const merkleTree = await (await NativeWorldStateService.tmp()).fork();
|
|
30
|
-
return new PublicTxSimulationTester(merkleTree, contractDataSource);
|
|
35
|
+
return new PublicTxSimulationTester(merkleTree, contractDataSource, globals, metrics);
|
|
36
|
+
}
|
|
37
|
+
setMetricsPrefix(prefix) {
|
|
38
|
+
this.metricsPrefix = prefix;
|
|
31
39
|
}
|
|
32
40
|
async createTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++)) {
|
|
33
|
-
const setupCallRequests = await asyncMap(setupCalls, (call)=>this.#createPubicCallRequestForCall(call, sender));
|
|
34
|
-
const appCallRequests = await asyncMap(appCalls, (call)=>this.#createPubicCallRequestForCall(call, sender));
|
|
35
|
-
const teardownCallRequest = teardownCall ? await this.#createPubicCallRequestForCall(teardownCall, sender) : undefined;
|
|
41
|
+
const setupCallRequests = await asyncMap(setupCalls, (call)=>this.#createPubicCallRequestForCall(call, call.sender ?? sender));
|
|
42
|
+
const appCallRequests = await asyncMap(appCalls, (call)=>this.#createPubicCallRequestForCall(call, call.sender ?? sender));
|
|
43
|
+
const teardownCallRequest = teardownCall ? await this.#createPubicCallRequestForCall(teardownCall, teardownCall.sender ?? sender) : undefined;
|
|
36
44
|
return createTxForPublicCalls(firstNullifier, setupCallRequests, appCallRequests, teardownCallRequest, feePayer);
|
|
37
45
|
}
|
|
38
|
-
async simulateTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++),
|
|
46
|
+
async simulateTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++), txLabel = 'unlabeledTx') {
|
|
39
47
|
const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier);
|
|
40
48
|
await this.setFeePayerBalance(feePayer);
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const txLabelWithCount = `${txLabel}.${this.txCount - 1}`;
|
|
50
|
+
const fullTxLabel = this.metricsPrefix ? `${this.metricsPrefix}.${txLabelWithCount}` : txLabelWithCount;
|
|
51
|
+
const avmResult = await this.simulator.simulate(tx, fullTxLabel);
|
|
52
|
+
// Something like this is often useful for debugging:
|
|
53
|
+
//if (avmResult.revertReason) {
|
|
54
|
+
// // resolve / enrich revert reason
|
|
55
|
+
// const lastAppCall = appCalls[appCalls.length - 1];
|
|
56
|
+
// const contractArtifact =
|
|
57
|
+
// lastAppCall.contractArtifact || (await this.contractDataSource.getContractArtifact(lastAppCall.address));
|
|
58
|
+
// const fnAbi = getContractFunctionAbi(lastAppCall.fnName, contractArtifact!);
|
|
59
|
+
// const revertReason = resolveAssertionMessageFromRevertData(avmResult.revertReason.revertData, fnAbi!);
|
|
60
|
+
// this.logger.debug(`Revert reason: ${revertReason}`);
|
|
61
|
+
//}
|
|
48
62
|
return avmResult;
|
|
49
63
|
}
|
|
64
|
+
async simulateTxWithLabel(txLabel, sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier) {
|
|
65
|
+
return await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier, txLabel);
|
|
66
|
+
}
|
|
67
|
+
prettyPrintMetrics() {
|
|
68
|
+
this.metrics.prettyPrint();
|
|
69
|
+
}
|
|
50
70
|
async #createPubicCallRequestForCall(call, sender) {
|
|
51
71
|
const address = call.address;
|
|
52
72
|
const contractArtifact = call.contractArtifact || await this.contractDataSource.getContractArtifact(address);
|
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
|
|
2
5
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
6
|
import { type AvmExecutionHints } from '@aztec/stdlib/avm';
|
|
4
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
8
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
6
|
-
import type
|
|
9
|
+
import { type IndexedTreeId, MerkleTreeId, type MerkleTreeLeafType, type SequentialInsertionResult } from '@aztec/stdlib/trees';
|
|
10
|
+
import type { PublicContractsDBInterface } from '../common/db_interfaces.js';
|
|
11
|
+
import { PublicTreesDB } from './public_db_sources.js';
|
|
7
12
|
/**
|
|
8
13
|
* A public contracts database that forwards requests and collects AVM hints.
|
|
9
14
|
*/
|
|
10
15
|
export declare class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
11
16
|
private readonly db;
|
|
12
|
-
|
|
17
|
+
private hints;
|
|
13
18
|
constructor(db: PublicContractsDBInterface, hints: AvmExecutionHints);
|
|
14
19
|
getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
|
|
15
20
|
getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
|
|
16
21
|
getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
|
|
17
22
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
18
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A public trees database that forwards requests and collects AVM hints.
|
|
26
|
+
*/
|
|
27
|
+
export declare class HintingPublicTreesDB extends PublicTreesDB {
|
|
28
|
+
private hints;
|
|
29
|
+
private static readonly log;
|
|
30
|
+
constructor(db: PublicTreesDB, hints: AvmExecutionHints);
|
|
31
|
+
getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
|
|
32
|
+
getPreviousValueIndex<ID extends IndexedTreeId>(treeId: ID, value: bigint): Promise<{
|
|
33
|
+
index: bigint;
|
|
34
|
+
alreadyPresent: boolean;
|
|
35
|
+
} | undefined>;
|
|
36
|
+
getLeafPreimage<ID extends IndexedTreeId>(treeId: ID, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
|
|
37
|
+
getLeafValue<ID extends MerkleTreeId>(treeId: ID, index: bigint): Promise<MerkleTreeLeafType<typeof treeId> | undefined>;
|
|
38
|
+
sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(treeId: ID, leaves: Buffer[]): Promise<SequentialInsertionResult<TreeHeight>>;
|
|
39
|
+
revertCheckpoint(): Promise<void>;
|
|
40
|
+
private getHintKey;
|
|
41
|
+
}
|
|
19
42
|
//# sourceMappingURL=hinting_db_sources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAIL,KAAK,iBAAiB,EAMvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAEL,KAAK,aAAa,EAClB,YAAY,EACZ,KAAK,kBAAkB,EAGvB,KAAK,yBAAyB,EAE/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,qBAAa,wBAAyB,YAAW,0BAA0B;IAC7D,OAAO,CAAC,QAAQ,CAA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,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC;IAenC,gBAAgB,CAAC,UAAU,SAAS,MAAM,EAAE,EAAE,SAAS,aAAa,EACxF,MAAM,EAAE,EAAE,EACV,MAAM,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAgB3B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;YAkCzC,UAAU;CAIzB"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { AvmBytecodeCommitmentHint, AvmContractClassHint, AvmContractInstanceHint, AvmGetLeafPreimageHintNullifierTree, AvmGetLeafPreimageHintPublicDataTree, AvmGetLeafValueHint, AvmGetPreviousValueIndexHint, AvmGetSiblingPathHint } from '@aztec/stdlib/avm';
|
|
4
|
+
import { AppendOnlyTreeSnapshot, MerkleTreeId, getTreeName } from '@aztec/stdlib/trees';
|
|
5
|
+
import { strict as assert } from 'assert';
|
|
6
|
+
import { PublicTreesDB } from './public_db_sources.js';
|
|
2
7
|
/**
|
|
3
8
|
* A public contracts database that forwards requests and collects AVM hints.
|
|
4
9
|
*/ export class HintingPublicContractsDB {
|
|
@@ -34,3 +39,99 @@ import { AvmBytecodeCommitmentHint, AvmContractClassHint, AvmContractInstanceHin
|
|
|
34
39
|
return await this.db.getDebugFunctionName(contractAddress, selector);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A public trees database that forwards requests and collects AVM hints.
|
|
44
|
+
*/ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
45
|
+
hints;
|
|
46
|
+
static log = createLogger('HintingPublicTreesDB');
|
|
47
|
+
constructor(db, hints){
|
|
48
|
+
super(db), this.hints = hints;
|
|
49
|
+
}
|
|
50
|
+
// Getters.
|
|
51
|
+
async getSiblingPath(treeId, index) {
|
|
52
|
+
const path = await super.getSiblingPath(treeId, index);
|
|
53
|
+
const key = await this.getHintKey(treeId);
|
|
54
|
+
this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
|
|
55
|
+
return Promise.resolve(path);
|
|
56
|
+
}
|
|
57
|
+
async getPreviousValueIndex(treeId, value) {
|
|
58
|
+
const result = await super.getPreviousValueIndex(treeId, value);
|
|
59
|
+
if (result === undefined) {
|
|
60
|
+
throw new Error(`getPreviousValueIndex(${getTreeName(treeId)}, ${value}}) returned undefined. Possible wrong tree setup or corrupted state.`);
|
|
61
|
+
}
|
|
62
|
+
const key = await this.getHintKey(treeId);
|
|
63
|
+
this.hints.getPreviousValueIndexHints.push(new AvmGetPreviousValueIndexHint(key, treeId, new Fr(value), result.index, result.alreadyPresent));
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
async getLeafPreimage(treeId, index) {
|
|
67
|
+
const preimage = await super.getLeafPreimage(treeId, index);
|
|
68
|
+
if (preimage) {
|
|
69
|
+
const key = await this.getHintKey(treeId);
|
|
70
|
+
switch(treeId){
|
|
71
|
+
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
72
|
+
this.hints.getLeafPreimageHintsPublicDataTree.push(new AvmGetLeafPreimageHintPublicDataTree(key, index, preimage.asLeaf(), preimage.getNextIndex(), new Fr(preimage.getNextKey())));
|
|
73
|
+
break;
|
|
74
|
+
case MerkleTreeId.NULLIFIER_TREE:
|
|
75
|
+
this.hints.getLeafPreimageHintsNullifierTree.push(new AvmGetLeafPreimageHintNullifierTree(key, index, preimage.asLeaf(), preimage.getNextIndex(), new Fr(preimage.getNextKey())));
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
// Use getLeafValue for the other trees.
|
|
79
|
+
throw new Error('getLeafPreimage only supported for PublicDataTree and NullifierTree!');
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return preimage;
|
|
84
|
+
}
|
|
85
|
+
async getLeafValue(treeId, index) {
|
|
86
|
+
// Use getLeafPreimage for PublicDataTree and NullifierTree.
|
|
87
|
+
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
88
|
+
const value = await super.getLeafValue(treeId, index);
|
|
89
|
+
if (value) {
|
|
90
|
+
const key = await this.getHintKey(treeId);
|
|
91
|
+
// We can cast to Fr because we know the type of the tree.
|
|
92
|
+
this.hints.getLeafValueHints.push(new AvmGetLeafValueHint(key, treeId, index, value));
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
// State modification.
|
|
97
|
+
async sequentialInsert(treeId, leaves) {
|
|
98
|
+
HintingPublicTreesDB.log.debug('sequentialInsert not hinted yet!');
|
|
99
|
+
const beforeState = await this.getHintKey(treeId);
|
|
100
|
+
const result = await super.sequentialInsert(treeId, leaves);
|
|
101
|
+
const afterState = await this.getHintKey(treeId);
|
|
102
|
+
HintingPublicTreesDB.log.debug(`Evolved tree state (${getTreeName(treeId)}): ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`);
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
async revertCheckpoint() {
|
|
106
|
+
HintingPublicTreesDB.log.debug('revertCheckpoint not hinted yet!');
|
|
107
|
+
// TODO(fcarreiro): we probably want to hint on StateReference hash.
|
|
108
|
+
// WARNING: is this enough? we might actually need the number of the checkpoint or similar...
|
|
109
|
+
// We will need to keep a stack of checkpoints on the C++ side.
|
|
110
|
+
const beforeState = {
|
|
111
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
112
|
+
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
113
|
+
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
114
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
115
|
+
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE)
|
|
116
|
+
};
|
|
117
|
+
await super.revertCheckpoint();
|
|
118
|
+
const afterState = {
|
|
119
|
+
[MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
120
|
+
[MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
|
|
121
|
+
[MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
|
|
122
|
+
[MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
|
|
123
|
+
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE)
|
|
124
|
+
};
|
|
125
|
+
HintingPublicTreesDB.log.debug('Evolved tree state:');
|
|
126
|
+
for (const treeId of Object.keys(beforeState)){
|
|
127
|
+
const id = treeId;
|
|
128
|
+
const treeName = getTreeName(id);
|
|
129
|
+
HintingPublicTreesDB.log.debug(`${treeName}: ${beforeState[id].root}, ${beforeState[id].nextAvailableLeafIndex} -> ${afterState[id].root}, ${afterState[id].nextAvailableLeafIndex}.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Private methods.
|
|
133
|
+
async getHintKey(treeId) {
|
|
134
|
+
const treeInfo = await super.getTreeInfo(treeId);
|
|
135
|
+
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
|
|
136
|
+
}
|
|
137
|
+
}
|
package/dest/public/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '../common/db_interfaces.js';
|
|
2
|
-
export * from './public_tx_simulator/
|
|
2
|
+
export * from './public_tx_simulator/index.js';
|
|
3
3
|
export * from './public_db_sources.js';
|
|
4
4
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
5
5
|
export { SideEffectTrace } from './side_effect_trace.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/public/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/public/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC"}
|
package/dest/public/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '../common/db_interfaces.js';
|
|
2
|
-
export * from './public_tx_simulator/
|
|
2
|
+
export * from './public_tx_simulator/index.js';
|
|
3
3
|
export * from './public_db_sources.js';
|
|
4
4
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
5
5
|
export { SideEffectTrace } from './side_effect_trace.js';
|
|
@@ -5,7 +5,7 @@ import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/tre
|
|
|
5
5
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
8
|
-
import type { BatchInsertionResult, IndexedTreeId, MerkleTreeLeafType,
|
|
8
|
+
import type { BatchInsertionResult, IndexedTreeId, MerkleTreeLeafType, MerkleTreeWriteOperations, SequentialInsertionResult, TreeInfo } from '@aztec/stdlib/interfaces/server';
|
|
9
9
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
10
10
|
import type { BlockHeader, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
11
11
|
import type { PublicContractsDBInterface, PublicStateDBInterface } from '../common/db_interfaces.js';
|
|
@@ -126,7 +126,7 @@ declare class ForwardMerkleTree implements MerkleTreeWriteOperations {
|
|
|
126
126
|
* A class that provides access to the merkle trees, and other helper methods.
|
|
127
127
|
*/
|
|
128
128
|
export declare class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInterface {
|
|
129
|
-
db
|
|
129
|
+
private readonly db;
|
|
130
130
|
private logger;
|
|
131
131
|
constructor(db: MerkleTreeWriteOperations);
|
|
132
132
|
/**
|
|
@@ -148,6 +148,5 @@ export declare class PublicTreesDB extends ForwardMerkleTree implements PublicSt
|
|
|
148
148
|
getNoteHash(leafIndex: bigint): Promise<Fr | undefined>;
|
|
149
149
|
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
150
150
|
}
|
|
151
|
-
export declare function readPublicState(db: MerkleTreeReadOperations, contract: AztecAddress, slot: Fr): Promise<Fr>;
|
|
152
151
|
export {};
|
|
153
152
|
//# sourceMappingURL=public_db_sources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/public_db_sources.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,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