@aztec/simulator 0.40.1 → 0.42.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/acvm/acvm.d.ts +2 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +6 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +31 -19
- package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +17 -5
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_execution_environment.d.ts +4 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.d.ts +1 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +67 -73
- package/dest/avm/avm_simulator.d.ts +5 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -4
- package/dest/avm/errors.d.ts +6 -0
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +10 -1
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +15 -3
- package/dest/avm/index.d.ts +2 -0
- package/dest/avm/index.d.ts.map +1 -0
- package/dest/avm/index.js +2 -0
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/journal.d.ts +4 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +10 -11
- package/dest/avm/journal/nullifiers.d.ts +17 -5
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +27 -10
- package/dest/avm/journal/public_storage.d.ts +19 -6
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +30 -12
- package/dest/avm/journal/trace.d.ts +2 -0
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +7 -1
- package/dest/avm/journal/trace_types.d.ts +1 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +6 -7
- package/dest/avm/opcodes/arithmetic.d.ts +1 -7
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -12
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +25 -13
- package/dest/avm/opcodes/instruction.d.ts +1 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +6 -4
- package/dest/avm/opcodes/memory.d.ts +0 -4
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/storage.d.ts +0 -12
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -18
- package/dest/avm/serialization/bytecode_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +30 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +59 -39
- package/dest/client/db_oracle.d.ts +17 -12
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +2 -2
- package/dest/client/execution_result.d.ts +17 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +32 -4
- package/dest/client/private_execution.d.ts +2 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +22 -8
- package/dest/client/simulator.d.ts +0 -16
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +13 -30
- package/dest/client/unconstrained_execution.d.ts +2 -3
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -7
- package/dest/client/view_data_oracle.d.ts +12 -10
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -11
- package/dest/common/index.d.ts +1 -0
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -1
- package/dest/common/return_values.d.ts +11 -0
- package/dest/common/return_values.d.ts.map +1 -0
- package/dest/common/return_values.js +13 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -2
- package/dest/mocks/fixtures.d.ts +15 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -17
- package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
- package/dest/{simulator → providers}/acvm_native.js +13 -14
- package/dest/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/providers/acvm_wasm.js +15 -0
- package/dest/providers/index.d.ts.map +1 -0
- package/dest/{simulator → providers}/index.js +1 -1
- package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
- package/dest/{simulator → providers}/simulation_provider.js +1 -1
- package/dest/public/abstract_phase_manager.d.ts +43 -42
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +81 -103
- package/dest/public/app_logic_phase_manager.d.ts +7 -8
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +14 -14
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +2 -0
- package/dest/public/execution.d.ts +17 -14
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +3 -30
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +32 -279
- package/dest/public/fee_payment.d.ts +11 -0
- package/dest/public/fee_payment.d.ts.map +1 -0
- package/dest/public/fee_payment.js +24 -0
- package/dest/public/hints_builder.d.ts +3 -2
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +8 -4
- package/dest/public/index.d.ts +4 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +5 -3
- package/dest/public/phase_manager_factory.d.ts +1 -1
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +198 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +8 -6
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -29
- package/dest/public/setup_phase_manager.d.ts +7 -9
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +11 -20
- package/dest/public/tail_phase_manager.d.ts +5 -11
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +16 -36
- package/dest/public/teardown_phase_manager.d.ts +7 -9
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +15 -21
- package/dest/public/transitional_adaptors.d.ts +3 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +24 -8
- package/dest/public/utils.d.ts +2 -2
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +21 -14
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +53 -27
- package/src/acvm/oracle/typed_oracle.ts +25 -16
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_execution_environment.ts +9 -5
- package/src/avm/avm_gas.ts +66 -73
- package/src/avm/avm_simulator.ts +14 -3
- package/src/avm/errors.ts +10 -0
- package/src/avm/fixtures/index.ts +22 -2
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +15 -14
- package/src/avm/journal/nullifiers.ts +27 -14
- package/src/avm/journal/public_storage.ts +30 -16
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +1 -0
- package/src/avm/opcodes/accrued_substate.ts +5 -6
- package/src/avm/opcodes/arithmetic.ts +1 -14
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +26 -10
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/memory.ts +1 -8
- package/src/avm/opcodes/storage.ts +3 -20
- package/src/avm/serialization/bytecode_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +70 -44
- package/src/client/db_oracle.ts +18 -12
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +41 -3
- package/src/client/private_execution.ts +38 -20
- package/src/client/simulator.ts +11 -32
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +20 -12
- package/src/common/index.ts +1 -0
- package/src/common/return_values.ts +18 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +31 -33
- package/src/{simulator → providers}/acvm_native.ts +21 -19
- package/src/{simulator → providers}/acvm_wasm.ts +2 -16
- package/src/public/abstract_phase_manager.ts +146 -207
- package/src/public/app_logic_phase_manager.ts +23 -39
- package/src/public/{db.ts → db_interfaces.ts} +2 -2
- package/src/public/execution.ts +17 -14
- package/src/public/executor.ts +51 -391
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +17 -3
- package/src/public/index.ts +4 -2
- package/src/public/phase_manager_factory.ts +1 -1
- package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +82 -38
- package/src/public/setup_phase_manager.ts +20 -45
- package/src/public/tail_phase_manager.ts +18 -68
- package/src/public/teardown_phase_manager.ts +22 -41
- package/src/public/transitional_adaptors.ts +24 -13
- package/src/public/utils.ts +20 -14
- package/dest/client/logs_cache.d.ts +0 -33
- package/dest/client/logs_cache.d.ts.map +0 -1
- package/dest/client/logs_cache.js +0 -59
- package/dest/public/db.d.ts.map +0 -1
- package/dest/public/db.js +0 -2
- package/dest/public/public_execution_context.d.ts +0 -121
- package/dest/public/public_execution_context.d.ts.map +0 -1
- package/dest/public/public_execution_context.js +0 -214
- package/dest/public/public_executor.d.ts.map +0 -1
- package/dest/public/public_executor.js +0 -197
- package/dest/public/state_actions.d.ts +0 -39
- package/dest/public/state_actions.d.ts.map +0 -1
- package/dest/public/state_actions.js +0 -80
- package/dest/simulator/acvm_wasm.d.ts.map +0 -1
- package/dest/simulator/acvm_wasm.js +0 -22
- package/dest/simulator/index.d.ts.map +0 -1
- package/src/client/logs_cache.ts +0 -65
- package/src/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
- /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
- /package/dest/{simulator → providers}/index.d.ts +0 -0
- /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
- /package/src/{simulator → providers}/index.ts +0 -0
- /package/src/{simulator → providers}/simulation_provider.ts +0 -0
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { UnencryptedFunctionL2Logs, type UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
CallContext,
|
|
4
|
-
FunctionData,
|
|
5
|
-
type FunctionSelector,
|
|
6
|
-
type Gas,
|
|
7
|
-
type GasSettings,
|
|
8
|
-
type GlobalVariables,
|
|
9
|
-
type Header,
|
|
10
|
-
type Nullifier,
|
|
11
|
-
PublicContextInputs,
|
|
12
|
-
} from '@aztec/circuits.js';
|
|
13
|
-
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
14
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
15
|
-
import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
|
|
16
|
-
import { type ContractInstance } from '@aztec/types/contracts';
|
|
17
|
-
|
|
18
|
-
import { TypedOracle, toACVMWitness } from '../acvm/index.js';
|
|
19
|
-
import { type PackedValuesCache, type SideEffectCounter } from '../common/index.js';
|
|
20
|
-
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db.js';
|
|
21
|
-
import { type PublicExecution, type PublicExecutionResult, checkValidStaticCall } from './execution.js';
|
|
22
|
-
import { executePublicFunction } from './executor.js';
|
|
23
|
-
import { ContractStorageActionsCollector } from './state_actions.js';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The execution context for a public tx simulation.
|
|
27
|
-
*/
|
|
28
|
-
export class PublicExecutionContext extends TypedOracle {
|
|
29
|
-
private storageActions: ContractStorageActionsCollector;
|
|
30
|
-
private nestedExecutions: PublicExecutionResult[] = [];
|
|
31
|
-
private unencryptedLogs: UnencryptedL2Log[] = [];
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
/**
|
|
35
|
-
* Data for this execution.
|
|
36
|
-
*/
|
|
37
|
-
public readonly execution: PublicExecution,
|
|
38
|
-
public readonly header: Header,
|
|
39
|
-
public readonly globalVariables: GlobalVariables,
|
|
40
|
-
private readonly packedValuesCache: PackedValuesCache,
|
|
41
|
-
// TRANSITIONAL: once AVM-ACVM interoperability is removed (fully functional AVM), sideEffectCounter can be made private
|
|
42
|
-
public readonly sideEffectCounter: SideEffectCounter,
|
|
43
|
-
public readonly stateDb: PublicStateDB,
|
|
44
|
-
public readonly contractsDb: PublicContractsDB,
|
|
45
|
-
public readonly commitmentsDb: CommitmentsDB,
|
|
46
|
-
public readonly availableGas: Gas,
|
|
47
|
-
public readonly transactionFee: Fr,
|
|
48
|
-
public readonly gasSettings: GasSettings,
|
|
49
|
-
public readonly pendingNullifiers: Nullifier[],
|
|
50
|
-
// Unencrypted logs emitted during this call AND any nested calls
|
|
51
|
-
// Useful for maintaining correct ordering in ts
|
|
52
|
-
private allUnencryptedLogs: UnencryptedL2Log[] = [],
|
|
53
|
-
private log = createDebugLogger('aztec:simulator:public_execution_context'),
|
|
54
|
-
) {
|
|
55
|
-
super();
|
|
56
|
-
this.storageActions = new ContractStorageActionsCollector(stateDb, execution.callContext.storageContractAddress);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Generates the initial witness for a public function.
|
|
61
|
-
* @param args - The arguments to the function.
|
|
62
|
-
* @param callContext - The call context of the function.
|
|
63
|
-
* @param header - Contains data required to reconstruct a block hash (historical roots etc.).
|
|
64
|
-
* @param globalVariables - The global variables.
|
|
65
|
-
* @param witnessStartIndex - The index where to start inserting the parameters.
|
|
66
|
-
* @returns The initial witness.
|
|
67
|
-
*/
|
|
68
|
-
public getInitialWitness(witnessStartIndex = 0) {
|
|
69
|
-
const { callContext, args } = this.execution;
|
|
70
|
-
const publicContextInputs = new PublicContextInputs(
|
|
71
|
-
callContext,
|
|
72
|
-
this.header,
|
|
73
|
-
this.globalVariables,
|
|
74
|
-
this.sideEffectCounter.current(),
|
|
75
|
-
this.availableGas,
|
|
76
|
-
this.transactionFee,
|
|
77
|
-
);
|
|
78
|
-
const fields = [...publicContextInputs.toFields(), ...args];
|
|
79
|
-
return toACVMWitness(witnessStartIndex, fields);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Return the nested execution results during this execution.
|
|
84
|
-
*/
|
|
85
|
-
public getNestedExecutions() {
|
|
86
|
-
return this.nestedExecutions;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Return the encrypted logs emitted during this execution.
|
|
91
|
-
*/
|
|
92
|
-
public getUnencryptedLogs() {
|
|
93
|
-
return new UnencryptedFunctionL2Logs(this.unencryptedLogs);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Return the encrypted logs emitted during this execution, including nested calls.
|
|
98
|
-
*/
|
|
99
|
-
public getAllUnencryptedLogs() {
|
|
100
|
-
return new UnencryptedFunctionL2Logs(this.allUnencryptedLogs);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Return the data read and updated during this execution.
|
|
105
|
-
*/
|
|
106
|
-
public getStorageActionData() {
|
|
107
|
-
const [contractStorageReads, contractStorageUpdateRequests] = this.storageActions.collect();
|
|
108
|
-
return { contractStorageReads, contractStorageUpdateRequests };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Pack the given array of arguments.
|
|
113
|
-
* @param args - Arguments to pack
|
|
114
|
-
*/
|
|
115
|
-
public override packArgumentsArray(args: Fr[]): Promise<Fr> {
|
|
116
|
-
return Promise.resolve(this.packedValuesCache.pack(args));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Pack the given returns.
|
|
121
|
-
* @param returns - Returns to pack
|
|
122
|
-
*/
|
|
123
|
-
public override packReturns(returns: Fr[]): Promise<Fr> {
|
|
124
|
-
return Promise.resolve(this.packedValuesCache.pack(returns));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Unpack the given returns.
|
|
129
|
-
* @param returnsHash - Returns hash to unpack
|
|
130
|
-
*/
|
|
131
|
-
public override unpackReturns(returnsHash: Fr): Promise<Fr[]> {
|
|
132
|
-
return Promise.resolve(this.packedValuesCache.unpack(returnsHash));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Fetches a message from the db, given its key.
|
|
137
|
-
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
138
|
-
* @param messageHash - Hash of the message.
|
|
139
|
-
* @param secret - Secret used to compute a nullifier.
|
|
140
|
-
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
141
|
-
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
142
|
-
*/
|
|
143
|
-
public override async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
144
|
-
return await this.commitmentsDb.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Emit an unencrypted log.
|
|
149
|
-
* @param log - The unencrypted log to be emitted.
|
|
150
|
-
*/
|
|
151
|
-
public override emitUnencryptedLog(log: UnencryptedL2Log, _counter: number) {
|
|
152
|
-
this.unencryptedLogs.push(log);
|
|
153
|
-
this.allUnencryptedLogs.push(log);
|
|
154
|
-
this.log.verbose(`Emitted unencrypted log: "${log.toHumanReadable()}"`);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Read the public storage data.
|
|
159
|
-
* @param startStorageSlot - The starting storage slot.
|
|
160
|
-
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
161
|
-
*/
|
|
162
|
-
public override async storageRead(startStorageSlot: Fr, numberOfElements: number) {
|
|
163
|
-
const values = [];
|
|
164
|
-
for (let i = 0; i < Number(numberOfElements); i++) {
|
|
165
|
-
const storageSlot = new Fr(startStorageSlot.value + BigInt(i));
|
|
166
|
-
const sideEffectCounter = this.sideEffectCounter.count();
|
|
167
|
-
const value = await this.storageActions.read(storageSlot, sideEffectCounter);
|
|
168
|
-
this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value.toString()}`);
|
|
169
|
-
values.push(value);
|
|
170
|
-
}
|
|
171
|
-
return values;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Write some values to the public storage.
|
|
176
|
-
* @param startStorageSlot - The starting storage slot.
|
|
177
|
-
* @param values - The values to be written.
|
|
178
|
-
*/
|
|
179
|
-
public override async storageWrite(startStorageSlot: Fr, values: Fr[]) {
|
|
180
|
-
const newValues = [];
|
|
181
|
-
for (let i = 0; i < values.length; i++) {
|
|
182
|
-
const storageSlot = new Fr(startStorageSlot.toBigInt() + BigInt(i));
|
|
183
|
-
const newValue = values[i];
|
|
184
|
-
const sideEffectCounter = this.sideEffectCounter.count();
|
|
185
|
-
this.storageActions.write(storageSlot, newValue, sideEffectCounter);
|
|
186
|
-
await this.stateDb.storageWrite(this.execution.callContext.storageContractAddress, storageSlot, newValue);
|
|
187
|
-
this.log.debug(`Oracle storage write: slot=${storageSlot.toString()} value=${newValue.toString()}`);
|
|
188
|
-
newValues.push(newValue);
|
|
189
|
-
}
|
|
190
|
-
return newValues;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Calls a public function as a nested execution.
|
|
195
|
-
* @param targetContractAddress - The address of the contract to call.
|
|
196
|
-
* @param functionSelector - The function selector of the function to call.
|
|
197
|
-
* @param argsHash - The packed arguments to pass to the function.
|
|
198
|
-
* @returns The return values of the public function.
|
|
199
|
-
*/
|
|
200
|
-
public override async callPublicFunction(
|
|
201
|
-
targetContractAddress: AztecAddress,
|
|
202
|
-
functionSelector: FunctionSelector,
|
|
203
|
-
argsHash: Fr,
|
|
204
|
-
sideEffectCounter: number,
|
|
205
|
-
isStaticCall: boolean,
|
|
206
|
-
isDelegateCall: boolean,
|
|
207
|
-
) {
|
|
208
|
-
isStaticCall = isStaticCall || this.execution.callContext.isStaticCall;
|
|
209
|
-
|
|
210
|
-
const args = this.packedValuesCache.unpack(argsHash);
|
|
211
|
-
this.log.verbose(
|
|
212
|
-
`Public function call: addr=${targetContractAddress} selector=${functionSelector} args=${args.join(',')}`,
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
const functionData = new FunctionData(functionSelector, /*isPrivate=*/ false);
|
|
216
|
-
const callContext = CallContext.from({
|
|
217
|
-
msgSender: isDelegateCall ? this.execution.callContext.msgSender : this.execution.contractAddress,
|
|
218
|
-
storageContractAddress: isDelegateCall ? this.execution.contractAddress : targetContractAddress,
|
|
219
|
-
functionSelector,
|
|
220
|
-
isDelegateCall,
|
|
221
|
-
isStaticCall,
|
|
222
|
-
sideEffectCounter,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const nestedExecution: PublicExecution = {
|
|
226
|
-
args,
|
|
227
|
-
contractAddress: targetContractAddress,
|
|
228
|
-
functionData,
|
|
229
|
-
callContext,
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const context = new PublicExecutionContext(
|
|
233
|
-
nestedExecution,
|
|
234
|
-
this.header,
|
|
235
|
-
this.globalVariables,
|
|
236
|
-
this.packedValuesCache,
|
|
237
|
-
this.sideEffectCounter,
|
|
238
|
-
this.stateDb,
|
|
239
|
-
this.contractsDb,
|
|
240
|
-
this.commitmentsDb,
|
|
241
|
-
this.availableGas,
|
|
242
|
-
this.transactionFee,
|
|
243
|
-
this.gasSettings,
|
|
244
|
-
/*pendingNullifiers=*/ [],
|
|
245
|
-
this.allUnencryptedLogs,
|
|
246
|
-
this.log,
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const childExecutionResult = await executePublicFunction(context, /*nested=*/ true);
|
|
250
|
-
|
|
251
|
-
if (isStaticCall) {
|
|
252
|
-
checkValidStaticCall(
|
|
253
|
-
childExecutionResult.newNoteHashes,
|
|
254
|
-
childExecutionResult.newNullifiers,
|
|
255
|
-
childExecutionResult.contractStorageUpdateRequests,
|
|
256
|
-
childExecutionResult.newL2ToL1Messages,
|
|
257
|
-
childExecutionResult.unencryptedLogs,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
this.nestedExecutions.push(childExecutionResult);
|
|
262
|
-
this.log.debug(`Returning from nested call: ret=${childExecutionResult.returnValues.join(', ')}`);
|
|
263
|
-
|
|
264
|
-
return childExecutionResult.returnValues;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
public override async checkNullifierExists(nullifier: Fr): Promise<boolean> {
|
|
268
|
-
const witness = await this.commitmentsDb.getNullifierMembershipWitnessAtLatestBlock(nullifier);
|
|
269
|
-
return !!witness;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
public override async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
273
|
-
// Note to AVM implementor: The wrapper of the oracle call get_contract_instance in aztec-nr
|
|
274
|
-
// automatically checks that the returned instance is correct, by hashing it together back
|
|
275
|
-
// into the address. However, in the AVM, we also need to prove the negative, otherwise a malicious
|
|
276
|
-
// sequencer could just lie about not having the instance available in its local db. We can do this
|
|
277
|
-
// by using the prove_contract_non_deployment_at method if the contract is not found in the db.
|
|
278
|
-
const instance = await this.contractsDb.getContractInstance(address);
|
|
279
|
-
if (!instance) {
|
|
280
|
-
throw new Error(`Contract instance at ${address} not found`);
|
|
281
|
-
}
|
|
282
|
-
return instance;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public override debugLog(message: string, fields: Fr[]): void {
|
|
286
|
-
const formattedStr = applyStringFormatting(message, fields);
|
|
287
|
-
this.log.verbose(`debug_log ${formattedStr}`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { ContractStorageRead, ContractStorageUpdateRequest } from '@aztec/circuits.js';
|
|
2
|
-
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
3
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
-
|
|
5
|
-
import { type PublicStateDB } from './db.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Implements read/write operations on a contract public storage, collecting
|
|
9
|
-
* all read and update operations, and collapsing them into a single
|
|
10
|
-
* read or update per slot.
|
|
11
|
-
*/
|
|
12
|
-
export class ContractStorageActionsCollector {
|
|
13
|
-
// Map from slot to first read value
|
|
14
|
-
private readonly contractStorageReads: Map<
|
|
15
|
-
bigint,
|
|
16
|
-
{ /** The value read. */ currentValue: Fr; /** Side effect counter. */ sideEffectCounter: number }
|
|
17
|
-
> = new Map();
|
|
18
|
-
|
|
19
|
-
// Map from slot to first read value and latest updated value
|
|
20
|
-
private readonly contractStorageUpdateRequests: Map<
|
|
21
|
-
bigint,
|
|
22
|
-
{
|
|
23
|
-
/** The updated value. */ newValue: Fr;
|
|
24
|
-
/** Side effect counter. */ sideEffectCounter: number;
|
|
25
|
-
}
|
|
26
|
-
> = new Map();
|
|
27
|
-
|
|
28
|
-
constructor(private db: PublicStateDB, private address: AztecAddress) {}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns the current value of a slot according to the latest update request for it,
|
|
32
|
-
* falling back to the public db. Collects the operation in storage reads,
|
|
33
|
-
* as long as there is no existing update request.
|
|
34
|
-
* @param storageSlot - Slot to check.
|
|
35
|
-
* @param sideEffectCounter - Side effect counter associated with this storage action.
|
|
36
|
-
* @returns The current value as affected by all update requests so far.
|
|
37
|
-
*/
|
|
38
|
-
public async read(storageSlot: Fr, sideEffectCounter: number): Promise<Fr> {
|
|
39
|
-
const slot = storageSlot.value;
|
|
40
|
-
const updateRequest = this.contractStorageUpdateRequests.get(slot);
|
|
41
|
-
if (updateRequest) {
|
|
42
|
-
return updateRequest.newValue;
|
|
43
|
-
}
|
|
44
|
-
const read = this.contractStorageReads.get(slot);
|
|
45
|
-
if (read) {
|
|
46
|
-
return read.currentValue;
|
|
47
|
-
}
|
|
48
|
-
const value = await this.db.storageRead(this.address, storageSlot);
|
|
49
|
-
this.contractStorageReads.set(slot, { currentValue: value, sideEffectCounter });
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Sets a new value for a slot in the internal update requests cache,
|
|
55
|
-
* clearing any previous storage read or update operation for the same slot.
|
|
56
|
-
* @param storageSlot - Slot to write to.
|
|
57
|
-
* @param newValue - Value to write to it.
|
|
58
|
-
* @param sideEffectCounter - Side effect counter associated with this storage action.
|
|
59
|
-
*/
|
|
60
|
-
public write(storageSlot: Fr, newValue: Fr, sideEffectCounter: number): void {
|
|
61
|
-
const slot = storageSlot.toBigInt();
|
|
62
|
-
const updateRequest = this.contractStorageUpdateRequests.get(slot);
|
|
63
|
-
if (updateRequest) {
|
|
64
|
-
this.contractStorageUpdateRequests.set(slot, { newValue, sideEffectCounter });
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const read = this.contractStorageReads.get(slot);
|
|
69
|
-
if (read) {
|
|
70
|
-
this.contractStorageReads.delete(slot);
|
|
71
|
-
this.contractStorageUpdateRequests.set(slot, { newValue, sideEffectCounter });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.contractStorageUpdateRequests.set(slot, { newValue, sideEffectCounter });
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Returns all storage reads and update requests performed.
|
|
81
|
-
* @returns All storage read and update requests.
|
|
82
|
-
*/
|
|
83
|
-
public collect(): [ContractStorageRead[], ContractStorageUpdateRequest[]] {
|
|
84
|
-
const reads = Array.from(this.contractStorageReads.entries()).map(([slot, valueAndCounter]) =>
|
|
85
|
-
ContractStorageRead.from({
|
|
86
|
-
contractAddress: this.address,
|
|
87
|
-
storageSlot: new Fr(slot),
|
|
88
|
-
...valueAndCounter,
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const updateRequests = Array.from(this.contractStorageUpdateRequests.entries()).map(([slot, valuesAndCounter]) =>
|
|
93
|
-
ContractStorageUpdateRequest.from({
|
|
94
|
-
contractAddress: this.address,
|
|
95
|
-
storageSlot: new Fr(slot),
|
|
96
|
-
...valuesAndCounter,
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return [reads, updateRequests];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|