@aztec/simulator 0.71.0 → 0.73.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.
Files changed (137) hide show
  1. package/README.md +1 -1
  2. package/dest/acvm/oracle/oracle.d.ts +0 -1
  3. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/acvm/oracle/oracle.js +1 -5
  5. package/dest/acvm/oracle/typed_oracle.d.ts +0 -1
  6. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/acvm/oracle/typed_oracle.js +1 -4
  8. package/dest/avm/avm_simulator.d.ts +0 -1
  9. package/dest/avm/avm_simulator.d.ts.map +1 -1
  10. package/dest/avm/avm_simulator.js +4 -19
  11. package/dest/avm/avm_tree.d.ts +9 -8
  12. package/dest/avm/avm_tree.d.ts.map +1 -1
  13. package/dest/avm/avm_tree.js +35 -30
  14. package/dest/avm/errors.d.ts +6 -0
  15. package/dest/avm/errors.d.ts.map +1 -1
  16. package/dest/avm/errors.js +10 -1
  17. package/dest/avm/fixtures/avm_simulation_tester.d.ts +21 -0
  18. package/dest/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
  19. package/dest/avm/fixtures/avm_simulation_tester.js +74 -0
  20. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts +35 -0
  21. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
  22. package/dest/avm/fixtures/base_avm_simulation_tester.js +76 -0
  23. package/dest/avm/fixtures/index.d.ts +6 -2
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +28 -14
  26. package/dest/avm/fixtures/simple_contract_data_source.d.ts +31 -0
  27. package/dest/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
  28. package/dest/avm/fixtures/simple_contract_data_source.js +75 -0
  29. package/dest/avm/journal/journal.d.ts +5 -6
  30. package/dest/avm/journal/journal.d.ts.map +1 -1
  31. package/dest/avm/journal/journal.js +28 -26
  32. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  33. package/dest/avm/opcodes/accrued_substate.js +4 -3
  34. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  35. package/dest/avm/opcodes/conversion.js +10 -7
  36. package/dest/avm/opcodes/ec_add.js +2 -2
  37. package/dest/avm/opcodes/hashing.js +2 -2
  38. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  39. package/dest/avm/opcodes/multi_scalar_mul.js +9 -7
  40. package/dest/avm/test_utils.d.ts +1 -1
  41. package/dest/avm/test_utils.d.ts.map +1 -1
  42. package/dest/avm/test_utils.js +4 -3
  43. package/dest/client/client_execution_context.d.ts +2 -6
  44. package/dest/client/client_execution_context.d.ts.map +1 -1
  45. package/dest/client/client_execution_context.js +23 -26
  46. package/dest/client/execution_note_cache.d.ts +3 -3
  47. package/dest/client/execution_note_cache.d.ts.map +1 -1
  48. package/dest/client/execution_note_cache.js +10 -10
  49. package/dest/client/pick_notes.js +5 -5
  50. package/dest/client/simulator.js +4 -4
  51. package/dest/client/view_data_oracle.js +2 -2
  52. package/dest/common/hashed_values_cache.d.ts +1 -1
  53. package/dest/common/hashed_values_cache.d.ts.map +1 -1
  54. package/dest/common/hashed_values_cache.js +5 -5
  55. package/dest/providers/acvm_wasm.d.ts +2 -0
  56. package/dest/providers/acvm_wasm.d.ts.map +1 -1
  57. package/dest/providers/acvm_wasm.js +15 -2
  58. package/dest/public/execution.d.ts +8 -26
  59. package/dest/public/execution.d.ts.map +1 -1
  60. package/dest/public/execution.js +3 -3
  61. package/dest/public/fee_payment.d.ts +2 -2
  62. package/dest/public/fee_payment.d.ts.map +1 -1
  63. package/dest/public/fee_payment.js +3 -3
  64. package/dest/public/fixtures/index.d.ts +2 -37
  65. package/dest/public/fixtures/index.d.ts.map +1 -1
  66. package/dest/public/fixtures/index.js +3 -247
  67. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +21 -0
  68. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
  69. package/dest/public/fixtures/public_tx_simulation_tester.js +89 -0
  70. package/dest/public/fixtures/utils.d.ts +17 -0
  71. package/dest/public/fixtures/utils.d.ts.map +1 -0
  72. package/dest/public/fixtures/utils.js +66 -0
  73. package/dest/public/index.d.ts +1 -1
  74. package/dest/public/index.d.ts.map +1 -1
  75. package/dest/public/index.js +2 -2
  76. package/dest/public/public_db_sources.d.ts +2 -1
  77. package/dest/public/public_db_sources.d.ts.map +1 -1
  78. package/dest/public/public_db_sources.js +27 -21
  79. package/dest/public/public_processor.d.ts +4 -5
  80. package/dest/public/public_processor.d.ts.map +1 -1
  81. package/dest/public/public_processor.js +28 -28
  82. package/dest/public/public_tx_context.d.ts +5 -5
  83. package/dest/public/public_tx_context.d.ts.map +1 -1
  84. package/dest/public/public_tx_context.js +44 -18
  85. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  86. package/dest/public/public_tx_simulator.js +9 -12
  87. package/dest/public/{enqueued_call_side_effect_trace.d.ts → side_effect_trace.d.ts} +12 -15
  88. package/dest/public/side_effect_trace.d.ts.map +1 -0
  89. package/dest/public/side_effect_trace.js +350 -0
  90. package/dest/public/side_effect_trace_interface.d.ts +4 -5
  91. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  92. package/dest/test/utils.d.ts +1 -1
  93. package/dest/test/utils.d.ts.map +1 -1
  94. package/dest/test/utils.js +3 -3
  95. package/package.json +10 -10
  96. package/src/acvm/oracle/oracle.ts +0 -5
  97. package/src/acvm/oracle/typed_oracle.ts +0 -4
  98. package/src/avm/avm_simulator.ts +3 -27
  99. package/src/avm/avm_tree.ts +39 -37
  100. package/src/avm/errors.ts +10 -0
  101. package/src/avm/fixtures/avm_simulation_tester.ts +105 -0
  102. package/src/avm/fixtures/base_avm_simulation_tester.ts +104 -0
  103. package/src/avm/fixtures/index.ts +46 -17
  104. package/src/avm/fixtures/simple_contract_data_source.ts +98 -0
  105. package/src/avm/journal/journal.ts +28 -26
  106. package/src/avm/opcodes/accrued_substate.ts +3 -2
  107. package/src/avm/opcodes/conversion.ts +15 -6
  108. package/src/avm/opcodes/ec_add.ts +1 -1
  109. package/src/avm/opcodes/hashing.ts +1 -1
  110. package/src/avm/opcodes/multi_scalar_mul.ts +8 -6
  111. package/src/avm/test_utils.ts +3 -4
  112. package/src/client/client_execution_context.ts +29 -30
  113. package/src/client/execution_note_cache.ts +19 -14
  114. package/src/client/pick_notes.ts +4 -4
  115. package/src/client/simulator.ts +3 -3
  116. package/src/client/view_data_oracle.ts +1 -1
  117. package/src/common/hashed_values_cache.ts +4 -4
  118. package/src/providers/acvm_wasm.ts +13 -2
  119. package/src/public/execution.ts +10 -34
  120. package/src/public/fee_payment.ts +2 -2
  121. package/src/public/fixtures/index.ts +2 -381
  122. package/src/public/fixtures/public_tx_simulation_tester.ts +174 -0
  123. package/src/public/fixtures/utils.ts +110 -0
  124. package/src/public/index.ts +1 -1
  125. package/src/public/public_db_sources.ts +31 -20
  126. package/src/public/public_processor.ts +32 -30
  127. package/src/public/public_tx_context.ts +87 -28
  128. package/src/public/public_tx_simulator.ts +7 -14
  129. package/src/public/{enqueued_call_side_effect_trace.ts → side_effect_trace.ts} +29 -41
  130. package/src/public/side_effect_trace_interface.ts +4 -4
  131. package/src/test/utils.ts +2 -2
  132. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +0 -1
  133. package/dest/public/enqueued_call_side_effect_trace.js +0 -357
  134. package/dest/public/transitional_adapters.d.ts +0 -4
  135. package/dest/public/transitional_adapters.d.ts.map +0 -1
  136. package/dest/public/transitional_adapters.js +0 -29
  137. package/src/public/transitional_adapters.ts +0 -113
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
- import { type UnencryptedL2Log } from '@aztec/circuit-types';
4
- import { type ContractClassIdPreimage, type Gas, type NullifierLeafPreimage, type PublicCallRequest, type PublicDataTreeLeafPreimage, type SerializableContractInstance } from '@aztec/circuits.js';
3
+ import { type ContractClassIdPreimage, type Gas, type NullifierLeafPreimage, type PublicCallRequest, type PublicDataTreeLeafPreimage, type PublicLog, type SerializableContractInstance } from '@aztec/circuits.js';
5
4
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
6
5
  import { type Fr } from '@aztec/foundation/fields';
7
6
  import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
@@ -13,7 +12,7 @@ export interface PublicSideEffectTraceInterface {
13
12
  getCounter(): number;
14
13
  tracePublicStorageRead(contractAddress: AztecAddress, slot: Fr, value: Fr, leafPreimage?: PublicDataTreeLeafPreimage, leafIndex?: Fr, path?: Fr[]): void;
15
14
  tracePublicStorageWrite(contractAddress: AztecAddress, slot: Fr, // This is the storage slot not the computed leaf slot
16
- value: Fr, protocolWrite: boolean, lowLeafPreimage?: PublicDataTreeLeafPreimage, lowLeafIndex?: Fr, lowLeafPath?: Fr[], newLeafPreimage?: PublicDataTreeLeafPreimage, insertionPath?: Fr[]): void;
15
+ value: Fr, protocolWrite: boolean, lowLeafPreimage?: PublicDataTreeLeafPreimage, lowLeafIndex?: Fr, lowLeafPath?: Fr[], newLeafPreimage?: PublicDataTreeLeafPreimage, insertionPath?: Fr[]): Promise<void>;
17
16
  traceNoteHashCheck(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr, exists: boolean, path?: Fr[]): void;
18
17
  traceNewNoteHash(uniqueNoteHash: Fr, leafIndex?: Fr, path?: Fr[]): void;
19
18
  getNoteHashCount(): number;
@@ -21,7 +20,7 @@ export interface PublicSideEffectTraceInterface {
21
20
  traceNewNullifier(siloedNullifier: Fr, lowLeafPreimage?: NullifierLeafPreimage, lowLeafIndex?: Fr, lowLeafPath?: Fr[], insertionPath?: Fr[]): void;
22
21
  traceL1ToL2MessageCheck(contractAddress: AztecAddress, msgHash: Fr, msgLeafIndex: Fr, exists: boolean, path?: Fr[]): void;
23
22
  traceNewL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr): void;
24
- traceUnencryptedLog(contractAddress: AztecAddress, log: Fr[]): void;
23
+ tracePublicLog(contractAddress: AztecAddress, log: Fr[]): void;
25
24
  traceGetContractInstance(contractAddress: AztecAddress, exists: boolean, instance?: SerializableContractInstance, lowLeafPreimage?: NullifierLeafPreimage, lowLeafIndex?: Fr, lowLeafPath?: Fr[]): void;
26
25
  traceGetBytecode(contractAddress: AztecAddress, exists: boolean, bytecode?: Buffer, contractInstance?: SerializableContractInstance, contractClass?: ContractClassIdPreimage, lowLeafPreimage?: NullifierLeafPreimage, lowLeafIndex?: Fr, lowLeafPath?: Fr[]): void;
27
26
  traceEnqueuedCall(
@@ -45,6 +44,6 @@ export interface PublicSideEffectTraceInterface {
45
44
  avmCallResults: AvmFinalizedCallResult,
46
45
  /** Function name for logging */
47
46
  functionName: string): PublicFunctionCallResult;
48
- getUnencryptedLogs(): UnencryptedL2Log[];
47
+ getPublicLogs(): PublicLog[];
49
48
  }
50
49
  //# sourceMappingURL=side_effect_trace_interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"side_effect_trace_interface.d.ts","sourceRoot":"","sources":["../../src/public/side_effect_trace_interface.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,GAAG,EACR,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,KAAK,gDAAgD,EAAE,KAAK,wBAAwB,EAA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,gDAAgD,CAAC;IACpD,0BAA0B;IACxB,oDAAoD;IACpD,cAAc,EAAE,uBAAuB;IACvC,4DAA4D;IAC5D,YAAY,EAAE,GAAG;IACjB,wCAAwC;IACxC,QAAQ,EAAE,MAAM;IAChB,yBAAyB;IACzB,cAAc,EAAE,sBAAsB;IACtC,gCAAgC;IAChC,YAAY,EAAE,MAAM,GACnB,wBAAwB,CAAC;IAC5B,kBAAkB,IAAI,gBAAgB,EAAE,CAAC;CAC1C"}
1
+ {"version":3,"file":"side_effect_trace_interface.d.ts","sourceRoot":"","sources":["../../src/public/side_effect_trace_interface.ts"],"names":[],"mappings":";;AAAA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,GAAG,EACR,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,SAAS,EACd,KAAK,4BAA4B,EAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,KAAK,gDAAgD,EAAE,KAAK,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAEtH,MAAM,WAAW,8BAA8B;IAC7C,IAAI,IAAI,8BAA8B,CAAC;IACvC,KAAK,CAAC,WAAW,EAAE,8BAA8B,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7E,UAAU,IAAI,MAAM,CAAC;IAErB,sBAAsB,CACpB,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,EAAE,EACR,KAAK,EAAE,EAAE,EACT,YAAY,CAAC,EAAE,0BAA0B,EACzC,SAAS,CAAC,EAAE,EAAE,EACd,IAAI,CAAC,EAA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
  * @param secret - The secret to unlock the message.
9
9
  * @returns The L1 to L2 message.
10
10
  */
11
- export declare const buildL1ToL2Message: (selector: string, contentPreimage: Fr[], targetContract: AztecAddress, secret: Fr, msgIndex: Fr | number) => L1ToL2Message;
11
+ export declare const buildL1ToL2Message: (selector: string, contentPreimage: Fr[], targetContract: AztecAddress, secret: Fr, msgIndex: Fr | number) => Promise<L1ToL2Message>;
12
12
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,aAAa,EAAW,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAc,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAIvE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,aACnB,MAAM,mBACC,EAAE,EAAE,kBACL,YAAY,UACpB,EAAE,YACA,EAAE,GAAG,MAAM,kBAetB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,aAAa,EAAW,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAc,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAIvE;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,aACnB,MAAM,mBACC,EAAE,EAAE,kBACL,YAAY,UACpB,EAAE,YACA,EAAE,GAAG,MAAM,2BAetB,CAAC"}
@@ -10,11 +10,11 @@ import { sha256ToField } from '@aztec/foundation/crypto';
10
10
  * @param secret - The secret to unlock the message.
11
11
  * @returns The L1 to L2 message.
12
12
  */
13
- export const buildL1ToL2Message = (selector, contentPreimage, targetContract, secret, msgIndex) => {
13
+ export const buildL1ToL2Message = async (selector, contentPreimage, targetContract, secret, msgIndex) => {
14
14
  // Write the selector into a buffer.
15
15
  const selectorBuf = Buffer.from(selector, 'hex');
16
16
  const content = sha256ToField([selectorBuf, ...contentPreimage]);
17
- const secretHash = computeSecretHash(secret);
17
+ const secretHash = await computeSecretHash(secret);
18
18
  return new L1ToL2Message(new L1Actor(EthAddress.random(), 1), new L2Actor(targetContract, 1), content, secretHash, new Fr(msgIndex));
19
19
  };
20
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdC91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsT0FBTyxFQUFFLGFBQWEsRUFBRSxPQUFPLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN2RSxPQUFPLEVBQXFCLFVBQVUsRUFBRSxFQUFFLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUN2RSxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFekQ7Ozs7Ozs7R0FPRztBQUNILE1BQU0sQ0FBQyxNQUFNLGtCQUFrQixHQUFHLENBQ2hDLFFBQWdCLEVBQ2hCLGVBQXFCLEVBQ3JCLGNBQTRCLEVBQzVCLE1BQVUsRUFDVixRQUFxQixFQUNyQixFQUFFO0lBQ0Ysb0NBQW9DO0lBQ3BDLE1BQU0sV0FBVyxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsUUFBUSxFQUFFLEtBQUssQ0FBQyxDQUFDO0lBRWpELE1BQU0sT0FBTyxHQUFHLGFBQWEsQ0FBQyxDQUFDLFdBQVcsRUFBRSxHQUFHLGVBQWUsQ0FBQyxDQUFDLENBQUM7SUFDakUsTUFBTSxVQUFVLEdBQUcsaUJBQWlCLENBQUMsTUFBTSxDQUFDLENBQUM7SUFFN0MsT0FBTyxJQUFJLGFBQWEsQ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RSxNQUFNLFVBQVUsR0FBRyxNQUFNLGlCQUFpQixDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRW5ELE9BQU8sSUFBSSxhQUFhLENBQ3RCLElBQUksT0FBTyxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsRUFBRSxDQUFDLENBQUMsRUFDbkMsSUFBSSxPQUFPLENBQUMsY0FBYyxFQUFFLENBQUMsQ0FBQyxFQUM5QixPQUFPLEVBQ1AsVUFBVSxFQUNWLElBQUksRUFBRSxDQUFDLFFBQVEsQ0FBQyxDQUNqQixDQUFDO0FBQ0osQ0FBQyxDQUFDIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.71.0",
3
+ "version": "0.73.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./common": "./dest/common.js",
@@ -60,14 +60,14 @@
60
60
  ]
61
61
  },
62
62
  "dependencies": {
63
- "@aztec/circuit-types": "0.71.0",
64
- "@aztec/circuits.js": "0.71.0",
65
- "@aztec/foundation": "0.71.0",
66
- "@aztec/noir-protocol-circuits-types": "0.71.0",
67
- "@aztec/protocol-contracts": "0.71.0",
68
- "@aztec/telemetry-client": "0.71.0",
69
- "@aztec/types": "0.71.0",
70
- "@aztec/world-state": "0.71.0",
63
+ "@aztec/circuit-types": "0.73.0",
64
+ "@aztec/circuits.js": "0.73.0",
65
+ "@aztec/foundation": "0.73.0",
66
+ "@aztec/noir-protocol-circuits-types": "0.73.0",
67
+ "@aztec/protocol-contracts": "0.73.0",
68
+ "@aztec/telemetry-client": "0.73.0",
69
+ "@aztec/types": "0.73.0",
70
+ "@aztec/world-state": "0.73.0",
71
71
  "@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
72
72
  "@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
73
73
  "@noir-lang/types": "portal:../../noir/packages/types",
@@ -92,7 +92,7 @@
92
92
  "lodash.merge": "^4.6.2",
93
93
  "ts-node": "^10.9.1",
94
94
  "typescript": "^5.0.4",
95
- "viem": "^2.7.15"
95
+ "viem": "2.22.8"
96
96
  },
97
97
  "files": [
98
98
  "dest",
@@ -19,11 +19,6 @@ export class Oracle {
19
19
  return toACVMField(val);
20
20
  }
21
21
 
22
- async storeArrayInExecutionCache(values: ACVMField[]): Promise<ACVMField> {
23
- const hash = await this.typedOracle.storeArrayInExecutionCache(values.map(fromACVMField));
24
- return toACVMField(hash);
25
- }
26
-
27
22
  // Since the argument is a slice, noir automatically adds a length field to oracle call.
28
23
  async storeInExecutionCache(_length: ACVMField[], values: ACVMField[]): Promise<ACVMField> {
29
24
  const hash = await this.typedOracle.storeInExecutionCache(values.map(fromACVMField));
@@ -56,10 +56,6 @@ export abstract class TypedOracle {
56
56
  return Fr.random();
57
57
  }
58
58
 
59
- storeArrayInExecutionCache(_args: Fr[]): Promise<Fr> {
60
- throw new OracleMethodNotAvailableError('storeArrayInExecutionCache');
61
- }
62
-
63
59
  storeInExecutionCache(_values: Fr[]): Promise<Fr> {
64
60
  throw new OracleMethodNotAvailableError('storeInExecutionCache');
65
61
  }
@@ -28,20 +28,14 @@ type OpcodeTally = {
28
28
  count: number;
29
29
  gas: Gas;
30
30
  };
31
- type PcTally = {
32
- opcode: string;
33
- count: number;
34
- gas: Gas;
35
- };
36
31
 
37
32
  export class AvmSimulator {
38
33
  private log: Logger;
39
34
  private bytecode: Buffer | undefined;
40
35
  private opcodeTallies: Map<string, OpcodeTally> = new Map();
41
- private pcTallies: Map<number, PcTally> = new Map();
42
36
 
43
37
  private tallyPrintFunction = () => {};
44
- private tallyInstructionFunction = (_a: number, _b: string, _c: Gas) => {};
38
+ private tallyInstructionFunction = (_b: string, _c: Gas) => {};
45
39
 
46
40
  // Test Purposes only: Logger will not have the proper function name. Use this constructor for testing purposes
47
41
  // only. Otherwise, use build() below.
@@ -145,7 +139,6 @@ export class AvmSimulator {
145
139
  while (!machineState.getHalted()) {
146
140
  const [instruction, bytesRead] = decodeInstructionFromBytecode(bytecode, machineState.pc, this.instructionSet);
147
141
  const instrStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
148
- const instrPc = machineState.pc; // Save PC before executing instruction (for profiling)
149
142
 
150
143
  this.log.trace(
151
144
  `[PC:${machineState.pc}] [IC:${instrCounter++}] ${instruction.toString()} (gasLeft l2=${
@@ -168,7 +161,7 @@ export class AvmSimulator {
168
161
  l2Gas: instrStartGas.l2Gas - machineState.l2GasLeft,
169
162
  daGas: instrStartGas.daGas - machineState.daGasLeft,
170
163
  };
171
- this.tallyInstructionFunction(instrPc, instruction.constructor.name, gasUsed);
164
+ this.tallyInstructionFunction(instruction.constructor.name, gasUsed);
172
165
 
173
166
  if (machineState.pc >= bytecode.length) {
174
167
  this.log.warn('Passed end of program');
@@ -239,18 +232,12 @@ export class AvmSimulator {
239
232
  );
240
233
  }
241
234
 
242
- private tallyInstruction(pc: number, opcode: string, gasUsed: Gas) {
235
+ private tallyInstruction(opcode: string, gasUsed: Gas) {
243
236
  const opcodeTally = this.opcodeTallies.get(opcode) || ({ count: 0, gas: { l2Gas: 0, daGas: 0 } } as OpcodeTally);
244
237
  opcodeTally.count++;
245
238
  opcodeTally.gas.l2Gas += gasUsed.l2Gas;
246
239
  opcodeTally.gas.daGas += gasUsed.daGas;
247
240
  this.opcodeTallies.set(opcode, opcodeTally);
248
-
249
- const pcTally = this.pcTallies.get(pc) || ({ opcode: opcode, count: 0, gas: { l2Gas: 0, daGas: 0 } } as PcTally);
250
- pcTally.count++;
251
- pcTally.gas.l2Gas += gasUsed.l2Gas;
252
- pcTally.gas.daGas += gasUsed.daGas;
253
- this.pcTallies.set(pc, pcTally);
254
241
  }
255
242
 
256
243
  private printOpcodeTallies() {
@@ -261,16 +248,5 @@ export class AvmSimulator {
261
248
  // NOTE: don't care to clutter the logs with DA gas for now
262
249
  this.log.debug(`${opcode} executed ${tally.count} times consuming a total of ${tally.gas.l2Gas} L2 gas`);
263
250
  }
264
-
265
- this.log.debug(`Printing tallies per PC sorted by #times each PC was executed...`);
266
- const sortedPcs = Array.from(this.pcTallies.entries())
267
- .sort((a, b) => b[1].count - a[1].count)
268
- .filter((_, i) => i < 20);
269
- for (const [pc, tally] of sortedPcs) {
270
- // NOTE: don't care to clutter the logs with DA gas for now
271
- this.log.debug(
272
- `PC:${pc} containing opcode ${tally.opcode} executed ${tally.count} times consuming a total of ${tally.gas.l2Gas} L2 gas`,
273
- );
274
- }
275
251
  }
276
252
  }
@@ -109,7 +109,7 @@ export class AvmEphemeralForest {
109
109
  */
110
110
  async getSiblingPath(treeId: MerkleTreeId, index: bigint): Promise<Fr[]> {
111
111
  const tree = this.treeMap.get(treeId)!;
112
- let path = tree.getSiblingPath(index);
112
+ let path = await tree.getSiblingPath(index);
113
113
  if (path === undefined) {
114
114
  // We dont have the sibling path in our tree - we have to get it from the DB
115
115
  path = (await this.treeDb.getSiblingPath(treeId, index)).toFields();
@@ -119,7 +119,7 @@ export class AvmEphemeralForest {
119
119
  const siblingIndex = index ^ 1n;
120
120
  const node = tree.getNode(siblingIndex, tree.depth - i);
121
121
  if (node !== undefined) {
122
- const nodeHash = tree.hashTree(node, i + 1);
122
+ const nodeHash = await tree.hashTree(node, i + 1);
123
123
  if (!nodeHash.equals(path[i])) {
124
124
  path[i] = nodeHash;
125
125
  }
@@ -138,17 +138,17 @@ export class AvmEphemeralForest {
138
138
  * @param newLeafPreimage - The preimage of the new leaf to be inserted.
139
139
  * @returns The sibling path of the new leaf (i.e. the insertion path)
140
140
  */
141
- appendIndexedTree<ID extends IndexedTreeId, T extends IndexedTreeLeafPreimage>(
141
+ async appendIndexedTree<ID extends IndexedTreeId, T extends IndexedTreeLeafPreimage>(
142
142
  treeId: ID,
143
143
  lowLeafIndex: bigint,
144
144
  lowLeafPreimage: T,
145
145
  newLeafPreimage: T,
146
- ): Fr[] {
146
+ ): Promise<Fr[]> {
147
147
  const tree = this.treeMap.get(treeId)!;
148
- const newLeaf = this.hashPreimage(newLeafPreimage);
148
+ const newLeaf = await this.hashPreimage(newLeafPreimage);
149
149
  const insertIndex = tree.leafCount;
150
150
 
151
- const lowLeaf = this.hashPreimage(lowLeafPreimage);
151
+ const lowLeaf = await this.hashPreimage(lowLeafPreimage);
152
152
  // Update the low nullifier hash
153
153
  this.setIndexedUpdates(treeId, lowLeafIndex, lowLeafPreimage);
154
154
  tree.updateLeaf(lowLeaf, lowLeafIndex);
@@ -156,7 +156,7 @@ export class AvmEphemeralForest {
156
156
  tree.appendLeaf(newLeaf);
157
157
  this.setIndexedUpdates(treeId, insertIndex, newLeafPreimage);
158
158
 
159
- return tree.getSiblingPath(insertIndex)!;
159
+ return (await tree.getSiblingPath(insertIndex))!;
160
160
  }
161
161
 
162
162
  /**
@@ -186,7 +186,7 @@ export class AvmEphemeralForest {
186
186
  const existingPublicDataSiblingPath = siblingPath;
187
187
  updatedPreimage.value = newValue;
188
188
 
189
- tree.updateLeaf(this.hashPreimage(updatedPreimage), lowLeafIndex);
189
+ tree.updateLeaf(await this.hashPreimage(updatedPreimage), lowLeafIndex);
190
190
  this.setIndexedUpdates(treeId, lowLeafIndex, updatedPreimage);
191
191
  this._updateSortedKeys(treeId, [updatedPreimage.slot], [lowLeafIndex]);
192
192
 
@@ -212,7 +212,7 @@ export class AvmEphemeralForest {
212
212
  new Fr(preimage.getNextKey()),
213
213
  preimage.getNextIndex(),
214
214
  );
215
- const insertionPath = this.appendIndexedTree(treeId, lowLeafIndex, updatedLowLeaf, newPublicDataLeaf);
215
+ const insertionPath = await this.appendIndexedTree(treeId, lowLeafIndex, updatedLowLeaf, newPublicDataLeaf);
216
216
 
217
217
  // Even though the low leaf key is not updated, we still need to update the sorted keys in case we have
218
218
  // not seen the low leaf before
@@ -281,7 +281,7 @@ export class AvmEphemeralForest {
281
281
  updatedLowNullifier.nextIndex = insertionIndex;
282
282
 
283
283
  const newNullifierLeaf = new NullifierLeafPreimage(nullifier, preimage.nextNullifier, preimage.nextIndex);
284
- const insertionPath = this.appendIndexedTree(treeId, index, updatedLowNullifier, newNullifierLeaf);
284
+ const insertionPath = await this.appendIndexedTree(treeId, index, updatedLowNullifier, newNullifierLeaf);
285
285
 
286
286
  // Even though the low nullifier key is not updated, we still need to update the sorted keys in case we have
287
287
  // not seen the low nullifier before
@@ -308,11 +308,11 @@ export class AvmEphemeralForest {
308
308
  * @param value - The note hash to be appended
309
309
  * @returns The insertion result which contains the insertion path
310
310
  */
311
- appendNoteHash(noteHash: Fr): Fr[] {
311
+ async appendNoteHash(noteHash: Fr): Promise<Fr[]> {
312
312
  const tree = this.treeMap.get(MerkleTreeId.NOTE_HASH_TREE)!;
313
313
  tree.appendLeaf(noteHash);
314
314
  // We use leafCount - 1 here because we would have just appended a leaf
315
- const insertionPath = tree.getSiblingPath(tree.leafCount - 1n);
315
+ const insertionPath = await tree.getSiblingPath(tree.leafCount - 1n);
316
316
  return insertionPath!;
317
317
  }
318
318
 
@@ -484,14 +484,15 @@ export class AvmEphemeralForest {
484
484
  /**
485
485
  * This hashes the preimage to a field element
486
486
  */
487
- hashPreimage<T extends TreeLeafPreimage>(preimage: T): Fr {
487
+ hashPreimage<T extends TreeLeafPreimage>(preimage: T): Promise<Fr> {
488
488
  const input = preimage.toHashInputs().map(x => Fr.fromBuffer(x));
489
489
  return poseidon2Hash(input);
490
490
  }
491
491
 
492
- getTreeSnapshot(id: MerkleTreeId): AppendOnlyTreeSnapshot {
492
+ async getTreeSnapshot(id: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
493
493
  const tree = this.treeMap.get(id)!;
494
- return new AppendOnlyTreeSnapshot(tree.getRoot(), Number(tree.leafCount));
494
+ const root = await tree.getRoot();
495
+ return new AppendOnlyTreeSnapshot(root, Number(tree.leafCount));
495
496
  }
496
497
  }
497
498
 
@@ -551,19 +552,10 @@ const Leaf = (value: Fr): Leaf => ({
551
552
  */
552
553
  export class EphemeralAvmTree {
553
554
  private tree: Tree;
554
- private readonly zeroHashes: Fr[];
555
555
  public frontier: Fr[];
556
556
 
557
- private constructor(public leafCount: bigint, public depth: number) {
558
- let zeroHash = Fr.zero();
559
- // Can probably cache this elsewhere
560
- const zeroHashes = [];
561
- for (let i = 0; i < this.depth; i++) {
562
- zeroHashes.push(zeroHash);
563
- zeroHash = poseidon2Hash([zeroHash, zeroHash]);
564
- }
565
- this.tree = Leaf(zeroHash);
566
- this.zeroHashes = zeroHashes;
557
+ private constructor(private root: Leaf, public leafCount: bigint, public depth: number, private zeroHashes: Fr[]) {
558
+ this.tree = root;
567
559
  this.frontier = [];
568
560
  }
569
561
 
@@ -573,7 +565,14 @@ export class EphemeralAvmTree {
573
565
  treeDb: MerkleTreeReadOperations,
574
566
  merkleId: MerkleTreeId,
575
567
  ): Promise<EphemeralAvmTree> {
576
- const tree = new EphemeralAvmTree(forkedLeafCount, depth);
568
+ let zeroHash = Fr.zero();
569
+ // Can probably cache this elsewhere
570
+ const zeroHashes = [];
571
+ for (let i = 0; i < depth; i++) {
572
+ zeroHashes.push(zeroHash);
573
+ zeroHash = await poseidon2Hash([zeroHash, zeroHash]);
574
+ }
575
+ const tree = new EphemeralAvmTree(Leaf(zeroHash), forkedLeafCount, depth, zeroHashes);
577
576
  await tree.initializeFrontier(treeDb, merkleId);
578
577
  return tree;
579
578
  }
@@ -604,10 +603,10 @@ export class EphemeralAvmTree {
604
603
  * @param index - The index of the leaf for which a sibling path should be returned.
605
604
  * @returns The sibling path of the leaf, can fail if the path is not found
606
605
  */
607
- getSiblingPath(index: bigint): Fr[] | undefined {
606
+ async getSiblingPath(index: bigint): Promise<Fr[] | undefined> {
608
607
  const searchPath = this._derivePathLE(index);
609
608
  // Handle cases where we error out
610
- const { path, status } = this._getSiblingPath(searchPath, this.tree, []);
609
+ const { path, status } = await this._getSiblingPath(searchPath, this.tree, []);
611
610
  if (status === SiblingStatus.ERROR) {
612
611
  return undefined;
613
612
  }
@@ -695,7 +694,7 @@ export class EphemeralAvmTree {
695
694
  /**
696
695
  * Computes the root of the tree
697
696
  */
698
- public getRoot(): Fr {
697
+ public getRoot(): Promise<Fr> {
699
698
  return this.hashTree(this.tree, this.depth);
700
699
  }
701
700
 
@@ -704,10 +703,13 @@ export class EphemeralAvmTree {
704
703
  * @param tree - The tree to be hashed
705
704
  * @param depth - The depth of the tree
706
705
  */
707
- public hashTree(tree: Tree, depth: number): Fr {
706
+ public async hashTree(tree: Tree, depth: number): Promise<Fr> {
708
707
  switch (tree.tag) {
709
708
  case TreeType.NODE: {
710
- return poseidon2Hash([this.hashTree(tree.leftTree, depth - 1), this.hashTree(tree.rightTree, depth - 1)]);
709
+ return poseidon2Hash([
710
+ await this.hashTree(tree.leftTree, depth - 1),
711
+ await this.hashTree(tree.rightTree, depth - 1),
712
+ ]);
711
713
  }
712
714
  case TreeType.LEAF: {
713
715
  return tree.value;
@@ -807,7 +809,7 @@ export class EphemeralAvmTree {
807
809
  * @param tree - The current tree
808
810
  * @param acc - The accumulated sibling path
809
811
  */
810
- private _getSiblingPath(searchPath: number[], tree: Tree, acc: Fr[]): AccumulatedSiblingPath {
812
+ private async _getSiblingPath(searchPath: number[], tree: Tree, acc: Fr[]): Promise<AccumulatedSiblingPath> {
811
813
  // If we have reached the end of the path, we should be at a leaf or empty node
812
814
  // If it is a leaf, we check if the value is equal to the leaf value
813
815
  // If it is empty we check if the value is equal to zero
@@ -824,15 +826,15 @@ export class EphemeralAvmTree {
824
826
  case TreeType.NODE: {
825
827
  // Look at the next element of the path to decided if we go left or right, note this mutates!
826
828
  return searchPath.pop() === 0
827
- ? this._getSiblingPath(
829
+ ? await this._getSiblingPath(
828
830
  searchPath,
829
831
  tree.leftTree,
830
- [this.hashTree(tree.rightTree, searchPath.length)].concat(acc),
832
+ [await this.hashTree(tree.rightTree, searchPath.length)].concat(acc),
831
833
  )
832
- : this._getSiblingPath(
834
+ : await this._getSiblingPath(
833
835
  searchPath,
834
836
  tree.rightTree,
835
- [this.hashTree(tree.leftTree, searchPath.length)].concat(acc),
837
+ [await this.hashTree(tree.leftTree, searchPath.length)].concat(acc),
836
838
  );
837
839
  }
838
840
  // In these two situations we are exploring a subtree we dont have information about
package/src/avm/errors.ts CHANGED
@@ -148,6 +148,16 @@ export class MSMPointNotOnCurveError extends AvmExecutionError {
148
148
  }
149
149
  }
150
150
 
151
+ /**
152
+ * Error is thrown when some inputs of ToRadixBE are not valid.
153
+ */
154
+ export class InvalidToRadixInputsError extends AvmExecutionError {
155
+ constructor(errorString: string) {
156
+ super(errorString);
157
+ this.name = 'InvalidToRadixInputsError';
158
+ }
159
+ }
160
+
151
161
  /**
152
162
  * Error is thrown when a static call attempts to alter some state
153
163
  */
@@ -0,0 +1,105 @@
1
+ import { type MerkleTreeWriteOperations } from '@aztec/circuit-types';
2
+ import { GasFees, GlobalVariables } from '@aztec/circuits.js';
3
+ import { encodeArguments } from '@aztec/foundation/abi';
4
+ import { type AztecAddress } from '@aztec/foundation/aztec-address';
5
+ import { Fr } from '@aztec/foundation/fields';
6
+ import { openTmpStore } from '@aztec/kv-store/lmdb';
7
+ import { MerkleTrees } from '@aztec/world-state';
8
+
9
+ import { type AvmContractCallResult } from '../../avm/avm_contract_call_result.js';
10
+ import {
11
+ getContractFunctionArtifact,
12
+ getFunctionSelector,
13
+ initContext,
14
+ initExecutionEnvironment,
15
+ resolveContractAssertionMessage,
16
+ } from '../../avm/fixtures/index.js';
17
+ import { WorldStateDB } from '../../public/public_db_sources.js';
18
+ import { SideEffectTrace } from '../../public/side_effect_trace.js';
19
+ import { AvmPersistableStateManager, AvmSimulator } from '../../server.js';
20
+ import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
21
+ import { SimpleContractDataSource } from './simple_contract_data_source.js';
22
+
23
+ const TIMESTAMP = new Fr(99833);
24
+ const DEFAULT_GAS_FEES = new GasFees(2, 3);
25
+
26
+ /**
27
+ * A test class that extends the BaseAvmSimulationTester to enable real-app testing of the core AvmSimulator.
28
+ * It provides an interface for simulating one top-level call at a time and maintains state between
29
+ * subsequent top-level calls.
30
+ */
31
+ export class AvmSimulationTester extends BaseAvmSimulationTester {
32
+ constructor(
33
+ contractDataSource: SimpleContractDataSource,
34
+ merkleTrees: MerkleTreeWriteOperations,
35
+ skipContractDeployments = false,
36
+ private stateManager: AvmPersistableStateManager,
37
+ ) {
38
+ super(contractDataSource, merkleTrees, skipContractDeployments);
39
+ }
40
+
41
+ static async create(skipContractDeployments = false): Promise<AvmSimulationTester> {
42
+ const contractDataSource = new SimpleContractDataSource();
43
+ const merkleTrees = await (await MerkleTrees.new(openTmpStore())).fork();
44
+ const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
45
+ const trace = new SideEffectTrace();
46
+ const firstNullifier = new Fr(420000);
47
+ // FIXME: merkle ops should work, but I'm seeing frequent (but inconsistent) bytecode retrieval
48
+ // failures on 2nd call to simulateCall with merkle ops on
49
+ const stateManager = await AvmPersistableStateManager.create(
50
+ worldStateDB,
51
+ trace,
52
+ /*doMerkleOperations=*/ false,
53
+ firstNullifier,
54
+ );
55
+ return new AvmSimulationTester(contractDataSource, merkleTrees, skipContractDeployments, stateManager);
56
+ }
57
+
58
+ /**
59
+ * Simulate a top-level contract call.
60
+ */
61
+ async simulateCall(
62
+ sender: AztecAddress,
63
+ address: AztecAddress,
64
+ fnName: string,
65
+ args: any[],
66
+ isStaticCall = false,
67
+ ): Promise<AvmContractCallResult> {
68
+ const contractArtifact = await this.contractDataSource.getContractArtifact(address);
69
+ if (!contractArtifact) {
70
+ throw new Error(`Contract not found at address: ${address}`);
71
+ }
72
+ const fnSelector = await getFunctionSelector(fnName, contractArtifact);
73
+ const fnAbi = getContractFunctionArtifact(fnName, contractArtifact);
74
+ const encodedArgs = encodeArguments(fnAbi!, args);
75
+ const calldata = [fnSelector.toField(), ...encodedArgs];
76
+
77
+ const globals = GlobalVariables.empty();
78
+ globals.timestamp = TIMESTAMP;
79
+ globals.gasFees = DEFAULT_GAS_FEES;
80
+
81
+ const environment = initExecutionEnvironment({
82
+ calldata,
83
+ globals,
84
+ address,
85
+ sender,
86
+ isStaticCall,
87
+ });
88
+ const persistableState = this.stateManager.fork();
89
+ const context = initContext({ env: environment, persistableState });
90
+
91
+ // First we simulate (though it's not needed in this simple case).
92
+ const simulator = new AvmSimulator(context);
93
+ const result = await simulator.execute();
94
+ if (result.reverted) {
95
+ this.logger.error(`Error in ${fnName}:`);
96
+ this.logger.error(
97
+ resolveContractAssertionMessage(fnName, result.revertReason!, result.output, contractArtifact)!,
98
+ );
99
+ } else {
100
+ this.logger.info(`Simulation of function ${fnName} succeeded!`);
101
+ this.stateManager.merge(persistableState);
102
+ }
103
+ return result;
104
+ }
105
+ }