Skip to content

Commit 8fa76dc

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/barretenberg
2 parents c17a852 + a5b02bb commit 8fa76dc

File tree

32 files changed

+217
-200
lines changed

32 files changed

+217
-200
lines changed

avm-transpiler/src/transpile.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,13 +1696,19 @@ fn handle_storage_read(
16961696
destinations: &[ValueOrArray],
16971697
inputs: &[ValueOrArray],
16981698
) {
1699-
assert_eq!(inputs.len(), 1); // output
1699+
assert_eq!(inputs.len(), 2); // slot, contract_address
17001700
assert_eq!(destinations.len(), 1); // return value
17011701

17021702
let slot_offset_maybe = inputs[0];
17031703
let slot_offset = match slot_offset_maybe {
17041704
ValueOrArray::MemoryAddress(slot_offset) => slot_offset,
1705-
_ => panic!("ForeignCall address input should be a single value"),
1705+
_ => panic!("ForeignCall slot input should be a single value"),
1706+
};
1707+
1708+
let contract_address_offset_maybe = inputs[1];
1709+
let contract_address_offset = match contract_address_offset_maybe {
1710+
ValueOrArray::MemoryAddress(contract_address_offset) => contract_address_offset,
1711+
_ => panic!("ForeignCall contract_address input should be a single value"),
17061712
};
17071713

17081714
let dest_offset_maybe = destinations[0];
@@ -1716,11 +1722,13 @@ fn handle_storage_read(
17161722
addressing_mode: Some(
17171723
AddressingModeBuilder::default()
17181724
.direct_operand(&slot_offset)
1725+
.direct_operand(&contract_address_offset)
17191726
.direct_operand(&dest_offset)
17201727
.build(),
17211728
),
17221729
operands: vec![
17231730
AvmOperand::U16 { value: slot_offset.to_u32() as u16 },
1731+
AvmOperand::U16 { value: contract_address_offset.to_u32() as u16 },
17241732
AvmOperand::U16 { value: dest_offset.to_u32() as u16 },
17251733
],
17261734
..Default::default()

barretenberg/cpp/pil/vm2/opcodes/sload.pil

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ include "../trees/public_data_check.pil";
44
// SLOAD opcode: Reads a value from storage at the provided slot
55
//
66
// This opcode interacts with the public data check gadget to read a value at the specified slot.
7-
// The execution trace reads the slot from memory into register[0], performs FF tag validation,
8-
// and writes the value retrieved from the tree to memory via register[1].
7+
// The execution trace reads the slot from memory into register[0], the contract address from
8+
// memory into register[1], performs FF tag validation, and writes the value retrieved from the
9+
// tree to memory via register[2].
910
// The value written to memory is checked to have tag FF.
1011
//
1112
// Register usage:
1213
// - register[0]: Contains the storage slot to read from
13-
// - register[1]: Contains the retrieved value to be written to memory
14+
// - register[1]: Contains the contract address to read from
15+
// - register[2]: Contains the retrieved value to be written to memory
1416
//
1517
// The opcode leverages the public_data_check gadget to verify the storage read operation
1618
// against the current public data tree root. The public_data_check gadget silos the slot
17-
// with the current contract address.
19+
// with the contract address.
1820
//
1921
namespace execution; // this is a virtual gadget that shares rows with the execution trace
2022

@@ -23,19 +25,19 @@ namespace execution; // this is a virtual gadget that shares rows with the execu
2325

2426
#[STORAGE_READ]
2527
sel_execute_sload {
26-
contract_address, // From context
27-
register[0],
28-
register[1],
28+
register[0], // Slot
29+
register[1], // Contract address from memory
30+
register[2], // Value (output)
2931
prev_public_data_tree_root // From context
3032
} in public_data_check.sel {
31-
public_data_check.address,
3233
public_data_check.slot,
34+
public_data_check.address,
3335
public_data_check.value,
3436
public_data_check.root
3537
};
3638

3739
#[SLOAD_FF_OUTPUT_TAG]
38-
sel_execute_sload * (constants.MEM_TAG_FF - mem_tag_reg[1]) = 0;
40+
sel_execute_sload * (constants.MEM_TAG_FF - mem_tag_reg[2]) = 0;
3941

4042
// This opcode is infallible and sel_opcode_error is constrained to be zero
4143
// in execution.pil (see #[INFALLIBLE_OPCODES_SUCCESS]).

barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/instructions/instruction.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ void sanitize_address_ref(AddressRef& address_ref, uint32_t base_offset, uint32_
8282
}
8383
}
8484

85+
uint32_t generate_address(std::mt19937_64& rng)
86+
{
87+
if (std::uniform_int_distribution<int>(0, 19)(rng) == 0) { // 5% chance to generate the highest address
88+
return AVM_HIGHEST_MEM_ADDRESS;
89+
}
90+
return generate_random_uint32(rng);
91+
}
92+
8593
} // namespace
8694

8795
namespace bb::avm2::fuzzer {
@@ -355,7 +363,7 @@ AddressingMode InstructionMutator::generate_addressing_mode(std::mt19937_64& rng
355363

356364
AddressRef InstructionMutator::generate_address_ref(std::mt19937_64& rng, uint32_t max_operand_value)
357365
{
358-
AddressRef address_ref = AddressRef{ .address = generate_random_uint32(rng),
366+
AddressRef address_ref = AddressRef{ .address = generate_address(rng),
359367
.pointer_address_seed = generate_random_uint16(rng),
360368
.mode = generate_addressing_mode(rng) };
361369
sanitize_address_ref(address_ref, base_offset, max_operand_value);

barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const std::unordered_map<WireOpCode, std::array<uint8_t, NUM_OP_DC_SELECTORS>>&
7272
{ WireOpCode::MOV_16, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
7373

7474
// World State
75-
{ WireOpCode::SLOAD, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
75+
{ WireOpCode::SLOAD, { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
7676
{ WireOpCode::SSTORE, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
7777
{ WireOpCode::NOTEHASHEXISTS, { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
7878
{ WireOpCode::EMITNOTEHASH, { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
@@ -336,7 +336,7 @@ const std::unordered_map<WireOpCode, WireInstructionSpec>& get_wire_instruction_
336336
// World State
337337
{ WireOpCode::SLOAD,
338338
{ .exec_opcode = ExecutionOpCode::SLOAD,
339-
.size_in_bytes = 6,
339+
.size_in_bytes = 8,
340340
.op_dc_selectors = get_wire_opcode_dc_selectors().at(WireOpCode::SLOAD) } },
341341
{ WireOpCode::SSTORE,
342342
{ .exec_opcode = ExecutionOpCode::SSTORE,
@@ -637,9 +637,11 @@ const std::unordered_map<ExecutionOpCode, ExecInstructionSpec>& get_exec_instruc
637637
.gas_cost = { .opcode_gas = AVM_MOV_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
638638
.register_info = RegisterInfo().add_input(/*src*/).add_output(/*dst*/) } },
639639
{ ExecutionOpCode::SLOAD,
640-
{ .num_addresses = 2,
640+
{ .num_addresses = 3,
641641
.gas_cost = { .opcode_gas = AVM_SLOAD_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
642-
.register_info = RegisterInfo().add_input(/*slot*/ ValueTag::FF).add_output(/*dst*/) } },
642+
.register_info = RegisterInfo()
643+
.add_inputs({ /*slot*/ ValueTag::FF, /*contract_address*/ ValueTag::FF })
644+
.add_output(/*dst*/) } },
643645
{ ExecutionOpCode::SSTORE,
644646
{ .num_addresses = 2,
645647
.gas_cost = { .opcode_gas = AVM_SSTORE_BASE_L2_GAS,

barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class AvmHardCodedVKAndHash {
9999
uint256_t(
100100
"0x0000000000000000000000000000000000000000000000000000000000000002")), // precomputed_first_row
101101
Commitment(
102-
uint256_t("0x2333e362e64fb1f107caced2abe6b15c83432eb7a32de2ecf30977a614985279"),
102+
uint256_t("0x00d3b534945cae272828a9621e350a4f42efe4258f3432b2ba7a535a6f8bd68f"),
103103
uint256_t(
104-
"0x0807a4fd784c9f8c30579a87a35c1841f81dfdf26bbb80ed89be6f5e972ebf76")), // precomputed_instr_size
104+
"0x07924546f2d14918d809f440d770e88525d4787c828e1efcb6154e1c2b257da9")), // precomputed_instr_size
105105
Commitment(
106106
uint256_t("0x11b710f896157a9557278a1f776cd6c7e1e7e256a572bd080797daaf1d6307d1"),
107107
uint256_t(
@@ -214,13 +214,13 @@ class AvmHardCodedVKAndHash {
214214
uint256_t(
215215
"0x0c76ef320d793294cfbf1519c7a124b640859b99d43d051dc828f0053081a4f0")), // precomputed_rw_reg_0_
216216
Commitment(
217-
uint256_t("0x2af2a42cc4fee5dbce68325a3264b898a726408414a0a6c789294bc54229a4de"),
217+
uint256_t("0x23d96c05f4bc75a456d34d051f876ef99ad7b22c4e21908b13b9f576a9d4c620"),
218218
uint256_t(
219-
"0x1852c4482c0f7af7895dff6d6342c39e440dd4b87c6c58e1dbe65b9ad2cfac44")), // precomputed_rw_reg_1_
219+
"0x008b8cb54710e5387557d73f2122ddd02a393ced7c57987776b55d6292964d89")), // precomputed_rw_reg_1_
220220
Commitment(
221-
uint256_t("0x0ea6ee40df0431b45fcc37d168b9a8acee572cea67f79f7c3ef7371fd4a45330"),
221+
uint256_t("0x039eae92cc21bf3c73b8406d17e8a06154a76ea489dfa0fb6049b9750a40b388"),
222222
uint256_t(
223-
"0x2e25f8abaf300ceaea6edb0d6e54539b4bedbdc034216e8e09c770b393d6a97a")), // precomputed_rw_reg_2_
223+
"0x1e2e477b3a65fc69df47516f7d306b81d3205d1e1983aadafe99f6aea755d944")), // precomputed_rw_reg_2_
224224
Commitment::infinity(), // precomputed_rw_reg_3_
225225
Commitment::infinity(), // precomputed_rw_reg_4_
226226
Commitment::infinity(), // precomputed_rw_reg_5_
@@ -261,9 +261,9 @@ class AvmHardCodedVKAndHash {
261261
uint256_t(
262262
"0x04a79156fabb49e693ddcf07815f53d163489149958311b79a4fcfd2703bf3fd")), // precomputed_sel_mem_op_reg_1_
263263
Commitment(
264-
uint256_t("0x2f9e1bd2b45c3be1bdf33b898ac4cc0dba2d96bcf77f0fdb24b666a954a2cccd"),
264+
uint256_t("0x252ca1bf6e5e141f715b94f7c186675aed430fe49c8ec06e46160e41c9086c97"),
265265
uint256_t(
266-
"0x1821245ac9715620427cfcb8f268d1b8b0c6af808c87d1047fab5ba3f0b2253d")), // precomputed_sel_mem_op_reg_2_
266+
"0x29d3d381d379ce261c1e66817822d796c6e605c276bf1f5993715ee56a5c7b82")), // precomputed_sel_mem_op_reg_2_
267267
Commitment(
268268
uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"),
269269
uint256_t(
@@ -338,9 +338,9 @@ class AvmHardCodedVKAndHash {
338338
uint256_t(
339339
"0x07aa17a6a67bcafb019d4adc0192a41f801563508f1ba7c64cd056731e2a7e01")), // precomputed_sel_op_dc_3
340340
Commitment(
341-
uint256_t("0x09c2810761dfd6879fd4ce6643fba632c0021351df5f3222fee25527be52566d"),
341+
uint256_t("0x074d234606a4d5bb93e0b2ad331eb61bdeaf87a7813bcc2b06494251154d9fb8"),
342342
uint256_t(
343-
"0x17880a4bed3382c66329a6cfcc49c70a33b3cc6bfcc500139cac203c074c22e2")), // precomputed_sel_op_dc_4
343+
"0x13e4734b603d75d2e71ba58a0fcf7532b2007296d22365242432bd708f5ed76a")), // precomputed_sel_op_dc_4
344344
Commitment(
345345
uint256_t("0x0ddf9e9dd8363fd4119ac1d79553829192ac465e7ee6656f099e40e5a8b709b0"),
346346
uint256_t(
@@ -370,9 +370,9 @@ class AvmHardCodedVKAndHash {
370370
uint256_t(
371371
"0x1945936772c40110b3ba7682c358ec4772d42e9b6152a4f8706fda2c4bbe85ff")), // precomputed_sel_op_is_address_1_
372372
Commitment(
373-
uint256_t("0x1f5b1e92050dcf9e5704486a2988ccaf207fc251d61c16e2b19e121669ce35ec"),
373+
uint256_t("0x06ea2e61015bf705c8e4f76bcccf8549ff3c66d1aaaaba0eefa491c2629922b2"),
374374
uint256_t(
375-
"0x1b320fadc737d6a4fd0e0743d2b8b67ea39dd23782151d9f22d9d4bfaf9ef504")), // precomputed_sel_op_is_address_2_
375+
"0x08381a2b896ad123189cf793ad2a205484c9c269572b8041261b60a358e8eee3")), // precomputed_sel_op_is_address_2_
376376
Commitment(
377377
uint256_t("0x3052e46c51289f5e76d606f7b57dd4f535602a065abdb0c6e9d02355ea1a31aa"),
378378
uint256_t(
@@ -426,9 +426,9 @@ class AvmHardCodedVKAndHash {
426426
uint256_t(
427427
"0x20361a4e1e73f07142325b1271d5fb172cb32252b44996dbed0264117cdb7b01")), // precomputed_sel_tag_check_reg_0_
428428
Commitment(
429-
uint256_t("0x018c380ccea19d9a50cbe3ed00c7461bda1f7e994f5dc2e7f6ed79642884b0aa"),
429+
uint256_t("0x061fc7f3ab86d2e539fa6acfa1a57c36ae3cdeb3f94f27fd4621e0b290a3e367"),
430430
uint256_t(
431-
"0x2019fb9538f8286cd319ddd6ee82904e932b858a2d1cdf18b4393134df1c8666")), // precomputed_sel_tag_check_reg_1_
431+
"0x2d6b6d6a6af0eb44678a40ac35a86dd3b2ba2529151d23589c1e65ff502dd888")), // precomputed_sel_tag_check_reg_1_
432432
Commitment(
433433
uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"),
434434
uint256_t(

barretenberg/cpp/src/barretenberg/vm2/constraining/relations/storage_load.test.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ TEST(SLoadConstrainingTest, PositiveTest)
5959
TestTraceContainer trace({
6060
{ { C::execution_sel_execute_sload, 1 },
6161
{ C::execution_register_0_, /*slot=*/42 },
62-
{ C::execution_register_1_, /*dst=*/27 },
62+
{ C::execution_register_1_, /*contract_address=*/1 },
63+
{ C::execution_register_2_, /*value=*/27 },
6364
{ C::execution_mem_tag_reg_0_, static_cast<uint8_t>(MemoryTag::FF) },
6465
{ C::execution_mem_tag_reg_1_, static_cast<uint8_t>(MemoryTag::FF) },
66+
{ C::execution_mem_tag_reg_2_, static_cast<uint8_t>(MemoryTag::FF) },
6567
{ C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_SLOAD } },
6668
});
6769
check_relation<sload>(trace);
@@ -72,9 +74,11 @@ TEST(SLoadConstrainingTest, NegativeInvalidOutputTag)
7274
TestTraceContainer trace({
7375
{ { C::execution_sel_execute_sload, 1 },
7476
{ C::execution_register_0_, /*slot=*/42 },
75-
{ C::execution_register_1_, /*dst=*/27 },
77+
{ C::execution_register_1_, /*contract_address=*/1 },
78+
{ C::execution_register_2_, /*value=*/27 },
7679
{ C::execution_mem_tag_reg_0_, static_cast<uint8_t>(MemoryTag::FF) },
77-
{ C::execution_mem_tag_reg_1_, static_cast<uint8_t>(MemoryTag::U32) },
80+
{ C::execution_mem_tag_reg_1_, static_cast<uint8_t>(MemoryTag::FF) },
81+
{ C::execution_mem_tag_reg_2_, static_cast<uint8_t>(MemoryTag::U32) },
7882
{ C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_SLOAD } },
7983
});
8084
EXPECT_THROW_WITH_MESSAGE(check_relation<sload>(trace), "SLOAD_FF_OUTPUT_TAG");
@@ -85,9 +89,11 @@ TEST(SLoadConstrainingTest, NegativeSloadSuccess)
8589
TestTraceContainer trace({
8690
{ { C::execution_sel_execute_sload, 1 },
8791
{ C::execution_register_0_, /*slot=*/42 },
88-
{ C::execution_register_1_, /*dst=*/27 },
92+
{ C::execution_register_1_, /*contract_address=*/1 },
93+
{ C::execution_register_2_, /*value=*/27 },
8994
{ C::execution_mem_tag_reg_0_, static_cast<uint8_t>(MemoryTag::FF) },
9095
{ C::execution_mem_tag_reg_1_, static_cast<uint8_t>(MemoryTag::FF) },
96+
{ C::execution_mem_tag_reg_2_, static_cast<uint8_t>(MemoryTag::FF) },
9197
{ C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_SLOAD },
9298
{ C::execution_sel_opcode_error, 1 } },
9399
});
@@ -132,11 +138,12 @@ TEST(SLoadConstrainingTest, Interactions)
132138
TestTraceContainer trace({
133139
{ { C::execution_sel_execute_sload, 1 },
134140
{ C::execution_register_0_, slot },
135-
{ C::execution_register_1_, value },
141+
{ C::execution_register_1_, FF(contract_address) },
142+
{ C::execution_register_2_, value },
136143
{ C::execution_mem_tag_reg_0_, static_cast<uint8_t>(MemoryTag::FF) },
137144
{ C::execution_mem_tag_reg_1_, static_cast<uint8_t>(MemoryTag::FF) },
145+
{ C::execution_mem_tag_reg_2_, static_cast<uint8_t>(MemoryTag::FF) },
138146
{ C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_SLOAD },
139-
{ C::execution_contract_address, contract_address },
140147
{ C::execution_prev_public_data_tree_root, trees.public_data_tree.root } },
141148
});
142149

barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_sload.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ struct lookup_sload_storage_read_settings_ {
2222
static constexpr Column COUNTS = Column::lookup_sload_storage_read_counts;
2323
static constexpr Column INVERSES = Column::lookup_sload_storage_read_inv;
2424
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
25-
ColumnAndShifts::execution_contract_address,
2625
ColumnAndShifts::execution_register_0_,
2726
ColumnAndShifts::execution_register_1_,
27+
ColumnAndShifts::execution_register_2_,
2828
ColumnAndShifts::execution_prev_public_data_tree_root
2929
};
3030
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> DST_COLUMNS = {
31-
ColumnAndShifts::public_data_check_address,
3231
ColumnAndShifts::public_data_check_slot,
32+
ColumnAndShifts::public_data_check_address,
3333
ColumnAndShifts::public_data_check_value,
3434
ColumnAndShifts::public_data_check_root
3535
};

barretenberg/cpp/src/barretenberg/vm2/generated/relations/sload_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void sloadImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
2020
{ // SLOAD_FF_OUTPUT_TAG
2121
using View = typename std::tuple_element_t<0, ContainerOverSubrelations>::View;
2222
auto tmp = static_cast<View>(in.get(C::execution_sel_execute_sload)) *
23-
(CView(constants_MEM_TAG_FF) - static_cast<View>(in.get(C::execution_mem_tag_reg_1_)));
23+
(CView(constants_MEM_TAG_FF) - static_cast<View>(in.get(C::execution_mem_tag_reg_2_)));
2424
std::get<0>(evals) += (tmp * scaling_factor);
2525
}
2626
}

barretenberg/cpp/src/barretenberg/vm2/simulation/events/events_container.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "barretenberg/vm2/simulation/events/range_check_event.hpp"
2929
#include "barretenberg/vm2/simulation/events/retrieved_bytecodes_tree_check_event.hpp"
3030
#include "barretenberg/vm2/simulation/events/sha256_event.hpp"
31-
#include "barretenberg/vm2/simulation/events/siloing_event.hpp"
3231
#include "barretenberg/vm2/simulation/events/to_radix_event.hpp"
3332
#include "barretenberg/vm2/simulation/events/tx_events.hpp"
3433
#include "barretenberg/vm2/simulation/events/update_check.hpp"
@@ -48,7 +47,6 @@ struct EventsContainer {
4847
EventEmitterInterface<InstructionFetchingEvent>::Container instruction_fetching;
4948
EventEmitterInterface<AddressDerivationEvent>::Container address_derivation;
5049
EventEmitterInterface<ClassIdDerivationEvent>::Container class_id_derivation;
51-
EventEmitterInterface<SiloingEvent>::Container siloing;
5250
EventEmitterInterface<Sha256CompressionEvent>::Container sha256_compression;
5351
EventEmitterInterface<EccAddEvent>::Container ecc_add;
5452
EventEmitterInterface<ScalarMulEvent>::Container scalar_mul;

barretenberg/cpp/src/barretenberg/vm2/simulation/events/siloing_event.hpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)