@aztec/simulator 0.24.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/deserialize.d.ts +5 -0
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +8 -1
- package/dest/acvm/oracle/oracle.d.ts +5 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +24 -11
- package/dest/acvm/oracle/typed_oracle.d.ts +7 -9
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +9 -9
- package/dest/avm/avm_context.d.ts +4 -4
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +11 -2
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +11 -1
- package/dest/avm/avm_simulator.d.ts +6 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +17 -18
- package/dest/avm/fixtures/index.d.ts +17 -5
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +19 -8
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/host_storage.js +1 -1
- package/dest/avm/journal/journal.d.ts +78 -50
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +125 -169
- package/dest/avm/journal/nullifiers.d.ts +85 -0
- package/dest/avm/journal/nullifiers.d.ts.map +1 -0
- package/dest/avm/journal/nullifiers.js +147 -0
- package/dest/avm/journal/public_storage.d.ts +88 -0
- package/dest/avm/journal/public_storage.d.ts.map +1 -0
- package/dest/avm/journal/public_storage.js +135 -0
- package/dest/avm/journal/trace.d.ts +43 -0
- package/dest/avm/journal/trace.d.ts.map +1 -0
- package/dest/avm/journal/trace.js +204 -0
- package/dest/avm/journal/trace_types.d.ts +26 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -0
- package/dest/avm/journal/trace_types.js +6 -0
- package/dest/avm/opcodes/accrued_substate.d.ts +37 -4
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +109 -12
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +5 -8
- package/dest/avm/opcodes/environment_getters.d.ts +14 -13
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -1
- package/dest/avm/opcodes/external_calls.js +5 -5
- package/dest/avm/opcodes/hashing.d.ts +48 -0
- package/dest/avm/opcodes/hashing.d.ts.map +1 -0
- package/dest/avm/opcodes/hashing.js +127 -0
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -1
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -3
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +12 -8
- package/dest/avm/serialization/instruction_serialization.d.ts +10 -7
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +12 -9
- package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
- package/dest/avm/temporary_executor_migration.js +5 -5
- package/dest/client/client_execution_context.d.ts +9 -5
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +46 -24
- package/dest/client/db_oracle.d.ts +7 -0
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.js +1 -1
- package/dest/client/execution_result.d.ts +2 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -4
- package/dest/client/simulator.d.ts +1 -1
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +3 -2
- package/dest/client/view_data_oracle.d.ts +9 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +13 -5
- package/dest/public/db.d.ts +17 -4
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +9 -4
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +17 -4
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +18 -9
- package/dest/public/public_execution_context.d.ts +5 -4
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +23 -12
- package/dest/public/state_actions.js +2 -2
- package/dest/test/utils.js +4 -4
- package/dest/utils.js +2 -3
- package/package.json +6 -5
- package/src/acvm/deserialize.ts +8 -0
- package/src/acvm/oracle/oracle.ts +30 -6
- package/src/acvm/oracle/typed_oracle.ts +13 -5
- package/src/avm/avm_context.ts +5 -5
- package/src/avm/avm_memory_types.ts +18 -3
- package/src/avm/avm_simulator.ts +22 -24
- package/src/avm/fixtures/index.ts +34 -9
- package/src/avm/journal/host_storage.ts +5 -11
- package/src/avm/journal/journal.ts +147 -182
- package/src/avm/journal/nullifiers.ts +170 -0
- package/src/avm/journal/public_storage.ts +149 -0
- package/src/avm/journal/trace.ts +223 -0
- package/src/avm/journal/trace_types.ts +79 -0
- package/src/avm/opcodes/accrued_substate.ts +132 -10
- package/src/avm/opcodes/comparators.ts +4 -7
- package/src/avm/opcodes/environment_getters.ts +15 -13
- package/src/avm/opcodes/external_calls.ts +4 -4
- package/src/avm/opcodes/hashing.ts +170 -0
- package/src/avm/opcodes/memory.ts +1 -0
- package/src/avm/opcodes/storage.ts +5 -2
- package/src/avm/serialization/bytecode_serialization.ts +13 -6
- package/src/avm/serialization/instruction_serialization.ts +6 -3
- package/src/avm/temporary_executor_migration.ts +4 -3
- package/src/client/client_execution_context.ts +53 -23
- package/src/client/db_oracle.ts +8 -0
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +2 -2
- package/src/client/private_execution.ts +5 -4
- package/src/client/simulator.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -4
- package/src/public/db.ts +19 -4
- package/src/public/execution.ts +30 -6
- package/src/public/executor.ts +29 -9
- package/src/public/public_execution_context.ts +36 -12
- package/src/public/state_actions.ts +1 -1
- package/src/test/utils.ts +3 -3
- package/src/utils.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
1
|
+
import { FunctionL2Logs, NullifierMembershipWitness, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
2
|
import { CallContext, FunctionData, FunctionSelector, GlobalVariables, Header } from '@aztec/circuits.js';
|
|
3
3
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -8,7 +8,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
8
8
|
import { TypedOracle, toACVMWitness } from '../acvm/index.js';
|
|
9
9
|
import { PackedArgsCache, SideEffectCounter } from '../common/index.js';
|
|
10
10
|
import { CommitmentsDB, PublicContractsDB, PublicStateDB } from './db.js';
|
|
11
|
-
import { PublicExecution, PublicExecutionResult } from './execution.js';
|
|
11
|
+
import { PublicExecution, PublicExecutionResult, checkValidStaticCall } from './execution.js';
|
|
12
12
|
import { executePublicFunction } from './executor.js';
|
|
13
13
|
import { ContractStorageActionsCollector } from './state_actions.js';
|
|
14
14
|
|
|
@@ -35,7 +35,7 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
35
35
|
private log = createDebugLogger('aztec:simulator:public_execution_context'),
|
|
36
36
|
) {
|
|
37
37
|
super();
|
|
38
|
-
this.storageActions = new ContractStorageActionsCollector(stateDb, execution.
|
|
38
|
+
this.storageActions = new ContractStorageActionsCollector(stateDb, execution.callContext.storageContractAddress);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -86,11 +86,11 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Fetches the a message from the db, given its key.
|
|
89
|
-
* @param
|
|
89
|
+
* @param entryKey - A buffer representing the entry key.
|
|
90
90
|
* @returns The l1 to l2 message data
|
|
91
91
|
*/
|
|
92
|
-
public async
|
|
93
|
-
return await this.commitmentsDb.
|
|
92
|
+
public async getL1ToL2MembershipWitness(entryKey: Fr) {
|
|
93
|
+
return await this.commitmentsDb.getL1ToL2MembershipWitness(entryKey);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -138,11 +138,11 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
138
138
|
public async storageWrite(startStorageSlot: Fr, values: Fr[]) {
|
|
139
139
|
const newValues = [];
|
|
140
140
|
for (let i = 0; i < values.length; i++) {
|
|
141
|
-
const storageSlot = new Fr(startStorageSlot.
|
|
141
|
+
const storageSlot = new Fr(startStorageSlot.toBigInt() + BigInt(i));
|
|
142
142
|
const newValue = values[i];
|
|
143
143
|
const sideEffectCounter = this.sideEffectCounter.count();
|
|
144
144
|
this.storageActions.write(storageSlot, newValue, sideEffectCounter);
|
|
145
|
-
await this.stateDb.storageWrite(this.execution.
|
|
145
|
+
await this.stateDb.storageWrite(this.execution.callContext.storageContractAddress, storageSlot, newValue);
|
|
146
146
|
this.log(`Oracle storage write: slot=${storageSlot.toString()} value=${newValue.toString()}`);
|
|
147
147
|
newValues.push(newValue);
|
|
148
148
|
}
|
|
@@ -160,7 +160,11 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
160
160
|
targetContractAddress: AztecAddress,
|
|
161
161
|
functionSelector: FunctionSelector,
|
|
162
162
|
argsHash: Fr,
|
|
163
|
+
isStaticCall: boolean,
|
|
164
|
+
isDelegateCall: boolean,
|
|
163
165
|
) {
|
|
166
|
+
isStaticCall = isStaticCall || this.execution.callContext.isStaticCall;
|
|
167
|
+
|
|
164
168
|
const args = this.packedArgsCache.unpack(argsHash);
|
|
165
169
|
this.log(`Public function call: addr=${targetContractAddress} selector=${functionSelector} args=${args.join(',')}`);
|
|
166
170
|
|
|
@@ -178,13 +182,13 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
178
182
|
const functionData = new FunctionData(functionSelector, isInternal, false, false);
|
|
179
183
|
|
|
180
184
|
const callContext = CallContext.from({
|
|
181
|
-
msgSender: this.execution.contractAddress,
|
|
185
|
+
msgSender: isDelegateCall ? this.execution.callContext.msgSender : this.execution.contractAddress,
|
|
186
|
+
storageContractAddress: isDelegateCall ? this.execution.contractAddress : targetContractAddress,
|
|
182
187
|
portalContractAddress: portalAddress,
|
|
183
|
-
storageContractAddress: targetContractAddress,
|
|
184
188
|
functionSelector,
|
|
185
189
|
isContractDeployment: false,
|
|
186
|
-
isDelegateCall
|
|
187
|
-
isStaticCall
|
|
190
|
+
isDelegateCall,
|
|
191
|
+
isStaticCall,
|
|
188
192
|
startSideEffectCounter: 0, // TODO use counters in public execution
|
|
189
193
|
});
|
|
190
194
|
|
|
@@ -209,9 +213,29 @@ export class PublicExecutionContext extends TypedOracle {
|
|
|
209
213
|
|
|
210
214
|
const childExecutionResult = await executePublicFunction(context, acir);
|
|
211
215
|
|
|
216
|
+
if (isStaticCall) {
|
|
217
|
+
checkValidStaticCall(
|
|
218
|
+
childExecutionResult.newNoteHashes,
|
|
219
|
+
childExecutionResult.newNullifiers,
|
|
220
|
+
childExecutionResult.contractStorageUpdateRequests,
|
|
221
|
+
childExecutionResult.newL2ToL1Messages,
|
|
222
|
+
childExecutionResult.unencryptedLogs,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
212
226
|
this.nestedExecutions.push(childExecutionResult);
|
|
213
227
|
this.log(`Returning from nested call: ret=${childExecutionResult.returnValues.join(', ')}`);
|
|
214
228
|
|
|
215
229
|
return childExecutionResult.returnValues;
|
|
216
230
|
}
|
|
231
|
+
|
|
232
|
+
public async getNullifierMembershipWitness(
|
|
233
|
+
blockNumber: number,
|
|
234
|
+
nullifier: Fr,
|
|
235
|
+
): Promise<NullifierMembershipWitness | undefined> {
|
|
236
|
+
if (!this.header.globalVariables.blockNumber.equals(new Fr(blockNumber))) {
|
|
237
|
+
throw new Error(`Public execution oracle can only access nullifier membership witnesses for the current block`);
|
|
238
|
+
}
|
|
239
|
+
return await this.commitmentsDb.getNullifierMembershipWitnessAtLatestBlock(nullifier);
|
|
240
|
+
}
|
|
217
241
|
}
|
|
@@ -58,7 +58,7 @@ export class ContractStorageActionsCollector {
|
|
|
58
58
|
* @param sideEffectCounter - Side effect counter associated with this storage action.
|
|
59
59
|
*/
|
|
60
60
|
public write(storageSlot: Fr, newValue: Fr, sideEffectCounter: number): void {
|
|
61
|
-
const slot = storageSlot.
|
|
61
|
+
const slot = storageSlot.toBigInt();
|
|
62
62
|
const updateRequest = this.contractStorageUpdateRequests.get(slot);
|
|
63
63
|
if (updateRequest) {
|
|
64
64
|
this.contractStorageUpdateRequests.set(slot, { newValue, sideEffectCounter });
|
package/src/test/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/circuit-types';
|
|
2
2
|
import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
|
|
3
|
-
import {
|
|
3
|
+
import { computeMessageSecretHash } from '@aztec/circuits.js/hash';
|
|
4
4
|
import { sha256 } from '@aztec/foundation/crypto';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -23,7 +23,7 @@ export const buildL1ToL2Message = (
|
|
|
23
23
|
const contentBuf = Buffer.concat([selectorBuf, ...contentPreimage.map(field => field.toBuffer())]);
|
|
24
24
|
const content = Fr.fromBufferReduce(sha256(contentBuf));
|
|
25
25
|
|
|
26
|
-
const secretHash =
|
|
26
|
+
const secretHash = computeMessageSecretHash(secret);
|
|
27
27
|
|
|
28
28
|
// Eventually the kernel will need to prove the kernel portal pair exists within the contract tree,
|
|
29
29
|
// EthAddress.random() will need to be replaced when this happens
|
|
@@ -32,7 +32,7 @@ export const buildL1ToL2Message = (
|
|
|
32
32
|
new L2Actor(targetContract, 1),
|
|
33
33
|
content,
|
|
34
34
|
secretHash,
|
|
35
|
-
|
|
35
|
+
2 ** 32 - 1,
|
|
36
36
|
0,
|
|
37
37
|
);
|
|
38
38
|
};
|
package/src/utils.ts
CHANGED