From 41966fdbbaa73245e7074542846553ba7a704457 Mon Sep 17 00:00:00 2001 From: IlyasRidhuan Date: Fri, 15 Aug 2025 10:38:48 +0000 Subject: [PATCH] chore: Bump Noir reference Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE chore: restore noir libs in CI (https://github.com/noir-lang/noir/pull/9499) feat!: new semantic for bit-shifts (https://github.com/noir-lang/noir/pull/9373) fix(ssa): Replace side effects with defaults when disabled (https://github.com/noir-lang/noir/pull/9462) fix(ssa): Replace pop from 0-length slice with constraint and defaults (https://github.com/noir-lang/noir/pull/9489) fix: assert types are not mutated in constant folding (https://github.com/noir-lang/noir/pull/9481) fix: remove shadowing in `BoundedVec::any` causing returning false unconditionally (https://github.com/noir-lang/noir/pull/9478) END_COMMIT_OVERRIDE --- .../barretenberg/vm2/common/tagged_value.cpp | 16 ++---------- .../vm2/common/tagged_value.test.cpp | 7 ++--- noir-projects/aztec-nr/aztec/Nargo.toml | 2 +- .../ecdsa_k_account_contract/Nargo.toml | 2 +- .../ecdsa_r_account_contract/Nargo.toml | 2 +- .../app/card_game_contract/Nargo.toml | 2 +- .../test/avm_gadgets_test_contract/Nargo.toml | 2 +- .../test/avm_test_contract/Nargo.toml | 2 +- .../test/avm_test_contract/src/main.nr | 6 ++--- .../test/benchmarking_contract/Nargo.toml | 2 +- .../crates/blob/Nargo.toml | 4 +-- .../crates/rollup-lib/Nargo.toml | 2 +- .../crates/types/Nargo.toml | 2 +- .../crates/types/src/constants.nr | 12 ++++----- .../types/src/merkle_tree/append_only_tree.nr | 6 ++--- .../types/src/merkle_tree/indexed_tree.nr | 4 +-- .../tests/fixtures/protocol_contract_tree.nr | 2 +- noir/noir-repo-ref | 2 +- .../src/public/avm/opcodes/arithmetic.test.ts | 26 +++++++++---------- .../src/public/avm/opcodes/arithmetic.ts | 12 --------- 20 files changed, 46 insertions(+), 69 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp index 0c3ac9d7877d..6835d3280ee0 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp @@ -103,18 +103,6 @@ template struct BinaryOperationVisitor { } }; -// Helper visitor for shift operations. The right hand side is a different type. -template struct ShiftOperationVisitor { - template TaggedValue::value_type operator()(const T& a, const U& b) const - { - if constexpr (std::is_same_v || std::is_same_v) { - throw InvalidOperationTag("Bitwise operations not valid for FF"); - } else { - return static_cast(Op{}(a, b)); - } - } -}; - // Helper visitor for unary operations template struct UnaryOperationVisitor { template TaggedValue::value_type operator()(const T& a) const @@ -309,12 +297,12 @@ TaggedValue TaggedValue::operator~() const // Shift Operations TaggedValue TaggedValue::operator<<(const TaggedValue& other) const { - return std::visit(ShiftOperationVisitor(), value, other.value); + return std::visit(BinaryOperationVisitor(), value, other.value); } TaggedValue TaggedValue::operator>>(const TaggedValue& other) const { - return std::visit(ShiftOperationVisitor(), value, other.value); + return std::visit(BinaryOperationVisitor(), value, other.value); } // Comparison Operators diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.test.cpp index cdceb12596fc..442c0c822051 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.test.cpp @@ -508,25 +508,26 @@ TEST(TaggedValueTest, ErrorCases) // Test shift operations with different right-side types TEST(TaggedValueTest, ShiftOperationsWithDifferentTypes) { - auto shift_val = TaggedValue::from(3); - // Shift a uint8_t by shift_val auto u8_amount = TaggedValue::from(3); + auto shift_val = TaggedValue::from(3); auto result_shl_u8 = u8_amount << shift_val; ASSERT_EQ(result_shl_u8.get_tag(), ValueTag::U8); EXPECT_EQ(result_shl_u8.as(), 3 << 3); // Shift a uint16_t by shift_val auto u16_amount = TaggedValue::from(4); + shift_val = TaggedValue::from(3); auto result_shl_u16 = u16_amount << shift_val; ASSERT_EQ(result_shl_u16.get_tag(), ValueTag::U16); EXPECT_EQ(result_shl_u16.as(), 4 << 3); // Shift a uint32_t by shift_val auto u1_amount = TaggedValue::from(1); + shift_val = TaggedValue::from(1); auto result_shl_u1 = u1_amount << shift_val; ASSERT_EQ(result_shl_u1.get_tag(), ValueTag::U1); - EXPECT_EQ(result_shl_u1.as(), static_cast(0)); // 1 << 3 = 0 with overflow + EXPECT_EQ(result_shl_u1.as(), static_cast(0)); // 1 << 1 = 0 with overflow } // Test boundary cases for all types diff --git a/noir-projects/aztec-nr/aztec/Nargo.toml b/noir-projects/aztec-nr/aztec/Nargo.toml index 61481946259c..34c94cafe0ff 100644 --- a/noir-projects/aztec-nr/aztec/Nargo.toml +++ b/noir-projects/aztec-nr/aztec/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/Nargo.toml index 57dd9aa5c1e5..4af4e9c67873 100644 --- a/noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/account/ecdsa_k_account_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/account/ecdsa_r_account_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/account/ecdsa_r_account_contract/Nargo.toml index c5d9799c5dec..e5e06fd4bd5f 100644 --- a/noir-projects/noir-contracts/contracts/account/ecdsa_r_account_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/account/ecdsa_r_account_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/app/card_game_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/app/card_game_contract/Nargo.toml index 46a06114cf9f..a6de67c1b691 100644 --- a/noir-projects/noir-contracts/contracts/app/card_game_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/app/card_game_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/test/avm_gadgets_test_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test/avm_gadgets_test_contract/Nargo.toml index 69361082990f..72cc430d2228 100644 --- a/noir-projects/noir-contracts/contracts/test/avm_gadgets_test_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/test/avm_gadgets_test_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/test/avm_test_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test/avm_test_contract/Nargo.toml index 1936302a416d..8b405385b7dc 100644 --- a/noir-projects/noir-contracts/contracts/test/avm_test_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/test/avm_test_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-contracts/contracts/test/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test/avm_test_contract/src/main.nr index cebbd825c6bb..a0fafbd4960b 100644 --- a/noir-projects/noir-contracts/contracts/test/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test/avm_test_contract/src/main.nr @@ -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] diff --git a/noir-projects/noir-contracts/contracts/test/benchmarking_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test/benchmarking_contract/Nargo.toml index 9c3d994c7678..526ec09dbdaf 100644 --- a/noir-projects/noir-contracts/contracts/test/benchmarking_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/test/benchmarking_contract/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-protocol-circuits/crates/blob/Nargo.toml b/noir-projects/noir-protocol-circuits/crates/blob/Nargo.toml index da069bd171fb..6e7f9d55f6b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/blob/Nargo.toml +++ b/noir-projects/noir-protocol-circuits/crates/blob/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/Nargo.toml b/noir-projects/noir-protocol-circuits/crates/rollup-lib/Nargo.toml index 9f94de5d378e..3a509d230ccc 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/Nargo.toml +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-protocol-circuits/crates/types/Nargo.toml b/noir-projects/noir-protocol-circuits/crates/types/Nargo.toml index 9006050b1357..e74b39dcdc25 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/Nargo.toml +++ b/noir-projects/noir-protocol-circuits/crates/types/Nargo.toml @@ -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" } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 63d29b644e1c..97983fde5edb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -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; @@ -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; @@ -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); @@ -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, ); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr index 61f38065ef8c..51743d4f8c69 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/append_only_tree.nr @@ -12,7 +12,7 @@ pub fn insert_subtree_to_snapshot_tree( ) -> 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( @@ -31,10 +31,10 @@ pub fn insert_subtree_to_snapshot_tree( // 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, } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr index 21104c29bbf5..472e6b34a9a3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/indexed_tree.nr @@ -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, @@ -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, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/protocol_contract_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/protocol_contract_tree.nr index dad46037b529..112c7ce20278 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/protocol_contract_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/protocol_contract_tree.nr @@ -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, [ProtocolContractLeafPreimage; PROTOCOL_CONTRACT_TREE_WIDTH]) { diff --git a/noir/noir-repo-ref b/noir/noir-repo-ref index 1c76bcecbcd6..fd767581c699 100644 --- a/noir/noir-repo-ref +++ b/noir/noir-repo-ref @@ -1 +1 @@ -nightly-2025-08-13 +nightly-2025-08-15 diff --git a/yarn-project/simulator/src/public/avm/opcodes/arithmetic.test.ts b/yarn-project/simulator/src/public/avm/opcodes/arithmetic.test.ts index b9db87f7184b..ffa62b7f169d 100644 --- a/yarn-project/simulator/src/public/avm/opcodes/arithmetic.test.ts +++ b/yarn-project/simulator/src/public/avm/opcodes/arithmetic.test.ts @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/yarn-project/simulator/src/public/avm/opcodes/arithmetic.ts b/yarn-project/simulator/src/public/avm/opcodes/arithmetic.ts index 662a54de4173..47f70e44eb0f 100644 --- a/yarn-project/simulator/src/public/avm/opcodes/arithmetic.ts +++ b/yarn-project/simulator/src/public/avm/opcodes/arithmetic.ts @@ -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 { @@ -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); - } }