@aztec/simulator 1.1.2 → 1.2.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.
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +1 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +4 -0
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +35 -28
- package/dest/public/public_processor/public_processor.d.ts +1 -0
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +19 -0
- package/package.json +17 -16
- package/src/public/avm/avm_memory_types.ts +1 -0
- package/src/public/avm/opcodes/memory.ts +6 -0
- package/src/public/avm/serialization/instruction_serialization.ts +39 -25
- package/src/public/public_processor/public_processor.ts +25 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avm_memory_types.d.ts","sourceRoot":"","sources":["../../../src/public/avm/avm_memory_types.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAM3D,sEAAsE;AACtE,8BAAsB,WAAW;aACf,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;aAClC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;aAClC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;aAClC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW;aAElC,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO;aACjC,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO;aAG7B,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,KAAK,EAAE,WAAW,EAAE;IAa7C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAKtC;;OAEG;IACI,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;WAO9B,uBAAuB,CAAC,GAAG,EAAE,OAAO;WAIpC,kBAAkB,CAAC,GAAG,EAAE,OAAO;WAM/B,eAAe,CAAC,SAAS,EAAE,MAAM;IAM/C;;OAEG;IACI,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE;IAMnD;;OAEG;IACI,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKxD;;OAEG;IACI,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;WAMvD,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO;WAS3C,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,WAAW;CAqBpF"}
|
|
@@ -37,6 +37,7 @@ import { InvalidTagValueError, MemorySliceOutOfRangeError, TagCheckError } from
|
|
|
37
37
|
constructor(n){
|
|
38
38
|
super();
|
|
39
39
|
this.n = BigInt(n);
|
|
40
|
+
assert(n >= 0n, `${this.constructor.name} cannot handle negative values: ${n}.`);
|
|
40
41
|
assert(n < NewUintClass.mod, `Value ${n} is too large for ${this.constructor.name}.`);
|
|
41
42
|
}
|
|
42
43
|
build(n) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/memory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEp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AE,MAAM,CAAyB;IAEvD,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAA8D;gBAG7F,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IAKd,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAazD;AAED,qBAAa,cAAe,SAAQ,WAAW;IAa3C,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;IAfnB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAoB;IAChD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAyB;IAEvD,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAMvC;gBAGQ,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM;IAKd,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBzD"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { strict as assert } from 'assert';
|
|
1
3
|
import { Field, TaggedMemory, TypeTag, Uint32 } from '../avm_memory_types.js';
|
|
2
4
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
3
5
|
import { Addressing } from './addressing_mode.js';
|
|
@@ -54,6 +56,8 @@ export class Set extends Instruction {
|
|
|
54
56
|
];
|
|
55
57
|
constructor(indirect, dstOffset, inTag, value){
|
|
56
58
|
super(), this.indirect = indirect, this.dstOffset = dstOffset, this.inTag = inTag, this.value = value;
|
|
59
|
+
assert(this.value >= 0, `Value ${this.value} is negative`);
|
|
60
|
+
assert(this.value < Fr.MODULUS, `Value ${this.value} is larger than Fr.MODULUS`);
|
|
57
61
|
}
|
|
58
62
|
async execute(context) {
|
|
59
63
|
// Constructor ensured that this.inTag is a valid tag
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruction_serialization.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/serialization/instruction_serialization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instruction_serialization.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/serialization/instruction_serialization.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,oBAAY,MAAM;IAEhB,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;IACN,OAAO,IAAA;IACP,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,MAAM,KAAA;IACN,OAAO,KAAA;IAEP,YAAY,KAAA;IACZ,YAAY,KAAA;IACZ,WAAW,KAAA;IACX,cAAc,KAAA;IACd,cAAc,KAAA;IAEd,OAAO,KAAA;IACP,QAAQ,KAAA;IACR,YAAY,KAAA;IACZ,cAAc,KAAA;IAEd,KAAK,KAAA;IACL,MAAM,KAAA;IACN,MAAM,KAAA;IACN,MAAM,KAAA;IACN,OAAO,KAAA;IACP,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IAEN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,cAAc,KAAA;IACd,YAAY,KAAA;IACZ,eAAe,KAAA;IACf,aAAa,KAAA;IACb,eAAe,KAAA;IACf,mBAAmB,KAAA;IACnB,kBAAkB,KAAA;IAClB,aAAa,KAAA;IAEb,IAAI,KAAA;IACJ,UAAU,KAAA;IACV,MAAM,KAAA;IACN,QAAQ,KAAA;IACR,SAAS,KAAA;IAET,QAAQ,KAAA;IAER,SAAS,KAAA;IACT,iBAAiB,KAAA;IACjB,WAAW,KAAA;IACX,KAAK,KAAA;IAEL,SAAS,KAAA;CACV;AAED,eAAO,MAAM,gBAAgB,QAI5B,CAAC;AAIF,oBAAY,WAAW;IACrB,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;IACN,MAAM,IAAA;IACN,OAAO,IAAA;IACP,EAAE,IAAA;IACF,GAAG,IAAA;CACJ;AAGD,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAgEzC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,iBAAiB,EAAE,CAyBvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CAmBrF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
1
2
|
import { strict as assert } from 'assert';
|
|
2
3
|
import { TaggedMemory } from '../avm_memory_types.js';
|
|
3
4
|
import { BufferCursor } from './buffer_cursor.js';
|
|
@@ -127,24 +128,24 @@ const OPERAND_SPEC = new Map([
|
|
|
127
128
|
3,
|
|
128
129
|
[
|
|
129
130
|
8,
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
readUint64BE,
|
|
132
|
+
writeUint64BE
|
|
132
133
|
]
|
|
133
134
|
],
|
|
134
135
|
[
|
|
135
136
|
4,
|
|
136
137
|
[
|
|
137
138
|
16,
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
readUint128BE,
|
|
140
|
+
writeUint128BE
|
|
140
141
|
]
|
|
141
142
|
],
|
|
142
143
|
[
|
|
143
144
|
5,
|
|
144
145
|
[
|
|
145
146
|
32,
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
readUint254BE,
|
|
148
|
+
writeUint254BE
|
|
148
149
|
]
|
|
149
150
|
],
|
|
150
151
|
[
|
|
@@ -156,37 +157,43 @@ const OPERAND_SPEC = new Map([
|
|
|
156
157
|
]
|
|
157
158
|
]
|
|
158
159
|
]);
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
let ret = 0n;
|
|
160
|
+
function readUintBE(buf, offset, totalBytes) {
|
|
161
|
+
let value = 0n;
|
|
162
162
|
for(let i = 0; i < totalBytes; ++i){
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
value <<= 8n;
|
|
164
|
+
value |= BigInt(buf.readUint8(i + offset));
|
|
165
165
|
}
|
|
166
|
-
return
|
|
166
|
+
return value;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
const totalBytes = 32;
|
|
168
|
+
function writeUintBE(buf, value, totalBytes) {
|
|
170
169
|
for(let offset = totalBytes - 1; offset >= 0; --offset){
|
|
171
|
-
|
|
170
|
+
buf.writeUint8(Number(value & 0xffn), offset);
|
|
172
171
|
value >>= 8n;
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
let ret = 0n;
|
|
178
|
-
for(let i = 0; i < totalBytes; ++i){
|
|
179
|
-
ret <<= 8n;
|
|
180
|
-
ret |= BigInt(this.readUint8(i + offset));
|
|
181
|
-
}
|
|
182
|
-
return ret;
|
|
174
|
+
function readUint64BE(offset) {
|
|
175
|
+
return readUintBE(this, offset, 8);
|
|
183
176
|
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
177
|
+
function writeUint64BE(value) {
|
|
178
|
+
writeUintBE(this, value, 8);
|
|
179
|
+
}
|
|
180
|
+
function readUint254BE(offset) {
|
|
181
|
+
let value = readUintBE(this, offset, 32);
|
|
182
|
+
// In circuit, we only support values up to Fr.MODULUS and any deserialized value
|
|
183
|
+
// would naturally undergo a modulus reduction.
|
|
184
|
+
if (value >= Fr.MODULUS) {
|
|
185
|
+
value = value % Fr.MODULUS;
|
|
189
186
|
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
function writeUint254BE(value) {
|
|
190
|
+
writeUintBE(this, value, 32);
|
|
191
|
+
}
|
|
192
|
+
function readUint128BE(offset) {
|
|
193
|
+
return readUintBE(this, offset, 16);
|
|
194
|
+
}
|
|
195
|
+
function writeUint128BE(value) {
|
|
196
|
+
writeUintBE(this, value, 16);
|
|
190
197
|
}
|
|
191
198
|
/**
|
|
192
199
|
* Reads an array of operands from a buffer.
|
|
@@ -46,6 +46,7 @@ export declare class PublicProcessor implements Traceable {
|
|
|
46
46
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
47
47
|
*/
|
|
48
48
|
process(txs: Iterable<Tx> | AsyncIterable<Tx>, limits?: PublicProcessorLimits, validator?: PublicProcessorValidator): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]>;
|
|
49
|
+
private checkWorldStateUnchanged;
|
|
49
50
|
private processTx;
|
|
50
51
|
private doTreeInsertionsForPrivateOnlyTx;
|
|
51
52
|
/** Processes the given tx within deadline. Returns timeout if deadline is hit. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAMvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAMvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,KAAK,QAAQ,EACb,eAAe,EACf,yBAAyB,EACzB,KAAK,WAAW,EAEhB,EAAE,EAKH,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAiB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,KAAK,iBAAiB,EAA8B,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE;;GAEG;AACH,qBAAa,sBAAsB;IAE/B,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,SAAS,CAAC,eAAe,EAAE,eAAe;gBAFlC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,GAAE,YAAiC,EAC7C,eAAe,GAAE,eAAsC;IAGnE;;;;;;OAMG;IACI,MAAM,CACX,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,EAC3B,yBAAyB,GAAE,OAAe,GACzC,eAAe;IAuBlB,SAAS,CAAC,uBAAuB,CAC/B,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,EAC3B,kBAAkB,EAAE,OAAO,EAC3B,yBAAyB,EAAE,OAAO,GACjC,iBAAiB;CAWrB;AASD;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAI7C,SAAS,CAAC,eAAe,EAAE,eAAe;IAC1C,OAAO,CAAC,iBAAiB;IACzB,SAAS,CAAC,WAAW,EAAE,iBAAiB;IACxC,SAAS,CAAC,iBAAiB,EAAE,iBAAiB;IAC9C,OAAO,CAAC,YAAY;IAEpB,OAAO,CAAC,GAAG;IATb,OAAO,CAAC,OAAO,CAAyB;gBAG5B,eAAe,EAAE,eAAe,EAClC,iBAAiB,EAAE,2BAA2B,EAC5C,WAAW,EAAE,iBAAiB,EAC9B,iBAAiB,EAAE,iBAAiB,EACtC,YAAY,EAAE,YAAY,EAClC,eAAe,GAAE,eAAsC,EAC/C,GAAG,yCAA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;OAMG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE,qBAA0B,EAClC,SAAS,GAAE,wBAA6B,GACvC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YAyK5D,wBAAwB;YAiBxB,SAAS;YA2BT,gCAAgC;IAoC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,gCAAgC;YA0BhC,oBAAoB;YAkCpB,wBAAwB;CA4CvC"}
|
|
@@ -159,6 +159,7 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
159
159
|
// By doing this, every transaction starts on a fresh checkpoint and it's state updates only make it to the fork if this checkpoint is committed.
|
|
160
160
|
// Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
|
|
161
161
|
const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
|
|
162
|
+
const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
|
|
162
163
|
try {
|
|
163
164
|
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
164
165
|
// If the actual size of this tx would exceed block size, skip it
|
|
@@ -199,10 +200,13 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
199
200
|
// Now we want to revert any/all remaining checkpoints, destroying any outstanding state updates.
|
|
200
201
|
// This needs to be done directly on the underlying fork as the guarded fork has been stopped.
|
|
201
202
|
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
203
|
+
// Ensure we're at the same state as when we started processing this tx.
|
|
204
|
+
await this.checkWorldStateUnchanged(startStateReference, txHash, err);
|
|
202
205
|
break;
|
|
203
206
|
}
|
|
204
207
|
// Roll back state to start of TX before proceeding to next TX
|
|
205
208
|
await checkpoint.revert();
|
|
209
|
+
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
206
210
|
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
207
211
|
this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
|
|
208
212
|
failed.push({
|
|
@@ -210,6 +214,8 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
210
214
|
error: err instanceof Error ? err : new Error(errorMessage)
|
|
211
215
|
});
|
|
212
216
|
returns.push(new NestedProcessReturnValues([]));
|
|
217
|
+
// Ensure we're at the same state as when we started processing this tx.
|
|
218
|
+
await this.checkWorldStateUnchanged(startStateReference, txHash, err);
|
|
213
219
|
} finally{
|
|
214
220
|
// Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
|
|
215
221
|
await checkpoint.commit();
|
|
@@ -234,6 +240,19 @@ class PublicProcessorTimeoutError extends Error {
|
|
|
234
240
|
returns
|
|
235
241
|
];
|
|
236
242
|
}
|
|
243
|
+
async checkWorldStateUnchanged(startStateReference, txHash, cause) {
|
|
244
|
+
const endStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
|
|
245
|
+
if (!startStateReference.equals(endStateReference)) {
|
|
246
|
+
this.log.warn(`Fork state reference changed by tx ${txHash} after error in public processor`, {
|
|
247
|
+
expected: startStateReference.toInspect(),
|
|
248
|
+
actual: endStateReference.toInspect(),
|
|
249
|
+
cause
|
|
250
|
+
});
|
|
251
|
+
throw new Error(`Fork state reference changed by tx ${txHash} after error in public processor`, {
|
|
252
|
+
cause
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
237
256
|
async processTx(tx, deadline) {
|
|
238
257
|
const [time, [processedTx, returnValues]] = await elapsed(()=>this.processTxWithinDeadline(tx, deadline));
|
|
239
258
|
this.log.verbose(!tx.hasPublicCalls() ? `Processed tx ${processedTx.hash} with no public calls in ${time}ms` : `Processed tx ${processedTx.hash} with ${tx.numberOfPublicCalls()} public calls in ${time}ms`, {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/server.js",
|
|
7
7
|
"./client": "./dest/client.js",
|
|
8
8
|
"./testing": "./dest/testing.js",
|
|
9
|
-
"./public/fixtures": "./dest/public/fixtures/index.js"
|
|
9
|
+
"./public/fixtures": "./dest/public/fixtures/index.js",
|
|
10
|
+
"./public/avm/opcodes": "./dest/public/avm/opcodes/index.js"
|
|
10
11
|
},
|
|
11
12
|
"typedocOptions": {
|
|
12
13
|
"entryPoints": [
|
|
@@ -62,25 +63,25 @@
|
|
|
62
63
|
]
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@aztec/constants": "1.
|
|
66
|
-
"@aztec/foundation": "1.
|
|
67
|
-
"@aztec/noir-acvm_js": "1.
|
|
68
|
-
"@aztec/noir-noirc_abi": "1.
|
|
69
|
-
"@aztec/noir-protocol-circuits-types": "1.
|
|
70
|
-
"@aztec/noir-types": "1.
|
|
71
|
-
"@aztec/protocol-contracts": "1.
|
|
72
|
-
"@aztec/stdlib": "1.
|
|
73
|
-
"@aztec/telemetry-client": "1.
|
|
74
|
-
"@aztec/world-state": "1.
|
|
66
|
+
"@aztec/constants": "1.2.0",
|
|
67
|
+
"@aztec/foundation": "1.2.0",
|
|
68
|
+
"@aztec/noir-acvm_js": "1.2.0",
|
|
69
|
+
"@aztec/noir-noirc_abi": "1.2.0",
|
|
70
|
+
"@aztec/noir-protocol-circuits-types": "1.2.0",
|
|
71
|
+
"@aztec/noir-types": "1.2.0",
|
|
72
|
+
"@aztec/protocol-contracts": "1.2.0",
|
|
73
|
+
"@aztec/stdlib": "1.2.0",
|
|
74
|
+
"@aztec/telemetry-client": "1.2.0",
|
|
75
|
+
"@aztec/world-state": "1.2.0",
|
|
75
76
|
"lodash.clonedeep": "^4.5.0",
|
|
76
77
|
"lodash.merge": "^4.6.2",
|
|
77
78
|
"tslib": "^2.4.0"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
80
|
-
"@aztec/kv-store": "1.
|
|
81
|
-
"@aztec/merkle-tree": "1.
|
|
82
|
-
"@aztec/noir-contracts.js": "1.
|
|
83
|
-
"@aztec/noir-test-contracts.js": "1.
|
|
81
|
+
"@aztec/kv-store": "1.2.0",
|
|
82
|
+
"@aztec/merkle-tree": "1.2.0",
|
|
83
|
+
"@aztec/noir-contracts.js": "1.2.0",
|
|
84
|
+
"@aztec/noir-test-contracts.js": "1.2.0",
|
|
84
85
|
"@jest/globals": "^30.0.0",
|
|
85
86
|
"@types/jest": "^30.0.0",
|
|
86
87
|
"@types/lodash.clonedeep": "^4.5.7",
|
|
@@ -81,6 +81,7 @@ function UnsignedIntegerClassFactory(bits: number) {
|
|
|
81
81
|
public constructor(n: bigint | number) {
|
|
82
82
|
super();
|
|
83
83
|
this.n = BigInt(n);
|
|
84
|
+
assert(n >= 0n, `${this.constructor.name} cannot handle negative values: ${n}.`);
|
|
84
85
|
assert(n < NewUintClass.mod, `Value ${n} is too large for ${this.constructor.name}.`);
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
|
|
3
|
+
import { strict as assert } from 'assert';
|
|
4
|
+
|
|
1
5
|
import type { AvmContext } from '../avm_context.js';
|
|
2
6
|
import { Field, TaggedMemory, TypeTag, Uint32 } from '../avm_memory_types.js';
|
|
3
7
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
@@ -59,6 +63,8 @@ export class Set extends Instruction {
|
|
|
59
63
|
private value: bigint | number,
|
|
60
64
|
) {
|
|
61
65
|
super();
|
|
66
|
+
assert(this.value >= 0, `Value ${this.value} is negative`);
|
|
67
|
+
assert(this.value < Fr.MODULUS, `Value ${this.value} is larger than Fr.MODULUS`);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
public async execute(context: AvmContext): Promise<void> {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
|
|
1
3
|
import { strict as assert } from 'assert';
|
|
2
4
|
|
|
3
5
|
import { TaggedMemory } from '../avm_memory_types.js';
|
|
@@ -116,46 +118,58 @@ const OPERAND_SPEC = new Map<OperandType, [number, (offset: number) => OperandNa
|
|
|
116
118
|
[OperandType.UINT8, [1, Buffer.prototype.readUint8, Buffer.prototype.writeUint8]],
|
|
117
119
|
[OperandType.UINT16, [2, Buffer.prototype.readUint16BE, Buffer.prototype.writeUint16BE]],
|
|
118
120
|
[OperandType.UINT32, [4, Buffer.prototype.readUint32BE, Buffer.prototype.writeUint32BE]],
|
|
119
|
-
[OperandType.UINT64, [8,
|
|
120
|
-
[OperandType.UINT128, [16,
|
|
121
|
-
[OperandType.FF, [32,
|
|
121
|
+
[OperandType.UINT64, [8, readUint64BE, writeUint64BE]],
|
|
122
|
+
[OperandType.UINT128, [16, readUint128BE, writeUint128BE]],
|
|
123
|
+
[OperandType.FF, [32, readUint254BE, writeUint254BE]],
|
|
122
124
|
[OperandType.TAG, [1, Buffer.prototype.readUint8, Buffer.prototype.writeUint8]],
|
|
123
125
|
]);
|
|
124
126
|
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
let ret: bigint = 0n;
|
|
127
|
+
function readUintBE(buf: Buffer, offset: number, totalBytes: number): bigint {
|
|
128
|
+
let value: bigint = 0n;
|
|
128
129
|
for (let i = 0; i < totalBytes; ++i) {
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
value <<= 8n;
|
|
131
|
+
value |= BigInt(buf.readUint8(i + offset));
|
|
131
132
|
}
|
|
132
|
-
return
|
|
133
|
+
return value;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
function
|
|
136
|
-
const totalBytes = 32;
|
|
136
|
+
function writeUintBE(buf: Buffer, value: bigint, totalBytes: number): void {
|
|
137
137
|
for (let offset = totalBytes - 1; offset >= 0; --offset) {
|
|
138
|
-
|
|
138
|
+
buf.writeUint8(Number(value & 0xffn), offset);
|
|
139
139
|
value >>= 8n;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
let ret: bigint = 0n;
|
|
146
|
-
for (let i = 0; i < totalBytes; ++i) {
|
|
147
|
-
ret <<= 8n;
|
|
148
|
-
ret |= BigInt(this.readUint8(i + offset));
|
|
149
|
-
}
|
|
150
|
-
return ret;
|
|
143
|
+
function readUint64BE(this: Buffer, offset: number): bigint {
|
|
144
|
+
return readUintBE(this, offset, 8);
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
147
|
+
function writeUint64BE(this: Buffer, value: bigint): void {
|
|
148
|
+
writeUintBE(this, value, 8);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function readUint254BE(this: Buffer, offset: number): bigint {
|
|
152
|
+
let value = readUintBE(this, offset, 32);
|
|
153
|
+
|
|
154
|
+
// In circuit, we only support values up to Fr.MODULUS and any deserialized value
|
|
155
|
+
// would naturally undergo a modulus reduction.
|
|
156
|
+
if (value >= Fr.MODULUS) {
|
|
157
|
+
value = value % Fr.MODULUS;
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function writeUint254BE(this: Buffer, value: bigint): void {
|
|
164
|
+
writeUintBE(this, value, 32);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function readUint128BE(this: Buffer, offset: number): bigint {
|
|
168
|
+
return readUintBE(this, offset, 16);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function writeUint128BE(this: Buffer, value: bigint): void {
|
|
172
|
+
writeUintBE(this, value, 16);
|
|
159
173
|
}
|
|
160
174
|
|
|
161
175
|
/**
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
GlobalVariables,
|
|
22
22
|
NestedProcessReturnValues,
|
|
23
23
|
type ProcessedTx,
|
|
24
|
+
StateReference,
|
|
24
25
|
Tx,
|
|
25
26
|
TxExecutionPhase,
|
|
26
27
|
type TxValidator,
|
|
@@ -228,6 +229,7 @@ export class PublicProcessor implements Traceable {
|
|
|
228
229
|
// By doing this, every transaction starts on a fresh checkpoint and it's state updates only make it to the fork if this checkpoint is committed.
|
|
229
230
|
// Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
|
|
230
231
|
const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
|
|
232
|
+
const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
|
|
231
233
|
|
|
232
234
|
try {
|
|
233
235
|
const [processedTx, returnValues] = await this.processTx(tx, deadline);
|
|
@@ -276,16 +278,23 @@ export class PublicProcessor implements Traceable {
|
|
|
276
278
|
// This needs to be done directly on the underlying fork as the guarded fork has been stopped.
|
|
277
279
|
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
278
280
|
|
|
281
|
+
// Ensure we're at the same state as when we started processing this tx.
|
|
282
|
+
await this.checkWorldStateUnchanged(startStateReference, txHash, err);
|
|
283
|
+
|
|
279
284
|
// We should now be in a position where the fork is in a clean state and no further updates can be made to it.
|
|
280
285
|
break;
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
// Roll back state to start of TX before proceeding to next TX
|
|
284
289
|
await checkpoint.revert();
|
|
290
|
+
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
285
291
|
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
286
292
|
this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
|
|
287
293
|
failed.push({ tx, error: err instanceof Error ? err : new Error(errorMessage) });
|
|
288
294
|
returns.push(new NestedProcessReturnValues([]));
|
|
295
|
+
|
|
296
|
+
// Ensure we're at the same state as when we started processing this tx.
|
|
297
|
+
await this.checkWorldStateUnchanged(startStateReference, txHash, err);
|
|
289
298
|
} finally {
|
|
290
299
|
// Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
|
|
291
300
|
await checkpoint.commit();
|
|
@@ -309,6 +318,22 @@ export class PublicProcessor implements Traceable {
|
|
|
309
318
|
return [result, failed, usedTxs, returns];
|
|
310
319
|
}
|
|
311
320
|
|
|
321
|
+
private async checkWorldStateUnchanged(
|
|
322
|
+
startStateReference: StateReference,
|
|
323
|
+
txHash: `0x${string}`,
|
|
324
|
+
cause: Error,
|
|
325
|
+
): Promise<void> {
|
|
326
|
+
const endStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
|
|
327
|
+
if (!startStateReference.equals(endStateReference)) {
|
|
328
|
+
this.log.warn(`Fork state reference changed by tx ${txHash} after error in public processor`, {
|
|
329
|
+
expected: startStateReference.toInspect(),
|
|
330
|
+
actual: endStateReference.toInspect(),
|
|
331
|
+
cause,
|
|
332
|
+
});
|
|
333
|
+
throw new Error(`Fork state reference changed by tx ${txHash} after error in public processor`, { cause });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
312
337
|
@trackSpan('PublicProcessor.processTx', async tx => ({ [Attributes.TX_HASH]: (await tx.getTxHash()).toString() }))
|
|
313
338
|
private async processTx(tx: Tx, deadline?: Date): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
314
339
|
const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline));
|