@aztec/simulator 0.0.1-commit.5daedc8 → 0.0.1-commit.6230efd
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/common/errors.d.ts +2 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.d.ts +2 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +1 -1
- package/dest/private/acvm/serialize.d.ts +2 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +16 -15
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.d.ts +2 -2
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +1 -1
- package/dest/public/avm/avm_gas.d.ts +1 -1
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.d.ts +2 -2
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.d.ts +2 -2
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_memory_types.js +1 -1
- package/dest/public/avm/avm_simulator.d.ts +2 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +6 -5
- package/dest/public/avm/errors.d.ts +8 -2
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +14 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts +2 -2
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +3 -3
- package/dest/public/avm/fixtures/utils.d.ts +4 -3
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +3 -2
- package/dest/public/avm/opcodes/addressing_mode.js +2 -2
- package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +11 -1
- package/dest/public/avm/opcodes/ec_add.js +2 -2
- package/dest/public/avm/opcodes/hashing.d.ts +1 -1
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +9 -4
- package/dest/public/avm/opcodes/memory.js +1 -1
- package/dest/public/avm/opcodes/misc.js +2 -2
- package/dest/public/avm/revert_reason.d.ts +2 -2
- package/dest/public/avm/revert_reason.d.ts.map +1 -1
- package/dest/public/avm/revert_reason.js +3 -2
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
- package/dest/public/avm/serialization/instruction_serialization.js +1 -1
- package/dest/public/avm/test_utils.d.ts +2 -2
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +1 -1
- package/dest/public/contracts_db_checkpoint.d.ts +2 -2
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
- package/dest/public/db_interfaces.d.ts +2 -2
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/debug_fn_name.d.ts +15 -2
- package/dest/public/debug_fn_name.d.ts.map +1 -1
- package/dest/public/debug_fn_name.js +28 -2
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.js +4 -52
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
- package/dest/public/fixtures/custom_bytecode_tests.d.ts +4 -1
- package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tests.js +74 -9
- package/dest/public/fixtures/index.d.ts +4 -2
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +3 -1
- package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
- package/dest/public/fixtures/minimal_public_tx.js +2 -12
- package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
- package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
- package/dest/public/fixtures/opcode_spammer.js +1681 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +22 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +50 -13
- package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/fixtures/simple_contract_data_source.js +4 -4
- package/dest/public/fixtures/token_test.d.ts +6 -2
- package/dest/public/fixtures/token_test.d.ts.map +1 -1
- package/dest/public/fixtures/token_test.js +13 -11
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +4 -3
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +100 -0
- package/dest/public/hinting_db_sources.d.ts +5 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +5 -2
- package/dest/public/index.d.ts +2 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -2
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -2
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +3 -0
- package/dest/public/public_processor/public_processor.d.ts +5 -5
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +35 -22
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +18 -53
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +21 -34
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +60 -139
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
- package/dest/public/public_tx_simulator/factories.d.ts +13 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +4 -1
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +3 -3
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +11 -5
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/side_effect_trace.d.ts +2 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +1 -1
- package/dest/public/side_effect_trace_interface.d.ts +2 -2
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts +2 -2
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts +2 -2
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.js +1 -1
- package/dest/public/state_manager/state_manager.d.ts +7 -2
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +5 -2
- package/package.json +19 -19
- package/src/common/errors.ts +1 -1
- package/src/private/acvm/deserialize.ts +1 -1
- package/src/private/acvm/serialize.ts +1 -1
- package/src/private/circuit_recording/circuit_recorder.ts +17 -16
- package/src/public/avm/avm_context.ts +1 -1
- package/src/public/avm/avm_contract_call_result.ts +1 -1
- package/src/public/avm/avm_execution_environment.ts +1 -1
- package/src/public/avm/avm_gas.ts +3 -3
- package/src/public/avm/avm_machine_state.ts +1 -1
- package/src/public/avm/avm_memory_types.ts +1 -1
- package/src/public/avm/avm_simulator.ts +8 -5
- package/src/public/avm/errors.ts +17 -3
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/initializers.ts +3 -3
- package/src/public/avm/fixtures/utils.ts +3 -2
- package/src/public/avm/opcodes/addressing_mode.ts +2 -2
- package/src/public/avm/opcodes/arithmetic.ts +13 -1
- package/src/public/avm/opcodes/ec_add.ts +2 -2
- package/src/public/avm/opcodes/hashing.ts +10 -4
- package/src/public/avm/opcodes/memory.ts +1 -1
- package/src/public/avm/opcodes/misc.ts +2 -2
- package/src/public/avm/revert_reason.ts +6 -3
- package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
- package/src/public/avm/serialization/instruction_serialization.ts +1 -1
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/contracts_db_checkpoint.ts +1 -1
- package/src/public/db_interfaces.ts +1 -1
- package/src/public/debug_fn_name.ts +35 -3
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +7 -7
- package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
- package/src/public/fixtures/custom_bytecode_tests.ts +93 -9
- package/src/public/fixtures/index.ts +7 -1
- package/src/public/fixtures/minimal_public_tx.ts +4 -13
- package/src/public/fixtures/opcode_spammer.ts +1638 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +69 -13
- package/src/public/fixtures/simple_contract_data_source.ts +8 -9
- package/src/public/fixtures/token_test.ts +18 -9
- package/src/public/fixtures/utils.ts +2 -3
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
- package/src/public/hinting_db_sources.ts +8 -3
- package/src/public/index.ts +7 -1
- package/src/public/public_db_sources.ts +1 -1
- package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
- package/src/public/public_processor/public_processor.ts +43 -27
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +19 -60
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +68 -174
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
- package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
- package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
- package/src/public/public_tx_simulator/factories.ts +41 -0
- package/src/public/public_tx_simulator/index.ts +3 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_simulator.ts +24 -9
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
- package/src/public/side_effect_trace.ts +1 -1
- package/src/public/side_effect_trace_interface.ts +1 -1
- package/src/public/state_manager/nullifiers.ts +1 -1
- package/src/public/state_manager/public_storage.ts +1 -1
- package/src/public/state_manager/state_manager.ts +10 -3
|
@@ -83,7 +83,7 @@ export class Addressing {
|
|
|
83
83
|
baseAddr = mem.get(0);
|
|
84
84
|
const baseAddrTag = baseAddr.getTag();
|
|
85
85
|
if (!TaggedMemory.isValidMemoryAddressTag(baseAddrTag!)) {
|
|
86
|
-
throw TagCheckError.
|
|
86
|
+
throw TagCheckError.forBaseAddress(TypeTag[baseAddrTag!]);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
// Here we know that resolved[i] is at most 32 bits and baseAddr is at most 32 bits.
|
|
@@ -100,7 +100,7 @@ export class Addressing {
|
|
|
100
100
|
|
|
101
101
|
// Final check.
|
|
102
102
|
if (!TaggedMemory.isValidMemoryAddressTag(resolvedTag)) {
|
|
103
|
-
throw TagCheckError.
|
|
103
|
+
throw TagCheckError.forIndirectAddress(resolved[i], TypeTag[resolvedTag]);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
resolved[i] = Number(resolvedValue.toBigInt());
|
|
@@ -88,7 +88,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
|
|
|
88
88
|
static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
|
|
89
89
|
|
|
90
90
|
protected compute(a: Field, b: Field): Field {
|
|
91
|
-
|
|
91
|
+
if (b.toBigInt() === 0n) {
|
|
92
|
+
throw new ArithmeticError('Division by zero');
|
|
93
|
+
}
|
|
92
94
|
return a.fdiv(b);
|
|
93
95
|
}
|
|
94
96
|
|
|
@@ -105,6 +107,11 @@ export class Shl extends ThreeOperandArithmeticInstruction {
|
|
|
105
107
|
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
106
108
|
return a.shl(b);
|
|
107
109
|
}
|
|
110
|
+
|
|
111
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
112
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
113
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
export class Shr extends ThreeOperandArithmeticInstruction {
|
|
@@ -114,4 +121,9 @@ export class Shr extends ThreeOperandArithmeticInstruction {
|
|
|
114
121
|
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
|
|
115
122
|
return a.shr(b);
|
|
116
123
|
}
|
|
124
|
+
|
|
125
|
+
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
|
|
126
|
+
memory.checkTagsAreSame(aOffset, bOffset);
|
|
127
|
+
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
|
|
128
|
+
}
|
|
117
129
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Grumpkin } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Point } from '@aztec/foundation/
|
|
1
|
+
import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
|
|
2
|
+
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
3
3
|
|
|
4
4
|
import type { AvmContext } from '../avm_context.js';
|
|
5
5
|
import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { keccakf1600
|
|
1
|
+
import { keccakf1600 } from '@aztec/foundation/crypto/keccak';
|
|
2
|
+
import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { sha256Compression } from '@aztec/foundation/crypto/sha256';
|
|
2
4
|
|
|
3
5
|
import type { AvmContext } from '../avm_context.js';
|
|
4
6
|
import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
@@ -130,13 +132,17 @@ export class Sha256Compression extends Instruction {
|
|
|
130
132
|
const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
|
|
131
133
|
|
|
132
134
|
// Note: size of output is same as size of state
|
|
133
|
-
const inputs =
|
|
134
|
-
const state =
|
|
135
|
+
const inputs = memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toBigInt());
|
|
136
|
+
const state = memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toBigInt());
|
|
135
137
|
|
|
136
138
|
memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
|
|
137
139
|
memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
|
|
138
140
|
|
|
139
|
-
|
|
141
|
+
// At this point both state and inputs are Uint32Array-compatible
|
|
142
|
+
const inputsArray = new Uint32Array(inputs.map(i => Number(i)));
|
|
143
|
+
const stateArray = new Uint32Array(state.map(i => Number(i)));
|
|
144
|
+
|
|
145
|
+
const output = sha256Compression(stateArray, inputsArray);
|
|
140
146
|
|
|
141
147
|
// Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
|
|
142
148
|
const res = [...output].map(word => new Uint32(word));
|
|
@@ -56,11 +56,11 @@ export class DebugLog extends Instruction {
|
|
|
56
56
|
const memoryReads = 1 /* level */ + 1 /* fieldsSize */ + this.messageSize /* message */ + fieldsSize; /* fields */
|
|
57
57
|
if (
|
|
58
58
|
context.persistableState.getDebugLogMemoryReads() + memoryReads >
|
|
59
|
-
context.environment.config.maxDebugLogMemoryReads
|
|
59
|
+
context.environment.config.collectionLimits.maxDebugLogMemoryReads
|
|
60
60
|
) {
|
|
61
61
|
// Regular error on purpose: this is not a recoverable error.
|
|
62
62
|
throw new Error(
|
|
63
|
-
`Max debug log memory reads exceeded: ${context.persistableState.getDebugLogMemoryReads() + memoryReads} > ${context.environment.config.maxDebugLogMemoryReads}`,
|
|
63
|
+
`Max debug log memory reads exceeded: ${context.persistableState.getDebugLogMemoryReads() + memoryReads} > ${context.environment.config.collectionLimits.maxDebugLogMemoryReads}`,
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
context.persistableState.writeDebugLogMemoryReads(memoryReads);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
|
|
3
3
|
import type { AvmContext } from './avm_context.js';
|
|
4
4
|
import { type AvmExecutionError, AvmRevertReason } from './errors.js';
|
|
@@ -18,13 +18,16 @@ async function createRevertReason(message: string, revertData: Fr[], context: Av
|
|
|
18
18
|
message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const { functionSelector, functionName } = await context.persistableState.getPublicFunctionSelectorAndName(
|
|
22
|
+
context.environment,
|
|
23
|
+
);
|
|
22
24
|
|
|
23
25
|
return new AvmRevertReason(
|
|
24
26
|
message,
|
|
25
27
|
/*failingFunction=*/ {
|
|
26
28
|
contractAddress: context.environment.address,
|
|
27
|
-
|
|
29
|
+
functionSelector,
|
|
30
|
+
functionName,
|
|
28
31
|
},
|
|
29
32
|
/*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
30
33
|
/*options=*/ { cause: nestedError },
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AvmExecutionError,
|
|
5
|
+
AvmParsingError,
|
|
6
|
+
InvalidOpcodeError,
|
|
7
|
+
InvalidProgramCounterError,
|
|
8
|
+
InvalidTagValueError,
|
|
9
|
+
duringInstrFetch,
|
|
10
|
+
} from '../errors.js';
|
|
4
11
|
import {
|
|
5
12
|
Add,
|
|
6
13
|
And,
|
|
@@ -172,7 +179,7 @@ export function decodeInstructionFromBytecode(
|
|
|
172
179
|
instructionSet: InstructionSet = INSTRUCTION_SET,
|
|
173
180
|
): [Instruction, number] {
|
|
174
181
|
if (pc >= bytecode.length) {
|
|
175
|
-
throw new InvalidProgramCounterError(pc, bytecode.length);
|
|
182
|
+
throw new InvalidProgramCounterError(pc, bytecode.length - 1);
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
try {
|
|
@@ -182,7 +189,7 @@ export function decodeInstructionFromBytecode(
|
|
|
182
189
|
|
|
183
190
|
if (opcode > MAX_OPCODE_VALUE) {
|
|
184
191
|
throw new InvalidOpcodeError(
|
|
185
|
-
`Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes.`,
|
|
192
|
+
`Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes (at PC ${pc}).`,
|
|
186
193
|
);
|
|
187
194
|
}
|
|
188
195
|
|
|
@@ -192,13 +199,17 @@ export function decodeInstructionFromBytecode(
|
|
|
192
199
|
}
|
|
193
200
|
|
|
194
201
|
const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
|
|
202
|
+
|
|
195
203
|
const instruction = instructionDeserializer(cursor);
|
|
196
204
|
return [instruction, cursor.position() - startingPosition];
|
|
197
205
|
} catch (error) {
|
|
198
|
-
if (error instanceof
|
|
199
|
-
throw error;
|
|
206
|
+
if (error instanceof InvalidTagValueError || error instanceof InvalidOpcodeError) {
|
|
207
|
+
throw duringInstrFetch(error, pc);
|
|
208
|
+
} else if (error instanceof AvmExecutionError) {
|
|
209
|
+
throw new AvmParsingError(`Instruction parsing error at pc ${pc}: ${error.message}`);
|
|
200
210
|
} else {
|
|
201
|
-
|
|
211
|
+
const msg = error instanceof Error ? `: ${error.message}` : '';
|
|
212
|
+
throw new AvmParsingError(`Instruction fetching error at pc ${pc}${msg}`);
|
|
202
213
|
}
|
|
203
214
|
}
|
|
204
215
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
|
|
@@ -13,6 +13,38 @@ export async function getPublicFunctionDebugName(
|
|
|
13
13
|
if (!calldata[0]) {
|
|
14
14
|
return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const fallbackName = `<calldata[0]:${calldata[0].toString()}> (Contract Address: ${contractAddress})`;
|
|
17
|
+
const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
|
|
18
|
+
if (!selector) {
|
|
19
|
+
return fallbackName;
|
|
20
|
+
}
|
|
21
|
+
return (await db.getDebugFunctionName(contractAddress, selector)) ?? fallbackName;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the function selector and optional debug name for a public function.
|
|
26
|
+
* Returns the selector and name separately, with name only populated if a debug name is available.
|
|
27
|
+
* @param db - The contracts database
|
|
28
|
+
* @param contractAddress - The contract address
|
|
29
|
+
* @param calldata - The calldata (selector is in calldata[0])
|
|
30
|
+
* @returns An object with functionSelector (always if calldata[0] exists) and functionName (only if debug name found)
|
|
31
|
+
*/
|
|
32
|
+
export async function getPublicFunctionSelectorAndName(
|
|
33
|
+
db: PublicContractsDBInterface,
|
|
34
|
+
contractAddress: AztecAddress,
|
|
35
|
+
calldata: Fr[],
|
|
36
|
+
): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
|
|
37
|
+
// Public function is dispatched and therefore the target function is passed in the first argument.
|
|
38
|
+
if (!calldata[0]) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
|
|
42
|
+
if (!selector) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
const debugName = await db.getDebugFunctionName(contractAddress, selector);
|
|
46
|
+
return {
|
|
47
|
+
functionSelector: selector,
|
|
48
|
+
functionName: debugName ?? undefined,
|
|
49
|
+
};
|
|
18
50
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GeneratorIndex } from '@aztec/constants';
|
|
2
|
-
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
3
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
6
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
@@ -119,9 +119,9 @@ export async function megaBulkTest(
|
|
|
119
119
|
const argsField3 = [7, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
120
120
|
const argsField4 = [9, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
121
121
|
const argsField5 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
122
|
-
const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
123
|
-
const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
124
|
-
const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
122
|
+
//const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
123
|
+
//const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
124
|
+
//const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
125
125
|
const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
|
|
126
126
|
const genArgs = (argsField: Fr[]) => [
|
|
127
127
|
argsField,
|
|
@@ -145,9 +145,9 @@ export async function megaBulkTest(
|
|
|
145
145
|
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField3) },
|
|
146
146
|
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField4) },
|
|
147
147
|
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField5) },
|
|
148
|
-
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
|
|
149
|
-
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
|
|
150
|
-
{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
|
|
148
|
+
//{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
|
|
149
|
+
//{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
|
|
150
|
+
//{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
|
|
151
151
|
],
|
|
152
152
|
/*teardownCall=*/ undefined,
|
|
153
153
|
/*feePayer*/ undefined,
|
|
@@ -1,49 +1,83 @@
|
|
|
1
1
|
import { FunctionType, emptyContractArtifact, emptyFunctionArtifact } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { PublicTxResult } from '@aztec/stdlib/avm';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
5
|
|
|
5
6
|
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Test custom bytecode (simulation or proving) with the provided bytecode.
|
|
9
|
+
* Deploy a contract with the provided bytecode.
|
|
10
10
|
* @param bytecode - The bytecode buffer to use
|
|
11
|
-
* @param tester - The tester to use
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
11
|
+
* @param tester - The tester to use
|
|
12
|
+
* @param contractName - The name of the contract
|
|
13
|
+
* @param deployer - The deployer address
|
|
14
|
+
* @returns The deployed contract instance
|
|
14
15
|
*/
|
|
15
|
-
export async function
|
|
16
|
+
export async function deployCustomBytecode(
|
|
16
17
|
bytecode: Buffer,
|
|
17
18
|
tester: PublicTxSimulationTester,
|
|
18
|
-
txLabel: string,
|
|
19
19
|
contractName: string = 'CustomBytecodeContract',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
deployer: AztecAddress = AztecAddress.fromNumber(42),
|
|
21
|
+
): Promise<ContractInstanceWithAddress> {
|
|
23
22
|
const contractArtifact = emptyContractArtifact();
|
|
24
23
|
contractArtifact.name = contractName;
|
|
25
24
|
contractArtifact.functions = [emptyFunctionArtifact()];
|
|
25
|
+
// We use name 'public_dispatch' since that is what is expected
|
|
26
|
+
// in a ContractArtifact. But function selectors are not required
|
|
27
|
+
// when executing since the custom bytecode likely has no dispatch.
|
|
26
28
|
contractArtifact.functions[0].name = 'public_dispatch';
|
|
27
29
|
contractArtifact.functions[0].functionType = FunctionType.PUBLIC;
|
|
28
30
|
contractArtifact.functions[0].bytecode = bytecode;
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
// return the contract instance
|
|
33
|
+
return await tester.registerAndDeployContract(
|
|
31
34
|
/*constructorArgs=*/ [],
|
|
32
35
|
deployer,
|
|
33
36
|
/*contractArtifact=*/ contractArtifact,
|
|
34
37
|
);
|
|
38
|
+
}
|
|
35
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Execute a custom bytecode contract.
|
|
42
|
+
* @param contract - The contract instance to execute
|
|
43
|
+
* @param tester - The tester to use
|
|
44
|
+
* @param txLabel - The label of the transaction
|
|
45
|
+
* @param calldata - The calldata to use
|
|
46
|
+
* @returns The execution result
|
|
47
|
+
*/
|
|
48
|
+
export async function executeCustomBytecode(
|
|
49
|
+
contract: ContractInstanceWithAddress,
|
|
50
|
+
tester: PublicTxSimulationTester,
|
|
51
|
+
txLabel: string = 'CustomBytecodeTest',
|
|
52
|
+
calldata: any[] = [],
|
|
53
|
+
): Promise<PublicTxResult> {
|
|
36
54
|
// EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
|
|
37
55
|
return await tester.executeTxWithLabel(
|
|
38
56
|
/*txLabel=*/ txLabel,
|
|
39
|
-
/*sender=*/ deployer,
|
|
57
|
+
/*sender=*/ contract.deployer,
|
|
40
58
|
/*setupCalls=*/ [],
|
|
41
|
-
/*appCalls=*/ [
|
|
42
|
-
{
|
|
43
|
-
address: testContract.address,
|
|
44
|
-
fnName: 'public_dispatch',
|
|
45
|
-
args: [],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
59
|
+
/*appCalls=*/ [{ address: contract.address, args: calldata }],
|
|
48
60
|
);
|
|
49
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Deploy and execute a custom bytecode contract.
|
|
65
|
+
* @param bytecode - The bytecode buffer to use
|
|
66
|
+
* @param tester - The tester to use
|
|
67
|
+
* @param txLabel - The label of the transaction
|
|
68
|
+
* @param contractName - The name of the contract
|
|
69
|
+
* @param deployer - The deployer address
|
|
70
|
+
* @param calldata - The calldata to use
|
|
71
|
+
* @returns The execution result
|
|
72
|
+
*/
|
|
73
|
+
export async function deployAndExecuteCustomBytecode(
|
|
74
|
+
bytecode: Buffer,
|
|
75
|
+
tester: PublicTxSimulationTester,
|
|
76
|
+
txLabel: string = 'CustomBytecodeTest',
|
|
77
|
+
contractName: string = 'CustomBytecodeContract',
|
|
78
|
+
deployer: AztecAddress = AztecAddress.fromNumber(42),
|
|
79
|
+
calldata: any[] = [],
|
|
80
|
+
): Promise<PublicTxResult> {
|
|
81
|
+
const testContract = await deployCustomBytecode(bytecode, tester, contractName, deployer);
|
|
82
|
+
return await executeCustomBytecode(testContract, tester, txLabel, calldata);
|
|
83
|
+
}
|
|
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
|
|
|
2
2
|
|
|
3
3
|
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
4
4
|
import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
|
|
5
|
-
import { CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
5
|
+
import { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
|
|
6
6
|
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
7
7
|
import {
|
|
8
8
|
MAX_OPCODE_VALUE,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
OperandType,
|
|
11
11
|
getOperandSize,
|
|
12
12
|
} from '../avm/serialization/instruction_serialization.js';
|
|
13
|
-
import {
|
|
13
|
+
import { deployAndExecuteCustomBytecode } from './custom_bytecode_tester.js';
|
|
14
14
|
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
15
15
|
|
|
16
16
|
// First instruction resolved a base address (offset 0) which is uninitialized and therefore
|
|
@@ -28,7 +28,91 @@ export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester
|
|
|
28
28
|
]);
|
|
29
29
|
|
|
30
30
|
const txLabel = isIndirect ? 'AddressingWithBaseTagInvalidIndirect' : 'AddressingWithBaseTagInvalidDirect';
|
|
31
|
-
return await
|
|
31
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// First instruction sets a value with tag U64 at offset 0. Then a CalldataCopy instruction
|
|
35
|
+
// uses INDIRECT addressing to read from offset 0, which should fail because the value at
|
|
36
|
+
// offset 0 has tag U64 (not U32), making it an invalid address tag.
|
|
37
|
+
export async function addressingWithIndirectTagIssueTest(tester: PublicTxSimulationTester) {
|
|
38
|
+
// Set a U64 value at offset 0 - this will be used as an indirect address
|
|
39
|
+
const addressingMode = Addressing.fromModes([
|
|
40
|
+
AddressingMode.INDIRECT, // First operand (cdOffset) uses indirect addressing
|
|
41
|
+
AddressingMode.DIRECT,
|
|
42
|
+
AddressingMode.DIRECT,
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const bytecode = encodeToBytecode([
|
|
46
|
+
// Set a U64 value at offset 0 - this has the wrong tag for an address (should be U32)
|
|
47
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT64, /*value=*/ 100n).as(Opcode.SET_64, Set.wireFormat64),
|
|
48
|
+
// Try to use indirect addressing: read from offset 0, which contains a U64 value
|
|
49
|
+
// This should fail because U64 is not a valid address tag (must be U32)
|
|
50
|
+
new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 1),
|
|
51
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
const txLabel = 'AddressingWithIndirectTagInvalid';
|
|
55
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// First instruction sets a value 10 with tag U32 at offset 1 (direct, no relative).
|
|
59
|
+
// Then an ADD_16 instruction uses INDIRECT addressing for the first operand (offset 1)
|
|
60
|
+
// and RELATIVE addressing for the second operand (offset 2). The indirect addressing
|
|
61
|
+
// succeeds (reads U32 value 10 from offset 1, uses it as address), but the relative
|
|
62
|
+
// addressing fails because the base address at offset 0 has the wrong tag (uninitialized/invalid).
|
|
63
|
+
export async function addressingWithIndirectThenRelativeTagIssueTest(tester: PublicTxSimulationTester) {
|
|
64
|
+
const addressingMode = Addressing.fromModes([
|
|
65
|
+
AddressingMode.INDIRECT, // First operand (aOffset) uses indirect addressing, no relative
|
|
66
|
+
AddressingMode.RELATIVE, // Second operand (bOffset) uses relative addressing
|
|
67
|
+
AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
const bytecode = encodeToBytecode([
|
|
71
|
+
// Set a U32 value 10 at offset 1 - this will be used as an indirect address
|
|
72
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, /*value=*/ 10).as(Opcode.SET_32, Set.wireFormat32),
|
|
73
|
+
// ADD_16: first operand uses indirect addressing (reads from offset 1, gets value 10, uses as address - succeeds)
|
|
74
|
+
// second operand uses relative addressing (tries to read base from offset 0, but offset 0 has wrong tag - fails)
|
|
75
|
+
new Add(/*indirect=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
|
|
76
|
+
Opcode.ADD_16,
|
|
77
|
+
Add.wireFormat16,
|
|
78
|
+
),
|
|
79
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const txLabel = 'AddressingWithIndirectThenRelativeTagInvalid';
|
|
83
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// First instruction sets UINT32_MAX at offset 0 (base address) with tag U32.
|
|
87
|
+
// Then an ADD_8 instruction uses INDIRECT_RELATIVE addressing for the first operand (offset 1)
|
|
88
|
+
// and INDIRECT addressing for the second operand (offset 2). The relative addressing
|
|
89
|
+
// for the first operand will overflow (UINT32_MAX + 1 >= MAX_MEMORY_SIZE), causing the instruction to fail.
|
|
90
|
+
// The second operand will also fail (indirect addressing from offset 2 which is uninitialized with tag FF).
|
|
91
|
+
export async function addressingWithRelativeOverflowAndIndirectTagIssueTest(tester: PublicTxSimulationTester) {
|
|
92
|
+
const addressingMode = Addressing.fromModes([
|
|
93
|
+
AddressingMode.INDIRECT_RELATIVE, // First operand (aOffset) uses both indirect and relative addressing
|
|
94
|
+
AddressingMode.INDIRECT, // Second operand (bOffset) uses indirect addressing only
|
|
95
|
+
AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
// UINT32_MAX = 2^32 - 1 = 4294967295
|
|
99
|
+
const UINT32_MAX = 0xffffffff;
|
|
100
|
+
|
|
101
|
+
const bytecode = encodeToBytecode([
|
|
102
|
+
// Set UINT32_MAX at offset 0 as base address - this will cause overflow when adding relative offset 1
|
|
103
|
+
new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ UINT32_MAX).as(
|
|
104
|
+
Opcode.SET_32,
|
|
105
|
+
Set.wireFormat32,
|
|
106
|
+
),
|
|
107
|
+
new Add(/*indirect=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
|
|
108
|
+
Opcode.ADD_8,
|
|
109
|
+
Add.wireFormat8,
|
|
110
|
+
),
|
|
111
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
const txLabel = 'AddressingWithRelativeOverflowAndIndirectTagInvalid';
|
|
115
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
32
116
|
}
|
|
33
117
|
|
|
34
118
|
export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
|
|
@@ -38,7 +122,7 @@ export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
|
|
|
38
122
|
]);
|
|
39
123
|
|
|
40
124
|
const txLabel = 'PcOutOfRange';
|
|
41
|
-
return await
|
|
125
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
42
126
|
}
|
|
43
127
|
|
|
44
128
|
export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
|
|
@@ -57,7 +141,7 @@ export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
|
|
|
57
141
|
bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
|
|
58
142
|
|
|
59
143
|
const txLabel = 'InvalidOpcode';
|
|
60
|
-
return await
|
|
144
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
61
145
|
}
|
|
62
146
|
|
|
63
147
|
// Single invalid byte in the bytecode.
|
|
@@ -67,7 +151,7 @@ export async function invalidByteTest(tester: PublicTxSimulationTester) {
|
|
|
67
151
|
const bytecode = Buffer.from([invalidOpcode]);
|
|
68
152
|
|
|
69
153
|
const txLabel = 'InvalidByte';
|
|
70
|
-
return await
|
|
154
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
71
155
|
}
|
|
72
156
|
|
|
73
157
|
// Truncate the last instruction in the bytecode.
|
|
@@ -80,7 +164,7 @@ export async function instructionTruncatedTest(tester: PublicTxSimulationTester)
|
|
|
80
164
|
bytecode = bytecode.subarray(0, -1);
|
|
81
165
|
|
|
82
166
|
const txLabel = 'InstructionTruncated';
|
|
83
|
-
return await
|
|
167
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
84
168
|
}
|
|
85
169
|
|
|
86
170
|
// Invalid tag value byte in an instruction.
|
|
@@ -95,7 +179,7 @@ export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
|
|
|
95
179
|
bytecode[tagOffset] = TypeTag.INVALID;
|
|
96
180
|
|
|
97
181
|
const txLabel = 'InvalidTagValue';
|
|
98
|
-
return await
|
|
182
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
99
183
|
}
|
|
100
184
|
|
|
101
185
|
// Combine an invalid tag in the last instruction that is truncated.
|
|
@@ -112,7 +196,7 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
|
|
|
112
196
|
bytecode[tagOffset] = 0x6f; // Invalid tag value.
|
|
113
197
|
|
|
114
198
|
const txLabel = 'InvalidTagValueAndInstructionTruncated';
|
|
115
|
-
return await
|
|
199
|
+
return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
|
|
116
200
|
}
|
|
117
201
|
|
|
118
202
|
/**
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export * from './public_tx_simulation_tester.js';
|
|
2
2
|
export * from './utils.js';
|
|
3
3
|
export * from './simple_contract_data_source.js';
|
|
4
|
-
export {
|
|
4
|
+
export { executeAvmMinimalPublicTx } from './minimal_public_tx.js';
|
|
5
5
|
export { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
6
6
|
export { ammTest } from './amm_test.js';
|
|
7
7
|
export { bulkTest, megaBulkTest } from './bulk_test.js';
|
|
8
8
|
export { tokenTest } from './token_test.js';
|
|
9
9
|
export * from './custom_bytecode_tests.js';
|
|
10
|
+
export {
|
|
11
|
+
deployCustomBytecode,
|
|
12
|
+
executeCustomBytecode,
|
|
13
|
+
deployAndExecuteCustomBytecode,
|
|
14
|
+
} from './custom_bytecode_tester.js';
|
|
15
|
+
export { getSpamConfigsPerOpcode, testOpcodeSpamCase } from './opcode_spammer.js';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PublicTxResult } from '@aztec/stdlib/avm';
|
|
2
2
|
import { ProtocolContracts } from '@aztec/stdlib/tx';
|
|
3
3
|
|
|
4
|
-
import avmMinimalCircuitInputsJson from '../../../artifacts/avm_minimal_inputs.json' with { type: 'json' };
|
|
5
4
|
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
6
5
|
import { Add, Return, Set } from '../avm/opcodes/index.js';
|
|
7
6
|
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
8
7
|
import { Opcode } from '../avm/serialization/instruction_serialization.js';
|
|
9
|
-
import {
|
|
8
|
+
import { deployAndExecuteCustomBytecode } from './custom_bytecode_tester.js';
|
|
10
9
|
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
11
10
|
|
|
12
11
|
export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester): Promise<PublicTxResult> {
|
|
@@ -17,19 +16,11 @@ export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester
|
|
|
17
16
|
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
|
|
18
17
|
]);
|
|
19
18
|
|
|
20
|
-
const result = await
|
|
19
|
+
const result = await deployAndExecuteCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');
|
|
21
20
|
|
|
22
21
|
// Modify the protocol contracts to be all zeros
|
|
23
22
|
result.hints!.protocolContracts = ProtocolContracts.empty();
|
|
24
|
-
result.publicInputs
|
|
23
|
+
result.publicInputs!.protocolContracts = ProtocolContracts.empty();
|
|
25
24
|
|
|
26
25
|
return result;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Reads the AVM circuit inputs for the minimal public tx from a pre-generated JSON file.
|
|
31
|
-
* @returns The AvmCircuitInputs for the minimal public tx.
|
|
32
|
-
*/
|
|
33
|
-
export function readAvmMinimalPublicTxInputsFromFile(): AvmCircuitInputs {
|
|
34
|
-
return AvmCircuitInputs.schema.parse(avmMinimalCircuitInputsJson);
|
|
35
|
-
}
|