@aztec/simulator 0.55.1 → 0.56.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/avm/avm_execution_environment.d.ts +0 -8
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +1 -19
- package/dest/avm/avm_gas.d.ts +2 -2
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +31 -115
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +35 -7
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +25 -11
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -6
- package/dest/avm/bytecode_utils.d.ts +1 -2
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.js +3 -17
- package/dest/avm/fixtures/index.d.ts +4 -16
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +9 -25
- package/dest/avm/journal/index.d.ts +0 -1
- package/dest/avm/journal/index.d.ts.map +1 -1
- package/dest/avm/journal/index.js +1 -2
- package/dest/avm/journal/journal.d.ts +4 -4
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +14 -13
- package/dest/avm/opcodes/bitwise.d.ts +10 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +17 -11
- package/dest/avm/opcodes/commitment.js +2 -2
- package/dest/avm/opcodes/comparators.js +2 -2
- package/dest/avm/opcodes/conversion.d.ts +3 -2
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +18 -11
- package/dest/avm/opcodes/environment_getters.d.ts +27 -63
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +75 -80
- package/dest/avm/opcodes/hashing.d.ts +7 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +40 -24
- package/dest/avm/opcodes/index.d.ts +3 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +4 -1
- package/dest/avm/opcodes/instruction_impl.d.ts +0 -26
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +1 -51
- package/dest/avm/opcodes/memory.d.ts +7 -2
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +23 -6
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +7 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -24
- package/dest/avm/serialization/instruction_serialization.d.ts +48 -60
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +50 -63
- package/dest/avm/test_utils.d.ts +8 -8
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +15 -15
- package/dest/client/simulator.d.ts +1 -1
- package/dest/client/test_utils.d.ts.map +1 -1
- package/dest/client/test_utils.js +12 -6
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/public/enqueued_call_simulator.d.ts +43 -0
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -0
- package/dest/public/enqueued_call_simulator.js +155 -0
- package/dest/public/enqueued_calls_processor.d.ts +44 -0
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -0
- package/dest/public/enqueued_calls_processor.js +218 -0
- package/dest/public/execution.d.ts +4 -9
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +5 -10
- package/dest/public/executor.d.ts +3 -5
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +5 -9
- package/dest/public/hints_builder.d.ts +4 -3
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +4 -4
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +3 -3
- package/dest/public/public_db_sources.d.ts +17 -24
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +58 -65
- package/dest/public/public_kernel.d.ts +3 -9
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +13 -40
- package/dest/public/public_kernel_circuit_simulator.d.ts +5 -11
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.d.ts +19 -0
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_tail_simulator.js +45 -0
- package/dest/public/public_processor.d.ts +8 -5
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +31 -48
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +4 -8
- package/package.json +9 -9
- package/src/avm/avm_execution_environment.ts +1 -21
- package/src/avm/avm_gas.ts +30 -114
- package/src/avm/avm_machine_state.ts +5 -5
- package/src/avm/avm_memory_types.ts +31 -9
- package/src/avm/avm_simulator.ts +4 -5
- package/src/avm/bytecode_utils.ts +2 -17
- package/src/avm/fixtures/index.ts +12 -44
- package/src/avm/journal/index.ts +0 -1
- package/src/avm/journal/journal.ts +13 -18
- package/src/avm/opcodes/bitwise.ts +14 -10
- package/src/avm/opcodes/commitment.ts +1 -1
- package/src/avm/opcodes/comparators.ts +2 -2
- package/src/avm/opcodes/conversion.ts +19 -10
- package/src/avm/opcodes/environment_getters.ts +72 -99
- package/src/avm/opcodes/hashing.ts +47 -22
- package/src/avm/opcodes/index.ts +3 -0
- package/src/avm/opcodes/instruction_impl.ts +0 -62
- package/src/avm/opcodes/memory.ts +20 -6
- package/src/avm/opcodes/multi_scalar_mul.ts +6 -6
- package/src/avm/serialization/bytecode_serialization.ts +11 -33
- package/src/avm/serialization/instruction_serialization.ts +5 -18
- package/src/avm/test_utils.ts +20 -16
- package/src/client/test_utils.ts +36 -9
- package/src/client/unconstrained_execution.ts +3 -8
- package/src/public/enqueued_call_simulator.ts +336 -0
- package/src/public/enqueued_calls_processor.ts +388 -0
- package/src/public/execution.ts +5 -12
- package/src/public/executor.ts +4 -12
- package/src/public/hints_builder.ts +14 -12
- package/src/public/index.ts +3 -2
- package/src/public/public_db_sources.ts +62 -67
- package/src/public/public_kernel.ts +15 -49
- package/src/public/public_kernel_circuit_simulator.ts +6 -10
- package/src/public/public_kernel_tail_simulator.ts +106 -0
- package/src/public/public_processor.ts +61 -86
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/side_effect_trace.ts +5 -12
- package/dest/avm/journal/host_storage.d.ts +0 -13
- package/dest/avm/journal/host_storage.d.ts.map +0 -1
- package/dest/avm/journal/host_storage.js +0 -13
- package/dest/avm/opcodes/context_getters.d.ts +0 -15
- package/dest/avm/opcodes/context_getters.d.ts.map +0 -1
- package/dest/avm/opcodes/context_getters.js +0 -19
- package/dest/public/abstract_phase_manager.d.ts +0 -93
- package/dest/public/abstract_phase_manager.d.ts.map +0 -1
- package/dest/public/abstract_phase_manager.js +0 -285
- package/dest/public/app_logic_phase_manager.d.ts +0 -25
- package/dest/public/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/public/app_logic_phase_manager.js +0 -52
- package/dest/public/phase_manager_factory.d.ts +0 -18
- package/dest/public/phase_manager_factory.d.ts.map +0 -1
- package/dest/public/phase_manager_factory.js +0 -56
- package/dest/public/setup_phase_manager.d.ts +0 -25
- package/dest/public/setup_phase_manager.d.ts.map +0 -1
- package/dest/public/setup_phase_manager.js +0 -39
- package/dest/public/tail_phase_manager.d.ts +0 -23
- package/dest/public/tail_phase_manager.d.ts.map +0 -1
- package/dest/public/tail_phase_manager.js +0 -50
- package/dest/public/teardown_phase_manager.d.ts +0 -27
- package/dest/public/teardown_phase_manager.d.ts.map +0 -1
- package/dest/public/teardown_phase_manager.js +0 -56
- package/src/avm/journal/host_storage.ts +0 -14
- package/src/avm/opcodes/context_getters.ts +0 -23
- package/src/public/abstract_phase_manager.ts +0 -522
- package/src/public/app_logic_phase_manager.ts +0 -81
- package/src/public/phase_manager_factory.ts +0 -126
- package/src/public/setup_phase_manager.ts +0 -61
- package/src/public/tail_phase_manager.ts +0 -127
- package/src/public/teardown_phase_manager.ts +0 -86
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { PublicKernelType, type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
4
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
5
|
-
|
|
6
|
-
import { type AbstractPhaseManager } from './abstract_phase_manager.js';
|
|
7
|
-
import { AppLogicPhaseManager } from './app_logic_phase_manager.js';
|
|
8
|
-
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
9
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
10
|
-
import { SetupPhaseManager } from './setup_phase_manager.js';
|
|
11
|
-
import { TailPhaseManager } from './tail_phase_manager.js';
|
|
12
|
-
import { TeardownPhaseManager } from './teardown_phase_manager.js';
|
|
13
|
-
|
|
14
|
-
export class PhaseDidNotChangeError extends Error {
|
|
15
|
-
constructor(phase: PublicKernelType) {
|
|
16
|
-
super(`Tried to advance the phase from [${phase}] when the circuit still needs [${phase}]`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class CannotTransitionToSetupError extends Error {
|
|
21
|
-
constructor() {
|
|
22
|
-
super('Cannot transition to setup phase');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class PhaseManagerFactory {
|
|
27
|
-
public static phaseFromTx(
|
|
28
|
-
tx: Tx,
|
|
29
|
-
db: MerkleTreeOperations,
|
|
30
|
-
publicExecutor: PublicExecutor,
|
|
31
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
32
|
-
globalVariables: GlobalVariables,
|
|
33
|
-
historicalHeader: Header,
|
|
34
|
-
publicContractsDB: ContractsDataSourcePublicDB,
|
|
35
|
-
publicStateDB: PublicStateDB,
|
|
36
|
-
): AbstractPhaseManager | undefined {
|
|
37
|
-
const data = tx.data.forPublic!;
|
|
38
|
-
if (data.needsSetup) {
|
|
39
|
-
return new SetupPhaseManager(
|
|
40
|
-
db,
|
|
41
|
-
publicExecutor,
|
|
42
|
-
publicKernel,
|
|
43
|
-
globalVariables,
|
|
44
|
-
historicalHeader,
|
|
45
|
-
publicContractsDB,
|
|
46
|
-
publicStateDB,
|
|
47
|
-
);
|
|
48
|
-
} else if (data.needsAppLogic) {
|
|
49
|
-
return new AppLogicPhaseManager(
|
|
50
|
-
db,
|
|
51
|
-
publicExecutor,
|
|
52
|
-
publicKernel,
|
|
53
|
-
globalVariables,
|
|
54
|
-
historicalHeader,
|
|
55
|
-
publicContractsDB,
|
|
56
|
-
publicStateDB,
|
|
57
|
-
);
|
|
58
|
-
} else if (data.needsTeardown) {
|
|
59
|
-
return new TeardownPhaseManager(
|
|
60
|
-
db,
|
|
61
|
-
publicExecutor,
|
|
62
|
-
publicKernel,
|
|
63
|
-
globalVariables,
|
|
64
|
-
historicalHeader,
|
|
65
|
-
publicContractsDB,
|
|
66
|
-
publicStateDB,
|
|
67
|
-
);
|
|
68
|
-
} else {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public static phaseFromOutput(
|
|
74
|
-
output: PublicKernelCircuitPublicInputs,
|
|
75
|
-
currentPhaseManager: AbstractPhaseManager,
|
|
76
|
-
db: MerkleTreeOperations,
|
|
77
|
-
publicExecutor: PublicExecutor,
|
|
78
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
79
|
-
globalVariables: GlobalVariables,
|
|
80
|
-
historicalHeader: Header,
|
|
81
|
-
publicContractsDB: ContractsDataSourcePublicDB,
|
|
82
|
-
publicStateDB: PublicStateDB,
|
|
83
|
-
): AbstractPhaseManager | undefined {
|
|
84
|
-
if (output.needsSetup) {
|
|
85
|
-
throw new CannotTransitionToSetupError();
|
|
86
|
-
} else if (output.needsAppLogic) {
|
|
87
|
-
if (currentPhaseManager.phase === PublicKernelType.APP_LOGIC) {
|
|
88
|
-
throw new PhaseDidNotChangeError(currentPhaseManager.phase);
|
|
89
|
-
}
|
|
90
|
-
return new AppLogicPhaseManager(
|
|
91
|
-
db,
|
|
92
|
-
publicExecutor,
|
|
93
|
-
publicKernel,
|
|
94
|
-
globalVariables,
|
|
95
|
-
historicalHeader,
|
|
96
|
-
publicContractsDB,
|
|
97
|
-
publicStateDB,
|
|
98
|
-
);
|
|
99
|
-
} else if (output.needsTeardown) {
|
|
100
|
-
if (currentPhaseManager.phase === PublicKernelType.TEARDOWN) {
|
|
101
|
-
throw new PhaseDidNotChangeError(currentPhaseManager.phase);
|
|
102
|
-
}
|
|
103
|
-
return new TeardownPhaseManager(
|
|
104
|
-
db,
|
|
105
|
-
publicExecutor,
|
|
106
|
-
publicKernel,
|
|
107
|
-
globalVariables,
|
|
108
|
-
historicalHeader,
|
|
109
|
-
publicContractsDB,
|
|
110
|
-
publicStateDB,
|
|
111
|
-
);
|
|
112
|
-
} else if (currentPhaseManager.phase !== PublicKernelType.TAIL) {
|
|
113
|
-
return new TailPhaseManager(
|
|
114
|
-
db,
|
|
115
|
-
publicExecutor,
|
|
116
|
-
publicKernel,
|
|
117
|
-
globalVariables,
|
|
118
|
-
historicalHeader,
|
|
119
|
-
publicContractsDB,
|
|
120
|
-
publicStateDB,
|
|
121
|
-
);
|
|
122
|
-
} else {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PublicKernelType, type PublicProvingRequest, type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
-
import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
|
|
4
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
5
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
6
|
-
|
|
7
|
-
import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
8
|
-
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
9
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The phase manager responsible for performing the fee preparation phase.
|
|
13
|
-
*/
|
|
14
|
-
export class SetupPhaseManager extends AbstractPhaseManager {
|
|
15
|
-
constructor(
|
|
16
|
-
db: MerkleTreeOperations,
|
|
17
|
-
publicExecutor: PublicExecutor,
|
|
18
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
19
|
-
globalVariables: GlobalVariables,
|
|
20
|
-
historicalHeader: Header,
|
|
21
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
22
|
-
protected publicStateDB: PublicStateDB,
|
|
23
|
-
phase: PublicKernelType = PublicKernelType.SETUP,
|
|
24
|
-
) {
|
|
25
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
override async handle(
|
|
29
|
-
tx: Tx,
|
|
30
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
31
|
-
previousCircuit: ProtocolArtifact,
|
|
32
|
-
) {
|
|
33
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
34
|
-
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
35
|
-
// if so, this should only add contracts that were deployed during private app logic.
|
|
36
|
-
await this.publicContractsDB.addNewContracts(tx);
|
|
37
|
-
const { publicProvingInformation, kernelOutput, lastKernelArtifact, newUnencryptedLogs, revertReason, gasUsed } =
|
|
38
|
-
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousCircuit).catch(
|
|
39
|
-
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
40
|
-
async err => {
|
|
41
|
-
await this.publicStateDB.rollbackToCommit();
|
|
42
|
-
throw err;
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
46
|
-
await this.publicStateDB.checkpoint();
|
|
47
|
-
|
|
48
|
-
// Return a list of setup proving requests
|
|
49
|
-
const publicProvingRequests: PublicProvingRequest[] = publicProvingInformation.map(info => {
|
|
50
|
-
return makeAvmProvingRequest(info, PublicKernelType.SETUP);
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
publicProvingRequests,
|
|
54
|
-
publicKernelOutput: kernelOutput,
|
|
55
|
-
lastKernelArtifact,
|
|
56
|
-
revertReason,
|
|
57
|
-
returnValues: [],
|
|
58
|
-
gasUsed,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type GlobalVariables,
|
|
4
|
-
type Header,
|
|
5
|
-
type KernelCircuitPublicInputs,
|
|
6
|
-
MAX_NULLIFIERS_PER_TX,
|
|
7
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
8
|
-
type PublicKernelCircuitPublicInputs,
|
|
9
|
-
PublicKernelTailCircuitPrivateInputs,
|
|
10
|
-
mergeAccumulatedData,
|
|
11
|
-
} from '@aztec/circuits.js';
|
|
12
|
-
import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
|
|
13
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
14
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
15
|
-
|
|
16
|
-
import { AbstractPhaseManager } from './abstract_phase_manager.js';
|
|
17
|
-
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
18
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
19
|
-
|
|
20
|
-
export class TailPhaseManager extends AbstractPhaseManager {
|
|
21
|
-
constructor(
|
|
22
|
-
db: MerkleTreeOperations,
|
|
23
|
-
publicExecutor: PublicExecutor,
|
|
24
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
25
|
-
globalVariables: GlobalVariables,
|
|
26
|
-
historicalHeader: Header,
|
|
27
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
28
|
-
protected publicStateDB: PublicStateDB,
|
|
29
|
-
phase: PublicKernelType = PublicKernelType.TAIL,
|
|
30
|
-
) {
|
|
31
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
override async handle(
|
|
35
|
-
tx: Tx,
|
|
36
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
37
|
-
previousKernelArtifact: ProtocolArtifact,
|
|
38
|
-
) {
|
|
39
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
40
|
-
const [inputs, finalKernelOutput] = await this.simulate(previousPublicKernelOutput, previousKernelArtifact).catch(
|
|
41
|
-
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
42
|
-
async err => {
|
|
43
|
-
await this.publicStateDB.rollbackToCommit();
|
|
44
|
-
throw err;
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
// Return a tail proving request
|
|
49
|
-
const kernelRequest: PublicKernelRequest = {
|
|
50
|
-
type: PublicKernelType.TAIL,
|
|
51
|
-
inputs: inputs,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
publicProvingRequests: [kernelRequest],
|
|
56
|
-
publicKernelOutput: previousPublicKernelOutput,
|
|
57
|
-
lastKernelArtifact: 'PublicKernelTailArtifact' as ProtocolArtifact,
|
|
58
|
-
finalKernelOutput,
|
|
59
|
-
returnValues: [],
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private async simulate(
|
|
64
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
65
|
-
previousKernelArtifact: ProtocolArtifact,
|
|
66
|
-
): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
|
|
67
|
-
const inputs = await this.buildPrivateInputs(previousOutput, previousKernelArtifact);
|
|
68
|
-
// We take a deep copy (clone) of these to pass to the prover
|
|
69
|
-
return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private async buildPrivateInputs(
|
|
73
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
74
|
-
previousKernelArtifact: ProtocolArtifact,
|
|
75
|
-
) {
|
|
76
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, previousKernelArtifact);
|
|
77
|
-
|
|
78
|
-
const { validationRequests, endNonRevertibleData: nonRevertibleData, end: revertibleData } = previousOutput;
|
|
79
|
-
|
|
80
|
-
const noteHashReadRequestHints = await this.hintsBuilder.getNoteHashReadRequestsHints(
|
|
81
|
-
validationRequests.noteHashReadRequests,
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const pendingNullifiers = mergeAccumulatedData(
|
|
85
|
-
nonRevertibleData.nullifiers,
|
|
86
|
-
revertibleData.nullifiers,
|
|
87
|
-
MAX_NULLIFIERS_PER_TX,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
|
|
91
|
-
validationRequests.nullifierReadRequests,
|
|
92
|
-
pendingNullifiers,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const nullifierNonExistentReadRequestHints = await this.hintsBuilder.getNullifierNonExistentReadRequestHints(
|
|
96
|
-
validationRequests.nullifierNonExistentReadRequests,
|
|
97
|
-
pendingNullifiers,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const l1ToL2MsgReadRequestHints = await this.hintsBuilder.getL1ToL2MsgReadRequestsHints(
|
|
101
|
-
validationRequests.l1ToL2MsgReadRequests,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const pendingPublicDataWrites = mergeAccumulatedData(
|
|
105
|
-
nonRevertibleData.publicDataUpdateRequests,
|
|
106
|
-
revertibleData.publicDataUpdateRequests,
|
|
107
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const publicDataHints = await this.hintsBuilder.getPublicDataHints(
|
|
111
|
-
validationRequests.publicDataReads,
|
|
112
|
-
pendingPublicDataWrites,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const currentState = await this.db.getStateReference();
|
|
116
|
-
|
|
117
|
-
return new PublicKernelTailCircuitPrivateInputs(
|
|
118
|
-
previousKernel,
|
|
119
|
-
noteHashReadRequestHints,
|
|
120
|
-
nullifierReadRequestHints,
|
|
121
|
-
nullifierNonExistentReadRequestHints,
|
|
122
|
-
l1ToL2MsgReadRequestHints,
|
|
123
|
-
publicDataHints,
|
|
124
|
-
currentState.partial,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { PublicKernelType, type PublicProvingRequest, type Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type Fr,
|
|
4
|
-
type Gas,
|
|
5
|
-
type GlobalVariables,
|
|
6
|
-
type Header,
|
|
7
|
-
type PublicKernelCircuitPublicInputs,
|
|
8
|
-
} from '@aztec/circuits.js';
|
|
9
|
-
import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
|
|
10
|
-
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
11
|
-
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
12
|
-
|
|
13
|
-
import { inspect } from 'util';
|
|
14
|
-
|
|
15
|
-
import { AbstractPhaseManager, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
16
|
-
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
17
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The phase manager responsible for performing the fee preparation phase.
|
|
21
|
-
*/
|
|
22
|
-
export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
23
|
-
constructor(
|
|
24
|
-
db: MerkleTreeOperations,
|
|
25
|
-
publicExecutor: PublicExecutor,
|
|
26
|
-
publicKernel: PublicKernelCircuitSimulator,
|
|
27
|
-
globalVariables: GlobalVariables,
|
|
28
|
-
historicalHeader: Header,
|
|
29
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
30
|
-
protected publicStateDB: PublicStateDB,
|
|
31
|
-
phase: PublicKernelType = PublicKernelType.TEARDOWN,
|
|
32
|
-
) {
|
|
33
|
-
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
override async handle(
|
|
37
|
-
tx: Tx,
|
|
38
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
39
|
-
previousKernelArtifact: ProtocolArtifact,
|
|
40
|
-
) {
|
|
41
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
42
|
-
const { publicProvingInformation, kernelOutput, lastKernelArtifact, newUnencryptedLogs, revertReason, gasUsed } =
|
|
43
|
-
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousKernelArtifact).catch(
|
|
44
|
-
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
45
|
-
async err => {
|
|
46
|
-
await this.publicStateDB.rollbackToCommit();
|
|
47
|
-
throw err;
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
if (revertReason) {
|
|
51
|
-
await this.publicStateDB.rollbackToCheckpoint();
|
|
52
|
-
tx.filterRevertedLogs(kernelOutput);
|
|
53
|
-
} else {
|
|
54
|
-
// TODO(#6464): Should we allow emitting contracts in the public teardown phase?
|
|
55
|
-
// if so, we should insert them here
|
|
56
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Return a list of teardown proving requests
|
|
60
|
-
const publicProvingRequests: PublicProvingRequest[] = publicProvingInformation.map(info => {
|
|
61
|
-
return makeAvmProvingRequest(info, PublicKernelType.TEARDOWN);
|
|
62
|
-
});
|
|
63
|
-
return {
|
|
64
|
-
publicProvingRequests,
|
|
65
|
-
publicKernelOutput: kernelOutput,
|
|
66
|
-
lastKernelArtifact,
|
|
67
|
-
revertReason,
|
|
68
|
-
returnValues: [],
|
|
69
|
-
gasUsed,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
protected override getTransactionFee(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Fr {
|
|
74
|
-
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
75
|
-
const gasFees = this.globalVariables.gasFees;
|
|
76
|
-
// No need to add teardown limits since they are already included in end.gasUsed
|
|
77
|
-
const gasUsed = previousPublicKernelOutput.end.gasUsed.add(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
|
|
78
|
-
const txFee = gasSettings.inclusionFee.add(gasUsed.computeFee(gasFees));
|
|
79
|
-
this.log.debug(`Computed tx fee`, { txFee, gasUsed: inspect(gasUsed), gasFees: inspect(gasFees) });
|
|
80
|
-
return txFee;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
protected override getAvailableGas(tx: Tx, _previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Gas {
|
|
84
|
-
return tx.data.constants.txContext.gasSettings.getTeardownLimits();
|
|
85
|
-
}
|
|
86
|
-
}
|