@aztec/simulator 0.53.0 → 0.55.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 (60) hide show
  1. package/dest/avm/avm_execution_environment.d.ts +2 -2
  2. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  3. package/dest/avm/avm_execution_environment.js +5 -6
  4. package/dest/avm/avm_gas.d.ts.map +1 -1
  5. package/dest/avm/avm_gas.js +85 -41
  6. package/dest/avm/avm_memory_types.d.ts +1 -1
  7. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  8. package/dest/avm/avm_memory_types.js +5 -3
  9. package/dest/avm/bytecode_utils.js +5 -5
  10. package/dest/avm/opcodes/arithmetic.d.ts +9 -16
  11. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  12. package/dest/avm/opcodes/arithmetic.js +12 -37
  13. package/dest/avm/opcodes/bitwise.d.ts +6 -6
  14. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  15. package/dest/avm/opcodes/bitwise.js +7 -7
  16. package/dest/avm/opcodes/comparators.d.ts +3 -3
  17. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  18. package/dest/avm/opcodes/comparators.js +4 -4
  19. package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
  20. package/dest/avm/opcodes/control_flow.js +6 -6
  21. package/dest/avm/opcodes/external_calls.d.ts +2 -1
  22. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  23. package/dest/avm/opcodes/external_calls.js +11 -6
  24. package/dest/avm/opcodes/instruction.d.ts +18 -12
  25. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  26. package/dest/avm/opcodes/instruction.js +36 -19
  27. package/dest/avm/opcodes/instruction_impl.d.ts +10 -6
  28. package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
  29. package/dest/avm/opcodes/instruction_impl.js +29 -13
  30. package/dest/avm/opcodes/memory.d.ts +9 -10
  31. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  32. package/dest/avm/opcodes/memory.js +60 -60
  33. package/dest/avm/serialization/bytecode_serialization.d.ts +7 -8
  34. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  35. package/dest/avm/serialization/bytecode_serialization.js +86 -64
  36. package/dest/avm/serialization/instruction_serialization.d.ts +87 -64
  37. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  38. package/dest/avm/serialization/instruction_serialization.js +105 -67
  39. package/dest/public/hints_builder.d.ts +3 -4
  40. package/dest/public/hints_builder.d.ts.map +1 -1
  41. package/dest/public/hints_builder.js +2 -5
  42. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  43. package/dest/public/tail_phase_manager.js +2 -3
  44. package/package.json +9 -9
  45. package/src/avm/avm_execution_environment.ts +3 -4
  46. package/src/avm/avm_gas.ts +84 -40
  47. package/src/avm/avm_memory_types.ts +4 -2
  48. package/src/avm/bytecode_utils.ts +4 -4
  49. package/src/avm/opcodes/arithmetic.ts +12 -41
  50. package/src/avm/opcodes/bitwise.ts +6 -6
  51. package/src/avm/opcodes/comparators.ts +3 -3
  52. package/src/avm/opcodes/control_flow.ts +5 -5
  53. package/src/avm/opcodes/external_calls.ts +11 -5
  54. package/src/avm/opcodes/instruction.ts +41 -19
  55. package/src/avm/opcodes/instruction_impl.ts +28 -12
  56. package/src/avm/opcodes/memory.ts +61 -67
  57. package/src/avm/serialization/bytecode_serialization.ts +96 -73
  58. package/src/avm/serialization/instruction_serialization.ts +64 -24
  59. package/src/public/hints_builder.ts +0 -11
  60. package/src/public/tail_phase_manager.ts +0 -7
@@ -1,39 +1,57 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
- import { Field, TaggedMemory, TypeTag } from '../avm_memory_types.js';
3
- import { InstructionExecutionError } from '../errors.js';
4
- import { BufferCursor } from '../serialization/buffer_cursor.js';
5
- import { Opcode, OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
2
+ import { Field, TaggedMemory } from '../avm_memory_types.js';
3
+ import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
4
  import { Addressing } from './addressing_mode.js';
7
5
  import { Instruction } from './instruction.js';
8
6
  import { TwoOperandInstruction } from './instruction_impl.js';
9
7
 
10
- const TAG_TO_OPERAND_TYPE = new Map<TypeTag, OperandType>([
11
- [TypeTag.UINT8, OperandType.UINT8],
12
- [TypeTag.UINT16, OperandType.UINT16],
13
- [TypeTag.UINT32, OperandType.UINT32],
14
- [TypeTag.UINT64, OperandType.UINT64],
15
- [TypeTag.UINT128, OperandType.UINT128],
16
- ]);
17
-
18
- function getOperandTypeFromInTag(inTag: number | bigint): OperandType {
19
- inTag = inTag as number;
20
- const tagOperandType = TAG_TO_OPERAND_TYPE.get(inTag);
21
- if (tagOperandType === undefined) {
22
- throw new Error(`Invalid tag ${inTag} for SET.`);
23
- }
24
- return tagOperandType;
25
- }
26
-
27
8
  export class Set extends Instruction {
28
9
  static readonly type: string = 'SET';
29
- static readonly opcode: Opcode = Opcode.SET;
30
-
31
- private static readonly wireFormatBeforeConst: OperandType[] = [
32
- OperandType.UINT8,
33
- OperandType.UINT8,
34
- OperandType.UINT8,
10
+ // Required for gas.
11
+ static readonly opcode: Opcode = Opcode.SET_8;
12
+
13
+ public static readonly wireFormat8: OperandType[] = [
14
+ OperandType.UINT8, // opcode
15
+ OperandType.UINT8, // indirect
16
+ OperandType.UINT8, // tag
17
+ OperandType.UINT8, // const (value)
18
+ OperandType.UINT8, // dstOffset
19
+ ];
20
+ public static readonly wireFormat16: OperandType[] = [
21
+ OperandType.UINT8, // opcode
22
+ OperandType.UINT8, // indirect
23
+ OperandType.UINT8, // tag
24
+ OperandType.UINT16, // const (value)
25
+ OperandType.UINT16, // dstOffset
26
+ ];
27
+ public static readonly wireFormat32: OperandType[] = [
28
+ OperandType.UINT8, // opcode
29
+ OperandType.UINT8, // indirect
30
+ OperandType.UINT8, // tag
31
+ OperandType.UINT32, // const (value)
32
+ OperandType.UINT16, // dstOffset
33
+ ];
34
+ public static readonly wireFormat64: OperandType[] = [
35
+ OperandType.UINT8, // opcode
36
+ OperandType.UINT8, // indirect
37
+ OperandType.UINT8, // tag
38
+ OperandType.UINT64, // const (value)
39
+ OperandType.UINT16, // dstOffset
40
+ ];
41
+ public static readonly wireFormat128: OperandType[] = [
42
+ OperandType.UINT8, // opcode
43
+ OperandType.UINT8, // indirect
44
+ OperandType.UINT8, // tag
45
+ OperandType.UINT128, // const (value)
46
+ OperandType.UINT16, // dstOffset
47
+ ];
48
+ public static readonly wireFormatFF: OperandType[] = [
49
+ OperandType.UINT8, // opcode
50
+ OperandType.UINT8, // indirect
51
+ OperandType.UINT8, // tag
52
+ OperandType.FF, // const (value)
53
+ OperandType.UINT16, // dstOffset
35
54
  ];
36
- private static readonly wireFormatAfterConst: OperandType[] = [OperandType.UINT32];
37
55
 
38
56
  constructor(
39
57
  private indirect: number,
@@ -44,42 +62,13 @@ export class Set extends Instruction {
44
62
  super();
45
63
  }
46
64
 
47
- /** We need to use a custom serialize function because of the variable length of the value. */
48
- public override serialize(): Buffer {
49
- const format: OperandType[] = [
50
- ...Set.wireFormatBeforeConst,
51
- getOperandTypeFromInTag(this.inTag),
52
- ...Set.wireFormatAfterConst,
53
- ];
54
- return serialize(format, this);
55
- }
56
-
57
- /** We need to use a custom deserialize function because of the variable length of the value. */
58
- public static override deserialize(this: typeof Set, buf: BufferCursor | Buffer): Set {
59
- if (buf instanceof Buffer) {
60
- buf = new BufferCursor(buf);
61
- }
62
- const beforeConst = deserialize(buf, Set.wireFormatBeforeConst);
63
- const tag = beforeConst[beforeConst.length - 1];
64
- const val = deserialize(buf, [getOperandTypeFromInTag(tag)]);
65
- const afterConst = deserialize(buf, Set.wireFormatAfterConst);
66
- const res = [...beforeConst, ...val, ...afterConst];
67
- const args = res.slice(1) as ConstructorParameters<typeof Set>; // Remove opcode.
68
- return new this(...args);
69
- }
70
-
71
65
  public async execute(context: AvmContext): Promise<void> {
72
66
  const memoryOperations = { writes: 1, indirect: this.indirect };
73
67
  const memory = context.machineState.memory.track(this.type);
74
68
  context.machineState.consumeGas(this.gasCost(memoryOperations));
75
69
 
76
- // Per the YP, the tag cannot be a field.
77
- if ([TypeTag.FIELD, TypeTag.UNINITIALIZED, TypeTag.INVALID].includes(this.inTag)) {
78
- throw new InstructionExecutionError(`Invalid tag ${TypeTag[this.inTag]} for SET.`);
79
- }
80
70
  const [dstOffset] = Addressing.fromWire(this.indirect).resolve([this.dstOffset], memory);
81
-
82
- const res = TaggedMemory.integralFromTag(this.value, this.inTag);
71
+ const res = TaggedMemory.buildFromTagTruncating(this.value, this.inTag);
83
72
  memory.set(dstOffset, res);
84
73
 
85
74
  memory.assert(memoryOperations);
@@ -134,7 +123,7 @@ export class CMov extends Instruction {
134
123
 
135
124
  export class Cast extends TwoOperandInstruction {
136
125
  static readonly type: string = 'CAST';
137
- static readonly opcode = Opcode.CAST;
126
+ static readonly opcode = Opcode.CAST_8;
138
127
 
139
128
  constructor(indirect: number, dstTag: number, srcOffset: number, dstOffset: number) {
140
129
  super(indirect, dstTag, srcOffset, dstOffset);
@@ -148,9 +137,7 @@ export class Cast extends TwoOperandInstruction {
148
137
  const [srcOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.aOffset, this.dstOffset], memory);
149
138
 
150
139
  const a = memory.get(srcOffset);
151
-
152
- const casted =
153
- this.inTag == TypeTag.FIELD ? new Field(a.toBigInt()) : TaggedMemory.integralFromTag(a.toBigInt(), this.inTag);
140
+ const casted = TaggedMemory.buildFromTagTruncating(a.toBigInt(), this.inTag);
154
141
 
155
142
  memory.set(dstOffset, casted);
156
143
 
@@ -161,13 +148,20 @@ export class Cast extends TwoOperandInstruction {
161
148
 
162
149
  export class Mov extends Instruction {
163
150
  static readonly type: string = 'MOV';
164
- static readonly opcode: Opcode = Opcode.MOV;
165
- // Informs (de)serialization. See Instruction.deserialize.
166
- static readonly wireFormat: OperandType[] = [
151
+ // FIXME: This is needed for gas.
152
+ static readonly opcode: Opcode = Opcode.MOV_8;
153
+
154
+ static readonly wireFormat8: OperandType[] = [
167
155
  OperandType.UINT8,
168
156
  OperandType.UINT8,
169
- OperandType.UINT32,
170
- OperandType.UINT32,
157
+ OperandType.UINT8,
158
+ OperandType.UINT8,
159
+ ];
160
+ static readonly wireFormat16: OperandType[] = [
161
+ OperandType.UINT8,
162
+ OperandType.UINT8,
163
+ OperandType.UINT16,
164
+ OperandType.UINT16,
171
165
  ];
172
166
 
173
167
  constructor(private indirect: number, private srcOffset: number, private dstOffset: number) {
@@ -2,7 +2,6 @@ import { PedersenCommitment } from '../opcodes/commitment.js';
2
2
  import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js';
3
3
  import { EcAdd } from '../opcodes/ec_add.js';
4
4
  import { Keccak, KeccakF1600, Pedersen, Poseidon2, Sha256 } from '../opcodes/hashing.js';
5
- import type { Instruction } from '../opcodes/index.js';
6
5
  import {
7
6
  Add,
8
7
  Address,
@@ -24,6 +23,7 @@ import {
24
23
  FieldDiv,
25
24
  FunctionSelector,
26
25
  GetContractInstance,
26
+ Instruction,
27
27
  InternalCall,
28
28
  InternalReturn,
29
29
  Jump,
@@ -59,102 +59,125 @@ import { MultiScalarMul } from '../opcodes/multi_scalar_mul.js';
59
59
  import { BufferCursor } from './buffer_cursor.js';
60
60
  import { Opcode } from './instruction_serialization.js';
61
61
 
62
- interface DeserializableInstruction {
63
- deserialize(buf: BufferCursor | Buffer): Instruction;
64
- opcode: Opcode;
62
+ export type InstructionDeserializer = (buf: BufferCursor | Buffer) => Instruction;
63
+
64
+ export interface Serializable {
65
+ serialize(): Buffer;
66
+ }
67
+
68
+ export interface Deserializable {
69
+ deserialize: InstructionDeserializer;
65
70
  }
66
71
 
67
- export type InstructionSet = Map<Opcode, DeserializableInstruction>;
72
+ export type InstructionSet = Map<Opcode, InstructionDeserializer>;
68
73
  // TODO(4359): This is a function so that Call and StaticCall can be lazily resolved.
69
74
  // This is a temporary solution until we solve the dependency cycle.
70
75
  const INSTRUCTION_SET = () =>
71
- new Map<Opcode, DeserializableInstruction>([
72
- [Add.opcode, Add],
73
- [Sub.opcode, Sub],
74
- [Mul.opcode, Mul],
75
- [Div.opcode, Div],
76
- [FieldDiv.opcode, FieldDiv],
77
- [Eq.opcode, Eq],
78
- [Lt.opcode, Lt],
79
- [Lte.opcode, Lte],
80
- [And.opcode, And],
81
- [Or.opcode, Or],
82
- [Xor.opcode, Xor],
83
- [Not.opcode, Not],
84
- [Shl.opcode, Shl],
85
- [Shr.opcode, Shr],
86
- [Cast.opcode, Cast],
87
- [Address.opcode, Address],
88
- [StorageAddress.opcode, StorageAddress],
89
- [Sender.opcode, Sender],
90
- [FunctionSelector.opcode, FunctionSelector],
91
- [TransactionFee.opcode, TransactionFee],
76
+ new Map<Opcode, InstructionDeserializer>([
77
+ [Opcode.ADD_8, Add.as(Add.wireFormat8).deserialize],
78
+ [Opcode.ADD_16, Add.as(Add.wireFormat16).deserialize],
79
+ [Opcode.SUB_8, Sub.as(Sub.wireFormat8).deserialize],
80
+ [Opcode.SUB_16, Sub.as(Sub.wireFormat16).deserialize],
81
+ [Opcode.MUL_8, Mul.as(Mul.wireFormat8).deserialize],
82
+ [Opcode.MUL_16, Mul.as(Mul.wireFormat16).deserialize],
83
+ [Opcode.DIV_8, Div.as(Div.wireFormat8).deserialize],
84
+ [Opcode.DIV_16, Div.as(Div.wireFormat16).deserialize],
85
+ [Opcode.FDIV_8, FieldDiv.as(FieldDiv.wireFormat8).deserialize],
86
+ [Opcode.FDIV_16, FieldDiv.as(FieldDiv.wireFormat16).deserialize],
87
+ [Opcode.EQ_8, Eq.as(Eq.wireFormat8).deserialize],
88
+ [Opcode.EQ_16, Eq.as(Eq.wireFormat16).deserialize],
89
+ [Opcode.LT_8, Lt.as(Lt.wireFormat8).deserialize],
90
+ [Opcode.LT_16, Lt.as(Lt.wireFormat16).deserialize],
91
+ [Opcode.LTE_8, Lte.as(Lte.wireFormat8).deserialize],
92
+ [Opcode.LTE_16, Lte.as(Lte.wireFormat16).deserialize],
93
+ [Opcode.AND_8, And.as(And.wireFormat8).deserialize],
94
+ [Opcode.AND_16, And.as(And.wireFormat16).deserialize],
95
+ [Opcode.OR_8, Or.as(Or.wireFormat8).deserialize],
96
+ [Opcode.OR_16, Or.as(Or.wireFormat16).deserialize],
97
+ [Opcode.XOR_8, Xor.as(Xor.wireFormat8).deserialize],
98
+ [Opcode.XOR_16, Xor.as(Xor.wireFormat16).deserialize],
99
+ [Opcode.NOT_8, Not.as(Not.wireFormat8).deserialize],
100
+ [Opcode.NOT_16, Not.as(Not.wireFormat16).deserialize],
101
+ [Opcode.SHL_8, Shl.as(Shl.wireFormat8).deserialize],
102
+ [Opcode.SHL_16, Shl.as(Shl.wireFormat16).deserialize],
103
+ [Opcode.SHR_8, Shr.as(Shr.wireFormat8).deserialize],
104
+ [Opcode.SHR_16, Shr.as(Shr.wireFormat16).deserialize],
105
+ [Opcode.CAST_8, Cast.as(Cast.wireFormat8).deserialize],
106
+ [Opcode.CAST_16, Cast.as(Cast.wireFormat16).deserialize],
107
+ [Address.opcode, Instruction.deserialize.bind(Address)],
108
+ [StorageAddress.opcode, Instruction.deserialize.bind(StorageAddress)],
109
+ [Sender.opcode, Instruction.deserialize.bind(Sender)],
110
+ [FunctionSelector.opcode, Instruction.deserialize.bind(FunctionSelector)],
111
+ [TransactionFee.opcode, Instruction.deserialize.bind(TransactionFee)],
92
112
  // Execution Environment - Globals
93
- [ChainId.opcode, ChainId],
94
- [Version.opcode, Version],
95
- [BlockNumber.opcode, BlockNumber],
96
- [Timestamp.opcode, Timestamp],
97
- [FeePerL2Gas.opcode, FeePerL2Gas],
98
- [FeePerDAGas.opcode, FeePerDAGas],
113
+ [ChainId.opcode, Instruction.deserialize.bind(ChainId)],
114
+ [Version.opcode, Instruction.deserialize.bind(Version)],
115
+ [BlockNumber.opcode, Instruction.deserialize.bind(BlockNumber)],
116
+ [Timestamp.opcode, Instruction.deserialize.bind(Timestamp)],
117
+ [FeePerL2Gas.opcode, Instruction.deserialize.bind(FeePerL2Gas)],
118
+ [FeePerDAGas.opcode, Instruction.deserialize.bind(FeePerDAGas)],
99
119
  // Execution Environment - Calldata
100
- [CalldataCopy.opcode, CalldataCopy],
120
+ [CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)],
101
121
 
102
122
  // Machine State
103
123
  // Machine State - Gas
104
- [L2GasLeft.opcode, L2GasLeft],
105
- [DAGasLeft.opcode, DAGasLeft],
124
+ [L2GasLeft.opcode, Instruction.deserialize.bind(L2GasLeft)],
125
+ [DAGasLeft.opcode, Instruction.deserialize.bind(DAGasLeft)],
106
126
  // Machine State - Internal Control Flow
107
- [Jump.opcode, Jump],
108
- [JumpI.opcode, JumpI],
109
- [InternalCall.opcode, InternalCall],
110
- [InternalReturn.opcode, InternalReturn],
111
- [Set.opcode, Set],
112
- [Mov.opcode, Mov],
113
- [CMov.opcode, CMov],
127
+ [Jump.opcode, Instruction.deserialize.bind(Jump)],
128
+ [JumpI.opcode, Instruction.deserialize.bind(JumpI)],
129
+ [InternalCall.opcode, Instruction.deserialize.bind(InternalCall)],
130
+ [InternalReturn.opcode, Instruction.deserialize.bind(InternalReturn)],
131
+ [Opcode.SET_8, Set.as(Set.wireFormat8).deserialize],
132
+ [Opcode.SET_16, Set.as(Set.wireFormat16).deserialize],
133
+ [Opcode.SET_32, Set.as(Set.wireFormat32).deserialize],
134
+ [Opcode.SET_64, Set.as(Set.wireFormat64).deserialize],
135
+ [Opcode.SET_128, Set.as(Set.wireFormat128).deserialize],
136
+ [Opcode.SET_FF, Set.as(Set.wireFormatFF).deserialize],
137
+ [Opcode.MOV_8, Mov.as(Mov.wireFormat8).deserialize],
138
+ [Opcode.MOV_16, Mov.as(Mov.wireFormat16).deserialize],
139
+ [CMov.opcode, Instruction.deserialize.bind(CMov)],
114
140
 
115
141
  // World State
116
- [SLoad.opcode, SLoad], // Public Storage
117
- [SStore.opcode, SStore], // Public Storage
118
- [NoteHashExists.opcode, NoteHashExists], // Notes & Nullifiers
119
- [EmitNoteHash.opcode, EmitNoteHash], // Notes & Nullifiers
120
- [NullifierExists.opcode, NullifierExists], // Notes & Nullifiers
121
- [EmitNullifier.opcode, EmitNullifier], // Notes & Nullifiers
122
- [L1ToL2MessageExists.opcode, L1ToL2MessageExists], // Messages
142
+ [SLoad.opcode, Instruction.deserialize.bind(SLoad)], // Public Storage
143
+ [SStore.opcode, Instruction.deserialize.bind(SStore)], // Public Storage
144
+ [NoteHashExists.opcode, Instruction.deserialize.bind(NoteHashExists)], // Notes & Nullifiers
145
+ [EmitNoteHash.opcode, Instruction.deserialize.bind(EmitNoteHash)], // Notes & Nullifiers
146
+ [NullifierExists.opcode, Instruction.deserialize.bind(NullifierExists)], // Notes & Nullifiers
147
+ [EmitNullifier.opcode, Instruction.deserialize.bind(EmitNullifier)], // Notes & Nullifiers
148
+ [L1ToL2MessageExists.opcode, Instruction.deserialize.bind(L1ToL2MessageExists)], // Messages
123
149
 
124
150
  // Accrued Substate
125
- [EmitUnencryptedLog.opcode, EmitUnencryptedLog],
126
- [SendL2ToL1Message.opcode, SendL2ToL1Message],
127
- [GetContractInstance.opcode, GetContractInstance],
151
+ [EmitUnencryptedLog.opcode, Instruction.deserialize.bind(EmitUnencryptedLog)],
152
+ [SendL2ToL1Message.opcode, Instruction.deserialize.bind(SendL2ToL1Message)],
153
+ [GetContractInstance.opcode, Instruction.deserialize.bind(GetContractInstance)],
128
154
 
129
155
  // Control Flow - Contract Calls
130
- [Call.opcode, Call],
131
- [StaticCall.opcode, StaticCall],
132
- //[DelegateCall.opcode, DelegateCall],
133
- [Return.opcode, Return],
134
- [Revert.opcode, Revert],
156
+ [Call.opcode, Instruction.deserialize.bind(Call)],
157
+ [StaticCall.opcode, Instruction.deserialize.bind(StaticCall)],
158
+ //[DelegateCall.opcode, Instruction.deserialize.bind(DelegateCall)],
159
+ [Return.opcode, Instruction.deserialize.bind(Return)],
160
+ [Opcode.REVERT_8, Revert.as(Revert.wireFormat8).deserialize],
161
+ [Opcode.REVERT_16, Revert.as(Revert.wireFormat16).deserialize],
135
162
 
136
163
  // Misc
137
- [DebugLog.opcode, DebugLog],
164
+ [DebugLog.opcode, Instruction.deserialize.bind(DebugLog)],
138
165
 
139
166
  // Gadgets
140
- [EcAdd.opcode, EcAdd],
141
- [Keccak.opcode, Keccak],
142
- [Poseidon2.opcode, Poseidon2],
143
- [Sha256.opcode, Sha256],
144
- [Pedersen.opcode, Pedersen],
145
- [MultiScalarMul.opcode, MultiScalarMul],
146
- [PedersenCommitment.opcode, PedersenCommitment],
167
+ [EcAdd.opcode, Instruction.deserialize.bind(EcAdd)],
168
+ [Keccak.opcode, Instruction.deserialize.bind(Keccak)],
169
+ [Poseidon2.opcode, Instruction.deserialize.bind(Poseidon2)],
170
+ [Sha256.opcode, Instruction.deserialize.bind(Sha256)],
171
+ [Pedersen.opcode, Instruction.deserialize.bind(Pedersen)],
172
+ [MultiScalarMul.opcode, Instruction.deserialize.bind(MultiScalarMul)],
173
+ [PedersenCommitment.opcode, Instruction.deserialize.bind(PedersenCommitment)],
147
174
  // Conversions
148
- [ToRadixLE.opcode, ToRadixLE],
175
+ [ToRadixLE.opcode, Instruction.deserialize.bind(ToRadixLE)],
149
176
  // Future Gadgets -- pending changes in noir
150
177
  // SHA256COMPRESSION,
151
- [KeccakF1600.opcode, KeccakF1600],
178
+ [KeccakF1600.opcode, Instruction.deserialize.bind(KeccakF1600)],
152
179
  ]);
153
180
 
154
- interface Serializable {
155
- serialize(): Buffer;
156
- }
157
-
158
181
  /**
159
182
  * Serializes an array of instructions to bytecode.
160
183
  */
@@ -182,8 +205,8 @@ export function decodeFromBytecode(
182
205
  throw new Error(`Opcode ${Opcode[opcode]} (0x${opcode.toString(16)}) not implemented`);
183
206
  }
184
207
 
185
- const instructionDeserializer: DeserializableInstruction = instructionDeserializerOrUndef;
186
- const i: Instruction = instructionDeserializer.deserialize(cursor);
208
+ const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
209
+ const i: Instruction = instructionDeserializer(cursor);
187
210
  instructions.push(i);
188
211
  }
189
212
 
@@ -8,21 +8,36 @@ import { BufferCursor } from './buffer_cursor.js';
8
8
  */
9
9
  export enum Opcode {
10
10
  // Compute
11
- ADD,
12
- SUB,
13
- MUL,
14
- DIV,
15
- FDIV,
16
- EQ,
17
- LT,
18
- LTE,
19
- AND,
20
- OR,
21
- XOR,
22
- NOT,
23
- SHL,
24
- SHR,
25
- CAST,
11
+ ADD_8,
12
+ ADD_16,
13
+ SUB_8,
14
+ SUB_16,
15
+ MUL_8,
16
+ MUL_16,
17
+ DIV_8,
18
+ DIV_16,
19
+ FDIV_8,
20
+ FDIV_16,
21
+ EQ_8,
22
+ EQ_16,
23
+ LT_8,
24
+ LT_16,
25
+ LTE_8,
26
+ LTE_16,
27
+ AND_8,
28
+ AND_16,
29
+ OR_8,
30
+ OR_16,
31
+ XOR_8,
32
+ XOR_16,
33
+ NOT_8,
34
+ NOT_16,
35
+ SHL_8,
36
+ SHL_16,
37
+ SHR_8,
38
+ SHR_16,
39
+ CAST_8,
40
+ CAST_16,
26
41
  // Execution environment
27
42
  ADDRESS,
28
43
  STORAGEADDRESS,
@@ -40,13 +55,19 @@ export enum Opcode {
40
55
  L2GASLEFT,
41
56
  DAGASLEFT,
42
57
  // Control flow
43
- JUMP,
44
- JUMPI,
58
+ JUMP_16,
59
+ JUMPI_16,
45
60
  INTERNALCALL,
46
61
  INTERNALRETURN,
47
62
  // Memory
48
- SET,
49
- MOV,
63
+ SET_8,
64
+ SET_16,
65
+ SET_32,
66
+ SET_64,
67
+ SET_128,
68
+ SET_FF,
69
+ MOV_8,
70
+ MOV_16,
50
71
  CMOV,
51
72
  // World state
52
73
  SLOAD,
@@ -64,7 +85,8 @@ export enum Opcode {
64
85
  STATICCALL,
65
86
  DELEGATECALL,
66
87
  RETURN,
67
- REVERT,
88
+ REVERT_8,
89
+ REVERT_16,
68
90
  // Misc
69
91
  DEBUGLOG,
70
92
  // Gadgets
@@ -92,6 +114,7 @@ export enum OperandType {
92
114
  UINT32,
93
115
  UINT64,
94
116
  UINT128,
117
+ FF,
95
118
  }
96
119
 
97
120
  type OperandNativeType = number | bigint;
@@ -104,8 +127,27 @@ const OPERAND_SPEC = new Map<OperandType, [number, () => OperandNativeType, Oper
104
127
  [OperandType.UINT32, [4, Buffer.prototype.readUint32BE, Buffer.prototype.writeUint32BE]],
105
128
  [OperandType.UINT64, [8, Buffer.prototype.readBigInt64BE, Buffer.prototype.writeBigInt64BE]],
106
129
  [OperandType.UINT128, [16, readBigInt128BE, writeBigInt128BE]],
130
+ [OperandType.FF, [32, readBigInt254BE, writeBigInt254BE]],
107
131
  ]);
108
132
 
133
+ function readBigInt254BE(this: Buffer): bigint {
134
+ const totalBytes = 32;
135
+ let ret: bigint = 0n;
136
+ for (let i = 0; i < totalBytes; ++i) {
137
+ ret <<= 8n;
138
+ ret |= BigInt(this.readUint8(i));
139
+ }
140
+ return ret;
141
+ }
142
+
143
+ function writeBigInt254BE(this: Buffer, value: bigint): void {
144
+ const totalBytes = 32;
145
+ for (let offset = totalBytes - 1; offset >= 0; --offset) {
146
+ this.writeUint8(Number(value & 0xffn), offset);
147
+ value >>= 8n;
148
+ }
149
+ }
150
+
109
151
  function readBigInt128BE(this: Buffer): bigint {
110
152
  const totalBytes = 16;
111
153
  let ret: bigint = 0n;
@@ -156,12 +198,10 @@ export function deserialize(cursor: BufferCursor | Buffer, operands: OperandType
156
198
  * @param cls The class to be serialized.
157
199
  * @returns
158
200
  */
159
- export function serialize(operands: OperandType[], cls: any): Buffer {
201
+ export function serializeAs(operands: OperandType[], opcode: Opcode, cls: any): Buffer {
160
202
  const chunks: Buffer[] = [];
161
203
 
162
- // TODO: infer opcode not in this loop
163
- assert(cls.constructor.opcode !== undefined && cls.constructor.opcode !== null);
164
- const rawClassValues: any[] = [cls.constructor.opcode, ...Object.values(cls)];
204
+ const rawClassValues: any[] = [opcode, ...Object.values(cls)];
165
205
  assert(
166
206
  rawClassValues.length === operands.length,
167
207
  `Got ${rawClassValues.length} values but only ${operands.length} serialization operands are specified!`,
@@ -7,7 +7,6 @@ import {
7
7
  type MAX_NULLIFIERS_PER_TX,
8
8
  type MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
9
9
  MAX_NULLIFIER_READ_REQUESTS_PER_TX,
10
- type MAX_PUBLIC_DATA_HINTS,
11
10
  type MAX_PUBLIC_DATA_READS_PER_TX,
12
11
  type MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
13
12
  MembershipWitness,
@@ -15,7 +14,6 @@ import {
15
14
  NULLIFIER_TREE_HEIGHT,
16
15
  type Nullifier,
17
16
  PUBLIC_DATA_TREE_HEIGHT,
18
- type PublicDataHint,
19
17
  type PublicDataRead,
20
18
  type PublicDataTreeLeafPreimage,
21
19
  type PublicDataUpdateRequest,
@@ -25,7 +23,6 @@ import {
25
23
  buildNullifierNonExistentReadRequestHints,
26
24
  buildPublicDataHint,
27
25
  buildPublicDataHints,
28
- buildPublicDataReadRequestHints,
29
26
  buildSiloedNullifierReadRequestHints,
30
27
  } from '@aztec/circuits.js';
31
28
  import { makeTuple } from '@aztec/foundation/array';
@@ -91,14 +88,6 @@ export class HintsBuilder {
91
88
  return buildPublicDataHint(this, slot);
92
89
  }
93
90
 
94
- getPublicDataReadRequestHints(
95
- publicDataReads: Tuple<PublicDataRead, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
96
- publicDataUpdateRequests: Tuple<PublicDataUpdateRequest, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
97
- publicDataHints: Tuple<PublicDataHint, typeof MAX_PUBLIC_DATA_HINTS>,
98
- ) {
99
- return buildPublicDataReadRequestHints(publicDataReads, publicDataUpdateRequests, publicDataHints);
100
- }
101
-
102
91
  async getNullifierMembershipWitness(nullifier: Fr) {
103
92
  const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
104
93
  if (index === undefined) {
@@ -112,12 +112,6 @@ export class TailPhaseManager extends AbstractPhaseManager {
112
112
  pendingPublicDataWrites,
113
113
  );
114
114
 
115
- const publicDataReadRequestHints = this.hintsBuilder.getPublicDataReadRequestHints(
116
- validationRequests.publicDataReads,
117
- pendingPublicDataWrites,
118
- publicDataHints,
119
- );
120
-
121
115
  const currentState = await this.db.getStateReference();
122
116
 
123
117
  return new PublicKernelTailCircuitPrivateInputs(
@@ -127,7 +121,6 @@ export class TailPhaseManager extends AbstractPhaseManager {
127
121
  nullifierNonExistentReadRequestHints,
128
122
  l1ToL2MsgReadRequestHints,
129
123
  publicDataHints,
130
- publicDataReadRequestHints,
131
124
  currentState.partial,
132
125
  );
133
126
  }