@aztec/simulator 0.24.0 → 0.26.2

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.
Files changed (129) hide show
  1. package/dest/acvm/deserialize.d.ts +5 -0
  2. package/dest/acvm/deserialize.d.ts.map +1 -1
  3. package/dest/acvm/deserialize.js +8 -1
  4. package/dest/acvm/oracle/oracle.d.ts +5 -4
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +24 -11
  7. package/dest/acvm/oracle/typed_oracle.d.ts +7 -9
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +9 -9
  10. package/dest/avm/avm_context.d.ts +4 -4
  11. package/dest/avm/avm_context.d.ts.map +1 -1
  12. package/dest/avm/avm_context.js +6 -6
  13. package/dest/avm/avm_memory_types.d.ts +11 -2
  14. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  15. package/dest/avm/avm_memory_types.js +11 -1
  16. package/dest/avm/avm_simulator.d.ts +6 -4
  17. package/dest/avm/avm_simulator.d.ts.map +1 -1
  18. package/dest/avm/avm_simulator.js +17 -18
  19. package/dest/avm/fixtures/index.d.ts +17 -5
  20. package/dest/avm/fixtures/index.d.ts.map +1 -1
  21. package/dest/avm/fixtures/index.js +19 -8
  22. package/dest/avm/journal/host_storage.d.ts.map +1 -1
  23. package/dest/avm/journal/host_storage.js +1 -1
  24. package/dest/avm/journal/journal.d.ts +78 -50
  25. package/dest/avm/journal/journal.d.ts.map +1 -1
  26. package/dest/avm/journal/journal.js +125 -169
  27. package/dest/avm/journal/nullifiers.d.ts +85 -0
  28. package/dest/avm/journal/nullifiers.d.ts.map +1 -0
  29. package/dest/avm/journal/nullifiers.js +147 -0
  30. package/dest/avm/journal/public_storage.d.ts +88 -0
  31. package/dest/avm/journal/public_storage.d.ts.map +1 -0
  32. package/dest/avm/journal/public_storage.js +135 -0
  33. package/dest/avm/journal/trace.d.ts +43 -0
  34. package/dest/avm/journal/trace.d.ts.map +1 -0
  35. package/dest/avm/journal/trace.js +204 -0
  36. package/dest/avm/journal/trace_types.d.ts +26 -0
  37. package/dest/avm/journal/trace_types.d.ts.map +1 -0
  38. package/dest/avm/journal/trace_types.js +6 -0
  39. package/dest/avm/opcodes/accrued_substate.d.ts +37 -4
  40. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  41. package/dest/avm/opcodes/accrued_substate.js +109 -12
  42. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  43. package/dest/avm/opcodes/comparators.js +5 -8
  44. package/dest/avm/opcodes/environment_getters.d.ts +14 -13
  45. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  46. package/dest/avm/opcodes/environment_getters.js +1 -1
  47. package/dest/avm/opcodes/external_calls.js +5 -5
  48. package/dest/avm/opcodes/hashing.d.ts +48 -0
  49. package/dest/avm/opcodes/hashing.d.ts.map +1 -0
  50. package/dest/avm/opcodes/hashing.js +127 -0
  51. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  52. package/dest/avm/opcodes/memory.js +1 -1
  53. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  54. package/dest/avm/opcodes/storage.js +3 -3
  55. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  56. package/dest/avm/serialization/bytecode_serialization.js +12 -8
  57. package/dest/avm/serialization/instruction_serialization.d.ts +10 -7
  58. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  59. package/dest/avm/serialization/instruction_serialization.js +12 -9
  60. package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
  61. package/dest/avm/temporary_executor_migration.js +5 -5
  62. package/dest/client/client_execution_context.d.ts +9 -5
  63. package/dest/client/client_execution_context.d.ts.map +1 -1
  64. package/dest/client/client_execution_context.js +46 -24
  65. package/dest/client/db_oracle.d.ts +7 -0
  66. package/dest/client/db_oracle.d.ts.map +1 -1
  67. package/dest/client/db_oracle.js +1 -1
  68. package/dest/client/execution_note_cache.js +1 -1
  69. package/dest/client/execution_result.d.ts +2 -2
  70. package/dest/client/execution_result.d.ts.map +1 -1
  71. package/dest/client/private_execution.d.ts.map +1 -1
  72. package/dest/client/private_execution.js +4 -4
  73. package/dest/client/simulator.d.ts +1 -1
  74. package/dest/client/simulator.d.ts.map +1 -1
  75. package/dest/client/simulator.js +3 -2
  76. package/dest/client/view_data_oracle.d.ts +9 -2
  77. package/dest/client/view_data_oracle.d.ts.map +1 -1
  78. package/dest/client/view_data_oracle.js +13 -5
  79. package/dest/public/db.d.ts +17 -4
  80. package/dest/public/db.d.ts.map +1 -1
  81. package/dest/public/execution.d.ts +9 -4
  82. package/dest/public/execution.d.ts.map +1 -1
  83. package/dest/public/execution.js +17 -4
  84. package/dest/public/executor.d.ts.map +1 -1
  85. package/dest/public/executor.js +18 -9
  86. package/dest/public/public_execution_context.d.ts +5 -4
  87. package/dest/public/public_execution_context.d.ts.map +1 -1
  88. package/dest/public/public_execution_context.js +23 -12
  89. package/dest/public/state_actions.js +2 -2
  90. package/dest/test/utils.js +4 -4
  91. package/dest/utils.js +2 -3
  92. package/package.json +6 -5
  93. package/src/acvm/deserialize.ts +8 -0
  94. package/src/acvm/oracle/oracle.ts +30 -6
  95. package/src/acvm/oracle/typed_oracle.ts +13 -5
  96. package/src/avm/avm_context.ts +5 -5
  97. package/src/avm/avm_memory_types.ts +18 -3
  98. package/src/avm/avm_simulator.ts +22 -24
  99. package/src/avm/fixtures/index.ts +34 -9
  100. package/src/avm/journal/host_storage.ts +5 -11
  101. package/src/avm/journal/journal.ts +147 -182
  102. package/src/avm/journal/nullifiers.ts +170 -0
  103. package/src/avm/journal/public_storage.ts +149 -0
  104. package/src/avm/journal/trace.ts +223 -0
  105. package/src/avm/journal/trace_types.ts +79 -0
  106. package/src/avm/opcodes/accrued_substate.ts +132 -10
  107. package/src/avm/opcodes/comparators.ts +4 -7
  108. package/src/avm/opcodes/environment_getters.ts +15 -13
  109. package/src/avm/opcodes/external_calls.ts +4 -4
  110. package/src/avm/opcodes/hashing.ts +170 -0
  111. package/src/avm/opcodes/memory.ts +1 -0
  112. package/src/avm/opcodes/storage.ts +5 -2
  113. package/src/avm/serialization/bytecode_serialization.ts +13 -6
  114. package/src/avm/serialization/instruction_serialization.ts +6 -3
  115. package/src/avm/temporary_executor_migration.ts +4 -3
  116. package/src/client/client_execution_context.ts +53 -23
  117. package/src/client/db_oracle.ts +8 -0
  118. package/src/client/execution_note_cache.ts +1 -1
  119. package/src/client/execution_result.ts +2 -2
  120. package/src/client/private_execution.ts +5 -4
  121. package/src/client/simulator.ts +2 -1
  122. package/src/client/view_data_oracle.ts +14 -4
  123. package/src/public/db.ts +19 -4
  124. package/src/public/execution.ts +30 -6
  125. package/src/public/executor.ts +29 -9
  126. package/src/public/public_execution_context.ts +36 -12
  127. package/src/public/state_actions.ts +1 -1
  128. package/src/test/utils.ts +3 -3
  129. 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.contractAddress);
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 msgKey - A buffer representing the message key.
89
+ * @param entryKey - A buffer representing the entry key.
90
90
  * @returns The l1 to l2 message data
91
91
  */
92
- public async getL1ToL2Message(msgKey: Fr) {
93
- return await this.commitmentsDb.getL1ToL2Message(msgKey);
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.value + BigInt(i));
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.contractAddress, storageSlot, newValue);
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: false,
187
- isStaticCall: false,
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.value;
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 { computeSecretMessageHash } from '@aztec/circuits.js/abis';
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 = computeSecretMessageHash(secret);
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
- 0,
35
+ 2 ** 32 - 1,
36
36
  0,
37
37
  );
38
38
  };
package/src/utils.ts CHANGED
@@ -14,5 +14,5 @@ export function computeSlotForMapping(
14
14
  toField: () => Fr;
15
15
  },
16
16
  ) {
17
- return Fr.fromBuffer(pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer())));
17
+ return pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer()));
18
18
  }