@aztec/simulator 0.26.5 → 0.27.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 (70) hide show
  1. package/dest/acvm/acvm.js +2 -2
  2. package/dest/acvm/serialize.d.ts.map +1 -1
  3. package/dest/acvm/serialize.js +8 -3
  4. package/dest/avm/avm_context.d.ts +3 -3
  5. package/dest/avm/avm_context.d.ts.map +1 -1
  6. package/dest/avm/avm_context.js +6 -5
  7. package/dest/avm/avm_execution_environment.d.ts +3 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +16 -17
  10. package/dest/avm/avm_memory_types.d.ts +10 -0
  11. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  12. package/dest/avm/avm_memory_types.js +39 -4
  13. package/dest/avm/avm_simulator.d.ts.map +1 -1
  14. package/dest/avm/avm_simulator.js +3 -3
  15. package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
  16. package/dest/avm/opcodes/addressing_mode.js +3 -3
  17. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  18. package/dest/avm/opcodes/arithmetic.js +2 -1
  19. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  20. package/dest/avm/opcodes/comparators.js +5 -7
  21. package/dest/avm/opcodes/control_flow.d.ts +0 -20
  22. package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
  23. package/dest/avm/opcodes/control_flow.js +2 -46
  24. package/dest/avm/opcodes/external_calls.d.ts +24 -2
  25. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  26. package/dest/avm/opcodes/external_calls.js +74 -17
  27. package/dest/avm/opcodes/storage.d.ts +4 -3
  28. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  29. package/dest/avm/opcodes/storage.js +23 -12
  30. package/dest/avm/serialization/instruction_serialization.d.ts +1 -2
  31. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  32. package/dest/avm/serialization/instruction_serialization.js +9 -3
  33. package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
  34. package/dest/avm/temporary_executor_migration.js +6 -1
  35. package/dest/client/client_execution_context.d.ts.map +1 -1
  36. package/dest/client/client_execution_context.js +4 -6
  37. package/dest/client/simulator.d.ts.map +1 -1
  38. package/dest/client/simulator.js +3 -3
  39. package/dest/index.d.ts +2 -1
  40. package/dest/index.d.ts.map +1 -1
  41. package/dest/index.js +3 -2
  42. package/dest/public/execution.d.ts +13 -12
  43. package/dest/public/execution.d.ts.map +1 -1
  44. package/dest/public/execution.js +2 -2
  45. package/dest/public/executor.d.ts +22 -1
  46. package/dest/public/executor.d.ts.map +1 -1
  47. package/dest/public/executor.js +137 -13
  48. package/dest/public/public_execution_context.d.ts.map +1 -1
  49. package/dest/public/public_execution_context.js +2 -3
  50. package/package.json +5 -5
  51. package/src/acvm/acvm.ts +1 -1
  52. package/src/acvm/serialize.ts +9 -3
  53. package/src/avm/avm_context.ts +21 -5
  54. package/src/avm/avm_execution_environment.ts +27 -12
  55. package/src/avm/avm_memory_types.ts +42 -3
  56. package/src/avm/avm_simulator.ts +10 -3
  57. package/src/avm/opcodes/addressing_mode.ts +3 -2
  58. package/src/avm/opcodes/arithmetic.ts +2 -0
  59. package/src/avm/opcodes/comparators.ts +4 -6
  60. package/src/avm/opcodes/control_flow.ts +1 -47
  61. package/src/avm/opcodes/external_calls.ts +88 -14
  62. package/src/avm/opcodes/storage.ts +37 -18
  63. package/src/avm/serialization/instruction_serialization.ts +8 -2
  64. package/src/avm/temporary_executor_migration.ts +6 -0
  65. package/src/client/client_execution_context.ts +1 -13
  66. package/src/client/simulator.ts +1 -2
  67. package/src/index.ts +2 -1
  68. package/src/public/execution.ts +15 -14
  69. package/src/public/executor.ts +157 -13
  70. package/src/public/public_execution_context.ts +1 -2
@@ -11,6 +11,8 @@ export class Add extends ThreeOperandInstruction {
11
11
  }
12
12
 
13
13
  async execute(context: AvmContext): Promise<void> {
14
+ context.machineState.memory.checkTags(this.inTag, this.aOffset, this.bOffset);
15
+
14
16
  const a = context.machineState.memory.get(this.aOffset);
15
17
  const b = context.machineState.memory.get(this.bOffset);
16
18
 
@@ -1,4 +1,5 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
+ import { TaggedMemory } from '../avm_memory_types.js';
2
3
  import { Opcode } from '../serialization/instruction_serialization.js';
3
4
  import { ThreeOperandInstruction } from './instruction_impl.js';
4
5
 
@@ -16,8 +17,7 @@ export class Eq extends ThreeOperandInstruction {
16
17
  const a = context.machineState.memory.get(this.aOffset);
17
18
  const b = context.machineState.memory.get(this.bOffset);
18
19
 
19
- // Result will be of the same type as 'a'.
20
- const dest = a.build(a.equals(b) ? 1n : 0n);
20
+ const dest = TaggedMemory.buildFromTagOrDie(a.equals(b) ? 1n : 0n, this.inTag);
21
21
  context.machineState.memory.set(this.dstOffset, dest);
22
22
 
23
23
  context.machineState.incrementPc();
@@ -38,8 +38,7 @@ export class Lt extends ThreeOperandInstruction {
38
38
  const a = context.machineState.memory.get(this.aOffset);
39
39
  const b = context.machineState.memory.get(this.bOffset);
40
40
 
41
- // Result will be of the same type as 'a'.
42
- const dest = a.build(a.lt(b) ? 1n : 0n);
41
+ const dest = TaggedMemory.buildFromTagOrDie(a.lt(b) ? 1n : 0n, this.inTag);
43
42
  context.machineState.memory.set(this.dstOffset, dest);
44
43
 
45
44
  context.machineState.incrementPc();
@@ -60,8 +59,7 @@ export class Lte extends ThreeOperandInstruction {
60
59
  const a = context.machineState.memory.get(this.aOffset);
61
60
  const b = context.machineState.memory.get(this.bOffset);
62
61
 
63
- // Result will be of the same type as 'a'.
64
- const dest = a.build(a.equals(b) || a.lt(b) ? 1n : 0n);
62
+ const dest = TaggedMemory.buildFromTagOrDie(a.lt(b) || a.equals(b) ? 1n : 0n, this.inTag);
65
63
  context.machineState.memory.set(this.dstOffset, dest);
66
64
 
67
65
  context.machineState.incrementPc();
@@ -4,52 +4,6 @@ import { InstructionExecutionError } from '../errors.js';
4
4
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
5
  import { Instruction } from './instruction.js';
6
6
 
7
- export class Return extends Instruction {
8
- static type: string = 'RETURN';
9
- static readonly opcode: Opcode = Opcode.RETURN;
10
- // Informs (de)serialization. See Instruction.deserialize.
11
- static readonly wireFormat: OperandType[] = [
12
- OperandType.UINT8,
13
- OperandType.UINT8,
14
- OperandType.UINT32,
15
- OperandType.UINT32,
16
- ];
17
-
18
- constructor(private indirect: number, private returnOffset: number, private copySize: number) {
19
- super();
20
- }
21
-
22
- async execute(context: AvmContext): Promise<void> {
23
- const output = context.machineState.memory.getSlice(this.returnOffset, this.copySize).map(word => word.toFr());
24
-
25
- context.machineState.return(output);
26
- }
27
- }
28
-
29
- export class Revert extends Instruction {
30
- static type: string = 'RETURN';
31
- static readonly opcode: Opcode = Opcode.REVERT;
32
- // Informs (de)serialization. See Instruction.deserialize.
33
- static readonly wireFormat: OperandType[] = [
34
- OperandType.UINT8,
35
- OperandType.UINT8,
36
- OperandType.UINT32,
37
- OperandType.UINT32,
38
- ];
39
-
40
- constructor(private indirect: number, private returnOffset: number, private retSize: number) {
41
- super();
42
- }
43
-
44
- async execute(context: AvmContext): Promise<void> {
45
- const output = context.machineState.memory
46
- .getSlice(this.returnOffset, this.returnOffset + this.retSize)
47
- .map(word => word.toFr());
48
-
49
- context.machineState.revert(output);
50
- }
51
- }
52
-
53
7
  export class Jump extends Instruction {
54
8
  static type: string = 'JUMP';
55
9
  static readonly opcode: Opcode = Opcode.JUMP;
@@ -122,7 +76,7 @@ export class InternalReturn extends Instruction {
122
76
  async execute(context: AvmContext): Promise<void> {
123
77
  const jumpOffset = context.machineState.internalCallStack.pop();
124
78
  if (jumpOffset === undefined) {
125
- throw new InstructionExecutionError('Internal call empty!');
79
+ throw new InstructionExecutionError('Internal call stack empty!');
126
80
  }
127
81
  context.machineState.pc = jumpOffset;
128
82
  }
@@ -1,9 +1,10 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { FunctionSelector } from '@aztec/circuits.js';
2
2
 
3
3
  import type { AvmContext } from '../avm_context.js';
4
- import { Field } from '../avm_memory_types.js';
4
+ import { Field, Uint8 } from '../avm_memory_types.js';
5
5
  import { AvmSimulator } from '../avm_simulator.js';
6
6
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
7
+ import { Addressing } from './addressing_mode.js';
7
8
  import { Instruction } from './instruction.js';
8
9
 
9
10
  export class Call extends Instruction {
@@ -20,6 +21,8 @@ export class Call extends Instruction {
20
21
  OperandType.UINT32,
21
22
  OperandType.UINT32,
22
23
  OperandType.UINT32,
24
+ /* temporary function selector */
25
+ OperandType.UINT32,
23
26
  ];
24
27
 
25
28
  constructor(
@@ -31,16 +34,30 @@ export class Call extends Instruction {
31
34
  private retOffset: number,
32
35
  private retSize: number,
33
36
  private successOffset: number,
37
+ // Function selector is temporary since eventually public contract bytecode will be one blob
38
+ // containing all functions, and function selector will become an application-level mechanism
39
+ // (e.g. first few bytes of calldata + compiler-generated jump table)
40
+ private temporaryFunctionSelectorOffset: number,
34
41
  ) {
35
42
  super();
36
43
  }
37
44
 
38
45
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3992): there is no concept of remaining / available gas at this moment
39
46
  async execute(context: AvmContext): Promise<void> {
40
- const callAddress = context.machineState.memory.getAs<Field>(this.addrOffset);
41
- const calldata = context.machineState.memory.getSlice(this.argsOffset, this.argsSize).map(f => f.toFr());
47
+ const [_gasOffset, addrOffset, argsOffset, retOffset, successOffset] = Addressing.fromWire(this.indirect).resolve(
48
+ [this._gasOffset, this.addrOffset, this.argsOffset, this.retOffset, this.successOffset],
49
+ context.machineState.memory,
50
+ );
51
+
52
+ const callAddress = context.machineState.memory.getAs<Field>(addrOffset);
53
+ const calldata = context.machineState.memory.getSlice(argsOffset, this.argsSize).map(f => f.toFr());
54
+ const functionSelector = context.machineState.memory.getAs<Field>(this.temporaryFunctionSelectorOffset).toFr();
42
55
 
43
- const nestedContext = context.createNestedContractCallContext(callAddress.toFr(), calldata);
56
+ const nestedContext = context.createNestedContractCallContext(
57
+ callAddress.toFr(),
58
+ calldata,
59
+ FunctionSelector.fromField(functionSelector),
60
+ );
44
61
 
45
62
  const nestedCallResults = await new AvmSimulator(nestedContext).execute();
46
63
  const success = !nestedCallResults.reverted;
@@ -50,8 +67,8 @@ export class Call extends Instruction {
50
67
  const convertedReturnData = returnData.map(f => new Field(f));
51
68
 
52
69
  // Write our return data into memory
53
- context.machineState.memory.set(this.successOffset, new Field(success ? 1 : 0));
54
- context.machineState.memory.setSlice(this.retOffset, convertedReturnData);
70
+ context.machineState.memory.set(successOffset, new Uint8(success ? 1 : 0));
71
+ context.machineState.memory.setSlice(retOffset, convertedReturnData);
55
72
 
56
73
  if (success) {
57
74
  context.persistableState.acceptNestedCallState(nestedContext.persistableState);
@@ -77,6 +94,8 @@ export class StaticCall extends Instruction {
77
94
  OperandType.UINT32,
78
95
  OperandType.UINT32,
79
96
  OperandType.UINT32,
97
+ /* temporary function selector */
98
+ OperandType.UINT32,
80
99
  ];
81
100
 
82
101
  constructor(
@@ -88,17 +107,26 @@ export class StaticCall extends Instruction {
88
107
  private retOffset: number,
89
108
  private retSize: number,
90
109
  private successOffset: number,
110
+ private temporaryFunctionSelectorOffset: number,
91
111
  ) {
92
112
  super();
93
113
  }
94
114
 
95
115
  async execute(context: AvmContext): Promise<void> {
96
- const callAddress = context.machineState.memory.get(this.addrOffset);
97
- const calldata = context.machineState.memory
98
- .getSlice(this.argsOffset, this.argsSize)
99
- .map(f => new Fr(f.toBigInt()));
116
+ const [_gasOffset, addrOffset, argsOffset, retOffset, successOffset] = Addressing.fromWire(this.indirect).resolve(
117
+ [this._gasOffset, this.addrOffset, this.argsOffset, this.retOffset, this.successOffset],
118
+ context.machineState.memory,
119
+ );
100
120
 
101
- const nestedContext = context.createNestedContractStaticCallContext(callAddress.toFr(), calldata);
121
+ const callAddress = context.machineState.memory.get(addrOffset);
122
+ const calldata = context.machineState.memory.getSlice(argsOffset, this.argsSize).map(f => f.toFr());
123
+ const functionSelector = context.machineState.memory.getAs<Field>(this.temporaryFunctionSelectorOffset).toFr();
124
+
125
+ const nestedContext = context.createNestedContractStaticCallContext(
126
+ callAddress.toFr(),
127
+ calldata,
128
+ FunctionSelector.fromField(functionSelector),
129
+ );
102
130
 
103
131
  const nestedCallResults = await new AvmSimulator(nestedContext).execute();
104
132
  const success = !nestedCallResults.reverted;
@@ -108,8 +136,8 @@ export class StaticCall extends Instruction {
108
136
  const convertedReturnData = returnData.map(f => new Field(f));
109
137
 
110
138
  // Write our return data into memory
111
- context.machineState.memory.set(this.successOffset, new Field(success ? 1 : 0));
112
- context.machineState.memory.setSlice(this.retOffset, convertedReturnData);
139
+ context.machineState.memory.set(successOffset, new Uint8(success ? 1 : 0));
140
+ context.machineState.memory.setSlice(retOffset, convertedReturnData);
113
141
 
114
142
  if (success) {
115
143
  context.persistableState.acceptNestedCallState(nestedContext.persistableState);
@@ -120,3 +148,49 @@ export class StaticCall extends Instruction {
120
148
  context.machineState.incrementPc();
121
149
  }
122
150
  }
151
+
152
+ export class Return extends Instruction {
153
+ static type: string = 'RETURN';
154
+ static readonly opcode: Opcode = Opcode.RETURN;
155
+ // Informs (de)serialization. See Instruction.deserialize.
156
+ static readonly wireFormat: OperandType[] = [
157
+ OperandType.UINT8,
158
+ OperandType.UINT8,
159
+ OperandType.UINT32,
160
+ OperandType.UINT32,
161
+ ];
162
+
163
+ constructor(private indirect: number, private returnOffset: number, private copySize: number) {
164
+ super();
165
+ }
166
+
167
+ async execute(context: AvmContext): Promise<void> {
168
+ const output = context.machineState.memory.getSlice(this.returnOffset, this.copySize).map(word => word.toFr());
169
+
170
+ context.machineState.return(output);
171
+ }
172
+ }
173
+
174
+ export class Revert extends Instruction {
175
+ static type: string = 'RETURN';
176
+ static readonly opcode: Opcode = Opcode.REVERT;
177
+ // Informs (de)serialization. See Instruction.deserialize.
178
+ static readonly wireFormat: OperandType[] = [
179
+ OperandType.UINT8,
180
+ OperandType.UINT8,
181
+ OperandType.UINT32,
182
+ OperandType.UINT32,
183
+ ];
184
+
185
+ constructor(private indirect: number, private returnOffset: number, private retSize: number) {
186
+ super();
187
+ }
188
+
189
+ async execute(context: AvmContext): Promise<void> {
190
+ const output = context.machineState.memory
191
+ .getSlice(this.returnOffset, this.returnOffset + this.retSize)
192
+ .map(word => word.toFr());
193
+
194
+ context.machineState.revert(output);
195
+ }
196
+ }
@@ -4,6 +4,7 @@ import type { AvmContext } from '../avm_context.js';
4
4
  import { Field } from '../avm_memory_types.js';
5
5
  import { InstructionExecutionError } from '../errors.js';
6
6
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
7
+ import { Addressing } from './addressing_mode.js';
7
8
  import { Instruction } from './instruction.js';
8
9
 
9
10
  abstract class BaseStorageInstruction extends Instruction {
@@ -13,9 +14,15 @@ abstract class BaseStorageInstruction extends Instruction {
13
14
  OperandType.UINT8,
14
15
  OperandType.UINT32,
15
16
  OperandType.UINT32,
17
+ OperandType.UINT32,
16
18
  ];
17
19
 
18
- constructor(protected indirect: number, protected aOffset: number, protected bOffset: number) {
20
+ constructor(
21
+ protected indirect: number,
22
+ protected aOffset: number,
23
+ protected /*temporary*/ size: number,
24
+ protected bOffset: number,
25
+ ) {
19
26
  super();
20
27
  }
21
28
  }
@@ -24,8 +31,8 @@ export class SStore extends BaseStorageInstruction {
24
31
  static readonly type: string = 'SSTORE';
25
32
  static readonly opcode = Opcode.SSTORE;
26
33
 
27
- constructor(indirect: number, srcOffset: number, slotOffset: number) {
28
- super(indirect, srcOffset, slotOffset);
34
+ constructor(indirect: number, srcOffset: number, /*temporary*/ srcSize: number, slotOffset: number) {
35
+ super(indirect, srcOffset, srcSize, slotOffset);
29
36
  }
30
37
 
31
38
  async execute(context: AvmContext): Promise<void> {
@@ -33,15 +40,19 @@ export class SStore extends BaseStorageInstruction {
33
40
  throw new StaticCallStorageAlterError();
34
41
  }
35
42
 
36
- const slot = context.machineState.memory.get(this.aOffset);
37
- const data = context.machineState.memory.get(this.bOffset);
38
-
39
- context.persistableState.writeStorage(
40
- context.environment.storageAddress,
41
- new Fr(slot.toBigInt()),
42
- new Fr(data.toBigInt()),
43
+ const [srcOffset, slotOffset] = Addressing.fromWire(this.indirect).resolve(
44
+ [this.aOffset, this.bOffset],
45
+ context.machineState.memory,
43
46
  );
44
47
 
48
+ const slot = context.machineState.memory.get(slotOffset).toFr();
49
+ const data = context.machineState.memory.getSlice(srcOffset, this.size).map(field => field.toFr());
50
+
51
+ for (const [index, value] of Object.entries(data)) {
52
+ const adjustedSlot = slot.add(new Fr(BigInt(index)));
53
+ context.persistableState.writeStorage(context.environment.storageAddress, adjustedSlot, value);
54
+ }
55
+
45
56
  context.machineState.incrementPc();
46
57
  }
47
58
  }
@@ -50,19 +61,27 @@ export class SLoad extends BaseStorageInstruction {
50
61
  static readonly type: string = 'SLOAD';
51
62
  static readonly opcode = Opcode.SLOAD;
52
63
 
53
- constructor(indirect: number, slotOffset: number, dstOffset: number) {
54
- super(indirect, slotOffset, dstOffset);
64
+ constructor(indirect: number, slotOffset: number, size: number, dstOffset: number) {
65
+ super(indirect, slotOffset, size, dstOffset);
55
66
  }
56
67
 
57
68
  async execute(context: AvmContext): Promise<void> {
58
- const slot = context.machineState.memory.get(this.aOffset);
59
-
60
- const data: Fr = await context.persistableState.readStorage(
61
- context.environment.storageAddress,
62
- new Fr(slot.toBigInt()),
69
+ const [aOffset, size, bOffset] = Addressing.fromWire(this.indirect).resolve(
70
+ [this.aOffset, this.size, this.bOffset],
71
+ context.machineState.memory,
63
72
  );
64
73
 
65
- context.machineState.memory.set(this.bOffset, new Field(data));
74
+ const slot = context.machineState.memory.get(aOffset);
75
+
76
+ // Write each read value from storage into memory
77
+ for (let i = 0; i < size; i++) {
78
+ const data: Fr = await context.persistableState.readStorage(
79
+ context.environment.storageAddress,
80
+ new Fr(slot.toBigInt() + BigInt(i)),
81
+ );
82
+
83
+ context.machineState.memory.set(bOffset + i, new Field(data));
84
+ }
66
85
 
67
86
  context.machineState.incrementPc();
68
87
  }
@@ -7,6 +7,7 @@ import { BufferCursor } from './buffer_cursor.js';
7
7
  * Source: https://yp-aztec.netlify.app/docs/public-vm/instruction-set
8
8
  */
9
9
  export enum Opcode {
10
+ // Compute
10
11
  ADD,
11
12
  SUB,
12
13
  MUL,
@@ -21,6 +22,7 @@ export enum Opcode {
21
22
  SHL,
22
23
  SHR,
23
24
  CAST,
25
+ // Execution environment
24
26
  ADDRESS,
25
27
  STORAGEADDRESS,
26
28
  ORIGIN,
@@ -39,16 +41,20 @@ export enum Opcode {
39
41
  BLOCKL2GASLIMIT,
40
42
  BLOCKDAGASLIMIT,
41
43
  CALLDATACOPY,
44
+ // Gas
42
45
  L1GASLEFT,
43
46
  L2GASLEFT,
44
47
  DAGASLEFT,
48
+ // Control flow
45
49
  JUMP,
46
50
  JUMPI,
47
51
  INTERNALCALL,
48
52
  INTERNALRETURN,
53
+ // Memory
49
54
  SET,
50
55
  MOV,
51
56
  CMOV,
57
+ // World state
52
58
  SLOAD,
53
59
  SSTORE,
54
60
  NOTEHASHEXISTS,
@@ -59,17 +65,17 @@ export enum Opcode {
59
65
  HEADERMEMBER,
60
66
  EMITUNENCRYPTEDLOG,
61
67
  SENDL2TOL1MSG,
68
+ // External calls
62
69
  CALL,
63
70
  STATICCALL,
64
71
  DELEGATECALL,
65
72
  RETURN,
66
73
  REVERT,
74
+ // Gadgets
67
75
  KECCAK,
68
76
  POSEIDON,
69
- // Add new opcodes before this
70
77
  SHA256, // temp - may be removed, but alot of contracts rely on it
71
78
  PEDERSEN, // temp - may be removed, but alot of contracts rely on it
72
- TOTAL_OPCODES_NUMBER,
73
79
  }
74
80
 
75
81
  // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
@@ -5,11 +5,13 @@ import {
5
5
  ContractStorageUpdateRequest,
6
6
  GlobalVariables,
7
7
  L2ToL1Message,
8
+ ReadRequest,
8
9
  SideEffect,
9
10
  SideEffectLinkedToNoteHash,
10
11
  } from '@aztec/circuits.js';
11
12
  import { Fr } from '@aztec/foundation/fields';
12
13
 
14
+ import { createSimulationError } from '../common/errors.js';
13
15
  import { PublicExecution, PublicExecutionResult } from '../public/execution.js';
14
16
  import { AvmExecutionEnvironment } from './avm_execution_environment.js';
15
17
  import { AvmContractCallResults } from './avm_message_call_result.js';
@@ -91,12 +93,14 @@ export function temporaryConvertAvmResults(
91
93
  // TODO(follow up in pr tree): NOT SUPPORTED YET, make sure hashing and log resolution is done correctly
92
94
  // Disabled.
93
95
  const nestedExecutions: PublicExecutionResult[] = [];
96
+ const nullifierReadRequests: ReadRequest[] = [];
94
97
  const newNullifiers: SideEffectLinkedToNoteHash[] = [];
95
98
  const unencryptedLogs = FunctionL2Logs.empty();
96
99
  const newL2ToL1Messages = newWorldState.newL1Messages.map(() => L2ToL1Message.empty());
97
100
 
98
101
  return {
99
102
  execution,
103
+ nullifierReadRequests,
100
104
  newNoteHashes,
101
105
  newL2ToL1Messages,
102
106
  newNullifiers,
@@ -105,5 +109,7 @@ export function temporaryConvertAvmResults(
105
109
  returnValues,
106
110
  nestedExecutions,
107
111
  unencryptedLogs,
112
+ reverted: result.reverted,
113
+ revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
108
114
  };
109
115
  }
@@ -10,7 +10,6 @@ import {
10
10
  } from '@aztec/circuit-types';
11
11
  import {
12
12
  CallContext,
13
- ContractDeploymentData,
14
13
  FunctionData,
15
14
  FunctionSelector,
16
15
  Header,
@@ -89,8 +88,6 @@ export class ClientExecutionContext extends ViewDataOracle {
89
88
  * @returns The initial witness.
90
89
  */
91
90
  public getInitialWitness(abi: FunctionAbi) {
92
- const contractDeploymentData = this.txContext.contractDeploymentData;
93
-
94
91
  const argumentsSize = countArgumentsSize(abi);
95
92
 
96
93
  const args = this.packedArgsCache.unpack(this.argsHash);
@@ -102,7 +99,6 @@ export class ClientExecutionContext extends ViewDataOracle {
102
99
  const fields = [
103
100
  ...this.callContext.toFields(),
104
101
  ...this.historicalHeader.toFields(),
105
- ...contractDeploymentData.toFields(),
106
102
 
107
103
  this.txContext.chainId,
108
104
  this.txContext.version,
@@ -348,14 +344,7 @@ export class ClientExecutionContext extends ViewDataOracle {
348
344
  const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
349
345
  const targetFunctionData = FunctionData.fromAbi(targetArtifact);
350
346
 
351
- const derivedTxContext = new TxContext(
352
- false,
353
- false,
354
- false,
355
- ContractDeploymentData.empty(),
356
- this.txContext.chainId,
357
- this.txContext.version,
358
- );
347
+ const derivedTxContext = new TxContext(false, false, this.txContext.chainId, this.txContext.version);
359
348
 
360
349
  const derivedCallContext = await this.deriveCallContext(
361
350
  targetContractAddress,
@@ -470,7 +459,6 @@ export class ClientExecutionContext extends ViewDataOracle {
470
459
  FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
471
460
  isDelegateCall,
472
461
  isStaticCall,
473
- false,
474
462
  startSideEffectCounter,
475
463
  );
476
464
  }
@@ -92,10 +92,9 @@ export class AcirSimulator {
92
92
  FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
93
93
  false,
94
94
  false,
95
- request.functionData.isConstructor,
96
95
  // TODO: when contract deployment is done in-app, we should only reserve one counter for the tx hash
97
96
  // 2 counters are reserved for tx hash and contract deployment nullifier
98
- request.txContext.isContractDeploymentTx ? 2 : 1,
97
+ 1,
99
98
  );
100
99
  const context = new ClientExecutionContext(
101
100
  contractAddress,
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from './client/index.js';
2
1
  export * from './acvm/index.js';
2
+ export * from './client/index.js';
3
+ export * from './common/index.js';
3
4
  export * from './public/index.js';
@@ -1,14 +1,14 @@
1
- import { FunctionL2Logs } from '@aztec/circuit-types';
1
+ import { FunctionL2Logs, SimulationError } from '@aztec/circuit-types';
2
2
  import {
3
3
  AztecAddress,
4
- CallContext,
5
4
  ContractStorageRead,
6
5
  ContractStorageUpdateRequest,
7
6
  Fr,
8
- FunctionData,
9
7
  L2ToL1Message,
8
+ PublicCallRequest,
10
9
  PublicDataRead,
11
10
  PublicDataUpdateRequest,
11
+ ReadRequest,
12
12
  SideEffect,
13
13
  SideEffectLinkedToNoteHash,
14
14
  } from '@aztec/circuits.js';
@@ -28,6 +28,8 @@ export interface PublicExecutionResult {
28
28
  newL2ToL1Messages: L2ToL1Message[];
29
29
  /** The new nullifiers to be inserted into the nullifier tree. */
30
30
  newNullifiers: SideEffectLinkedToNoteHash[];
31
+ /** The nullifier read requests emitted in this call. */
32
+ nullifierReadRequests: ReadRequest[];
31
33
  /** The contract storage reads performed by the function. */
32
34
  contractStorageReads: ContractStorageRead[];
33
35
  /** The contract storage update requests performed by the function. */
@@ -39,21 +41,20 @@ export interface PublicExecutionResult {
39
41
  * Note: These are preimages to `unencryptedLogsHash`.
40
42
  */
41
43
  unencryptedLogs: FunctionL2Logs;
44
+ /**
45
+ * Whether the execution reverted.
46
+ */
47
+ reverted: boolean;
48
+ /**
49
+ * The revert reason if the execution reverted.
50
+ */
51
+ revertReason: SimulationError | undefined;
42
52
  }
43
53
 
44
54
  /**
45
55
  * The execution of a public function.
46
56
  */
47
- export interface PublicExecution {
48
- /** Address of the contract being executed. */
49
- contractAddress: AztecAddress;
50
- /** Function of the contract being called. */
51
- functionData: FunctionData;
52
- /** Arguments for the call. */
53
- args: Fr[];
54
- /** Context of the call. */
55
- callContext: CallContext;
56
- }
57
+ export type PublicExecution = Pick<PublicCallRequest, 'contractAddress' | 'functionData' | 'callContext' | 'args'>;
57
58
 
58
59
  /**
59
60
  * Returns if the input is a public execution result and not just a public execution.
@@ -63,7 +64,7 @@ export interface PublicExecution {
63
64
  export function isPublicExecutionResult(
64
65
  input: PublicExecution | PublicExecutionResult,
65
66
  ): input is PublicExecutionResult {
66
- return !!(input as PublicExecutionResult).execution;
67
+ return 'execution' in input && input.execution !== undefined;
67
68
  }
68
69
 
69
70
  /**