Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ template <typename Op> struct BinaryOperationVisitor {
}
};

// Helper visitor for shift operations. The right hand side is a different type.
template <typename Op> struct ShiftOperationVisitor {
template <typename T, typename U> TaggedValue::value_type operator()(const T& a, const U& b) const
{
if constexpr (std::is_same_v<T, FF> || std::is_same_v<U, FF>) {
throw InvalidOperationTag("Bitwise operations not valid for FF");
} else {
return static_cast<T>(Op{}(a, b));
}
}
};

// Helper visitor for unary operations
template <typename Op> struct UnaryOperationVisitor {
template <typename T> TaggedValue::value_type operator()(const T& a) const
Expand Down Expand Up @@ -309,12 +297,12 @@ TaggedValue TaggedValue::operator~() const
// Shift Operations
TaggedValue TaggedValue::operator<<(const TaggedValue& other) const
{
return std::visit(ShiftOperationVisitor<shift_left>(), value, other.value);
return std::visit(BinaryOperationVisitor<shift_left>(), value, other.value);
}

TaggedValue TaggedValue::operator>>(const TaggedValue& other) const
{
return std::visit(ShiftOperationVisitor<shift_right>(), value, other.value);
return std::visit(BinaryOperationVisitor<shift_right>(), value, other.value);
}

// Comparison Operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,26 @@ TEST(TaggedValueTest, ErrorCases)
// Test shift operations with different right-side types
TEST(TaggedValueTest, ShiftOperationsWithDifferentTypes)
{
auto shift_val = TaggedValue::from<uint8_t>(3);

// Shift a uint8_t by shift_val
auto u8_amount = TaggedValue::from<uint8_t>(3);
auto shift_val = TaggedValue::from<uint8_t>(3);
auto result_shl_u8 = u8_amount << shift_val;
ASSERT_EQ(result_shl_u8.get_tag(), ValueTag::U8);
EXPECT_EQ(result_shl_u8.as<uint8_t>(), 3 << 3);

// Shift a uint16_t by shift_val
auto u16_amount = TaggedValue::from<uint16_t>(4);
shift_val = TaggedValue::from<uint16_t>(3);
auto result_shl_u16 = u16_amount << shift_val;
ASSERT_EQ(result_shl_u16.get_tag(), ValueTag::U16);
EXPECT_EQ(result_shl_u16.as<uint16_t>(), 4 << 3);

// Shift a uint32_t by shift_val
auto u1_amount = TaggedValue::from<uint1_t>(1);
shift_val = TaggedValue::from<uint1_t>(1);
auto result_shl_u1 = u1_amount << shift_val;
ASSERT_EQ(result_shl_u1.get_tag(), ValueTag::U1);
EXPECT_EQ(result_shl_u1.as<uint1_t>(), static_cast<uint1_t>(0)); // 1 << 3 = 0 with overflow
EXPECT_EQ(result_shl_u1.as<uint1_t>(), static_cast<uint1_t>(0)); // 1 << 1 = 0 with overflow
}

// Test boundary cases for all types
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ type = "lib"

[dependencies]
protocol_types = { path = "../../noir-protocol-circuits/crates/types" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
ecdsa_public_key_note = { path = "../../libs/ecdsa_public_key_note" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
ecdsa_public_key_note = { path = "../../libs/ecdsa_public_key_note" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
value_note = { path = "../../../../aztec-nr/value-note" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
poseidon = { tag= "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
compressed_string = { path = "../../../../aztec-nr/compressed-string" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
poseidon = { tag= "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ pub contract AvmTest {
************************************************************************/
#[public]
fn set_opcode_u8() -> u8 {
8 as u8
8
}

#[public]
fn set_opcode_u32() -> u32 {
1 << 30 as u8
1 << 30
}

#[public]
fn set_opcode_u64() -> u64 {
1 << 60 as u8
1 << 60
}

#[public]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
value_note = { path = "../../../../aztec-nr/value-note" }
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
4 changes: 2 additions & 2 deletions noir-projects/noir-protocol-circuits/crates/blob/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = [""]
compiler_version = ">=0.30.0"

[dependencies]
bigint = { tag = "v0.7.5", git = "https://github.com/noir-lang/noir-bignum" }
bigcurve = { tag = "v0.10.0", git = "https://github.com/noir-lang/noir_bigcurve" }
bigint = { tag = "v0.8.0", git = "https://github.com/noir-lang/noir-bignum" }
bigcurve = { tag = "v0.11.0", git = "https://github.com/noir-lang/noir_bigcurve" }
types = { path = "../types" }
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = [""]
compiler_version = ">=0.18.0"

[dependencies]
bigint = { tag = "v0.7.5", git = "https://github.com/noir-lang/noir-bignum" }
bigint = { tag = "v0.8.0", git = "https://github.com/noir-lang/noir-bignum" }
types = { path = "../types" }
parity_lib = { path = "../parity-lib" }
blob = { path = "../blob" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = [""]
compiler_version = ">=0.18.0"

[dependencies]
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
sha256 = { git = "https://github.com/noir-lang/sha256", tag = "v0.2.0" }
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub global NOTE_HASH_TREE_ID: Field = 1;
pub global PUBLIC_DATA_TREE_ID: Field = 2;
pub global L1_TO_L2_MESSAGE_TREE_ID: Field = 3;
pub global ARCHIVE_TREE_ID: Field = 4;
pub global NOTE_HASH_TREE_LEAF_COUNT: u64 = 1 << (NOTE_HASH_TREE_HEIGHT as u8);
pub global L1_TO_L2_MSG_TREE_LEAF_COUNT: u64 = 1 << (L1_TO_L2_MSG_TREE_HEIGHT as u8);
pub global NOTE_HASH_TREE_LEAF_COUNT: u64 = 1 << (NOTE_HASH_TREE_HEIGHT as u64);
pub global L1_TO_L2_MSG_TREE_LEAF_COUNT: u64 = 1 << (L1_TO_L2_MSG_TREE_HEIGHT as u64);

// SUB-TREES RELATED CONSTANTS
pub global NOTE_HASH_SUBTREE_HEIGHT: u32 = 6;
Expand All @@ -79,8 +79,8 @@ pub global L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH: u32 =
pub global MAX_L2_TO_L1_MSG_SUBTREES_PER_TX: u32 = 3; // ceil(log2(MAX_L2_TO_L1_MSGS_PER_TX))

// "PER TRANSACTION" CONSTANTS
pub global MAX_NOTE_HASHES_PER_TX: u32 = (1 as u8 << NOTE_HASH_SUBTREE_HEIGHT as u8) as u32;
pub global MAX_NULLIFIERS_PER_TX: u32 = (1 as u8 << NULLIFIER_SUBTREE_HEIGHT as u8) as u32;
pub global MAX_NOTE_HASHES_PER_TX: u32 = 1 << NOTE_HASH_SUBTREE_HEIGHT;
pub global MAX_NULLIFIERS_PER_TX: u32 = 1 << NULLIFIER_SUBTREE_HEIGHT;
pub global MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX: u32 = 8;
pub global MAX_ENQUEUED_CALLS_PER_TX: u32 = 32;
pub global PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX: u32 = 1;
Expand Down Expand Up @@ -175,7 +175,7 @@ pub global CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE: Field =
0x0e92f9f8a534e858fcf777da206e08b0c620ecf9deb21d13479813f6;

// CANONICAL CONTRACT ADDRESSES
pub global MAX_PROTOCOL_CONTRACTS: u32 = (1 << PROTOCOL_CONTRACT_TREE_HEIGHT as u8) - 1; // Index 0 can't be used.
pub global MAX_PROTOCOL_CONTRACTS: u32 = (1 << PROTOCOL_CONTRACT_TREE_HEIGHT) - 1; // Index 0 can't be used.
pub global CANONICAL_AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(1);
pub global CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(2);
pub global CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(3);
Expand Down Expand Up @@ -1144,7 +1144,7 @@ mod test {
#[test]
unconstrained fn test_avm_written_public_data_slots_tree_height() {
assert_eq(
(1 << (AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT as u8)),
1 << AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT,
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + 1,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn insert_subtree_to_snapshot_tree<let N: u32>(
) -> AppendOnlyTreeSnapshot {
// TODO(Lasse): Sanity check len of sibling_path > height of subtree
// TODO(Lasse): Ensure height of subtree is correct (eg 3 for commitments, 1 for contracts)
let leaf_index_at_depth = snapshot.next_available_leaf_index >> (subtree_depth as u8);
let leaf_index_at_depth = snapshot.next_available_leaf_index >> (subtree_depth as u32);

// Check that the current root is correct and that there is an empty subtree at the insertion location
assert_check_membership(
Expand All @@ -31,10 +31,10 @@ pub fn insert_subtree_to_snapshot_tree<let N: u32>(

// 2^subtree_depth is the number of leaves added. 2^x = 1 << x
let new_next_available_leaf_index =
(snapshot.next_available_leaf_index as u64) + (1 << (subtree_depth as u8));
snapshot.next_available_leaf_index + (1 << (subtree_depth as u32));

AppendOnlyTreeSnapshot {
root: new_root,
next_available_leaf_index: new_next_available_leaf_index as u32,
next_available_leaf_index: new_next_available_leaf_index,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
}

let empty_subtree_root = calculate_empty_tree_root(SubtreeHeight);
let leaf_index_subtree_depth = start_insertion_index >> (SubtreeHeight as u8);
let leaf_index_subtree_depth = start_insertion_index >> SubtreeHeight;

assert_check_membership(
empty_subtree_root,
Expand All @@ -103,7 +103,7 @@ where

// Calculate the new root
// We are inserting a subtree rather than a full tree here
let subtree_index = start_insertion_index >> (SubtreeHeight as u8);
let subtree_index = start_insertion_index >> SubtreeHeight;
let new_root = root_from_sibling_path(
subtree_root,
subtree_index as Field,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
utils::arrays::get_sorted_tuple::get_sorted_tuple,
};

global PROTOCOL_CONTRACT_TREE_WIDTH: u32 = 1 << PROTOCOL_CONTRACT_TREE_HEIGHT as u8;
global PROTOCOL_CONTRACT_TREE_WIDTH: u32 = 1 << PROTOCOL_CONTRACT_TREE_HEIGHT;
global NUM_PROTOCOL_CONTRACTS_FOR_TESTING: u32 = 3;

pub fn get_protocol_contract_tree() -> (MerkleTree<PROTOCOL_CONTRACT_TREE_WIDTH>, [ProtocolContractLeafPreimage; PROTOCOL_CONTRACT_TREE_WIDTH]) {
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo-ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2025-08-13
nightly-2025-08-15
26 changes: 13 additions & 13 deletions yarn-project/simulator/src/public/avm/opcodes/arithmetic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,21 @@ describe('Arithmetic Instructions', () => {
expect(inst.toBuffer()).toEqual(buf);
});

it('Should require shift amount to be U8', async () => {
it('Should require shift amount to be the same type as the LHS', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint32(0n);
const b = new Uint8(0n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);

await expect(
async () => await new Shr(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).execute(context),
).rejects.toThrow(/got UINT32, expected UINT8/);
).rejects.toThrow(/got UINT8, expected UINT32/);
});

it('Should shift correctly 0 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint8(0n);
const b = new Uint32(0n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand All @@ -327,7 +327,7 @@ describe('Arithmetic Instructions', () => {

it('Should shift correctly 2 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint8(2n);
const b = new Uint32(2n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand All @@ -341,7 +341,7 @@ describe('Arithmetic Instructions', () => {

it('Should shift correctly 19 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint8(19n);
const b = new Uint32(19n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand Down Expand Up @@ -372,21 +372,21 @@ describe('Arithmetic Instructions', () => {
expect(inst.toBuffer()).toEqual(buf);
});

it('Should require shift amount to be U8', async () => {
it('Should require shift amount to be the same type as the LHS', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint32(0n);
const b = new Uint8(0n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);

await expect(
async () => await new Shl(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).execute(context),
).rejects.toThrow(/got UINT32, expected UINT8/);
).rejects.toThrow(/got UINT8, expected UINT32/);
});

it('Should shift correctly 0 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint8(0n);
const b = new Uint32(0n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand All @@ -400,7 +400,7 @@ describe('Arithmetic Instructions', () => {

it('Should shift correctly 2 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint8(2n);
const b = new Uint32(2n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand All @@ -414,7 +414,7 @@ describe('Arithmetic Instructions', () => {

it('Should shift correctly over bit limit over integral types', async () => {
const a = new Uint16(0b1110010011100111n);
const b = new Uint8(17n);
const b = new Uint16(17n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand All @@ -428,7 +428,7 @@ describe('Arithmetic Instructions', () => {

it('Should truncate when shifting over bit size over integral types', async () => {
const a = new Uint16(0b1110010011100111n);
const b = new Uint8(2n);
const b = new Uint16(2n);

context.machineState.memory.set(0, a);
context.machineState.memory.set(1, b);
Expand Down
12 changes: 0 additions & 12 deletions yarn-project/simulator/src/public/avm/opcodes/arithmetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ export class Shl extends ThreeOperandArithmeticInstruction {
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
return a.shl(b);
}

// This override can be removed once Shifts are required to have the same tag on both operands.
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset));
memory.checkTag(TypeTag.UINT8, bOffset);
}
}

export class Shr extends ThreeOperandArithmeticInstruction {
Expand All @@ -120,10 +114,4 @@ export class Shr extends ThreeOperandArithmeticInstruction {
protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
return a.shr(b);
}

// This override can be removed once Shifts are required to have the same tag on both operands.
protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset));
memory.checkTag(TypeTag.UINT8, bOffset);
}
}
Loading