Skip to content

Commit ceda361

Browse files
feat!: Add Not instruction in brillig (#8488)
The AVM supports Not. We add it in brillig to avoid having to codegen it with two operations. <details> <summary>Brillig opcode count changes</summary> ``` contracts: Transpiling AppSubscription::constructor with size 1969 => 1964 contracts: Transpiling Auth::constructor with size 1557 => 1552 contracts: Transpiling Auth::get_authorized with size 128 => 127 contracts: Transpiling Auth::get_authorized_delay with size 175 => 174 contracts: Transpiling Auth::get_scheduled_authorized with size 107 => 106 contracts: Transpiling Auth::set_authorized with size 857 => 856 contracts: Transpiling Auth::set_authorized_delay with size 826 => 825 contracts: Transpiling AuthRegistry::_set_authorized with size 86 => 86 contracts: Transpiling AuthRegistry::consume with size 522 => 521 contracts: Transpiling AuthRegistry::is_consumable with size 123 => 122 contracts: Transpiling AuthRegistry::is_reject_all with size 106 => 105 contracts: Transpiling AuthRegistry::set_authorized with size 81 => 81 contracts: Transpiling AuthRegistry::set_reject_all with size 64 => 64 contracts: Transpiling AuthWitTest::consume_public with size 77 => 77 contracts: Transpiling AvmInitializerTest::constructor with size 1553 => 1548 contracts: Transpiling AvmInitializerTest::read_storage_immutable with size 89 => 88 contracts: Transpiling AvmTest::add_args_return with size 17 => 17 contracts: Transpiling AvmTest::add_storage_map with size 182 => 181 contracts: Transpiling AvmTest::add_u128 with size 34 => 34 contracts: Transpiling AvmTest::assert_nullifier_exists with size 18 => 18 contracts: Transpiling AvmTest::assert_same with size 20 => 20 contracts: Transpiling AvmTest::assert_timestamp with size 17 => 17 contracts: Transpiling AvmTest::assertion_failure with size 16 => 16 contracts: Transpiling AvmTest::check_selector with size 16 => 16 contracts: Transpiling AvmTest::create_different_nullifier_in_nested_call with size 121 => 120 contracts: Transpiling AvmTest::create_same_nullifier_in_nested_call with size 119 => 118 contracts: Transpiling AvmTest::debug_logging with size 282 => 282 contracts: Transpiling AvmTest::elliptic_curve_add_and_double with size 23 => 23 contracts: Transpiling AvmTest::emit_nullifier_and_check with size 19 => 19 contracts: Transpiling AvmTest::emit_unencrypted_log with size 524 => 520 contracts: Transpiling AvmTest::get_address with size 15 => 15 contracts: Transpiling AvmTest::get_args_hash with size 1046 => 1041 contracts: Transpiling AvmTest::get_block_number with size 15 => 15 contracts: Transpiling AvmTest::get_chain_id with size 15 => 15 contracts: Transpiling AvmTest::get_da_gas_left with size 15 => 15 contracts: Transpiling AvmTest::get_fee_per_da_gas with size 15 => 15 contracts: Transpiling AvmTest::get_fee_per_l2_gas with size 15 => 15 contracts: Transpiling AvmTest::get_function_selector with size 15 => 15 contracts: Transpiling AvmTest::get_l2_gas_left with size 15 => 15 contracts: Transpiling AvmTest::get_sender with size 15 => 15 contracts: Transpiling AvmTest::get_storage_address with size 15 => 15 contracts: Transpiling AvmTest::get_timestamp with size 15 => 15 contracts: Transpiling AvmTest::get_transaction_fee with size 15 => 15 contracts: Transpiling AvmTest::get_version with size 15 => 15 contracts: Transpiling AvmTest::keccak_f1600 with size 77 => 76 contracts: Transpiling AvmTest::keccak_hash with size 708 => 703 contracts: Transpiling AvmTest::l1_to_l2_msg_exists with size 19 => 19 contracts: Transpiling AvmTest::modulo2 with size 18 => 18 contracts: Transpiling AvmTest::nested_call_to_add with size 196 => 195 contracts: Transpiling AvmTest::nested_call_to_add_with_gas with size 204 => 203 contracts: Transpiling AvmTest::nested_static_call_to_add with size 196 => 195 contracts: Transpiling AvmTest::nested_static_call_to_set_storage with size 118 => 117 contracts: Transpiling AvmTest::new_note_hash with size 13 => 13 contracts: Transpiling AvmTest::new_nullifier with size 13 => 13 contracts: Transpiling AvmTest::note_hash_exists with size 19 => 19 contracts: Transpiling AvmTest::nullifier_collision with size 14 => 14 contracts: Transpiling AvmTest::nullifier_exists with size 19 => 19 contracts: Transpiling AvmTest::pedersen_commit with size 73 => 73 contracts: Transpiling AvmTest::pedersen_hash with size 42 => 41 contracts: Transpiling AvmTest::pedersen_hash_with_index with size 42 => 41 contracts: Transpiling AvmTest::poseidon2_hash with size 306 => 304 contracts: Transpiling AvmTest::read_storage_list with size 115 => 113 contracts: Transpiling AvmTest::read_storage_map with size 103 => 102 contracts: Transpiling AvmTest::read_storage_single with size 82 => 81 contracts: Transpiling AvmTest::send_l2_to_l1_msg with size 14 => 14 contracts: Transpiling AvmTest::set_opcode_big_field with size 15 => 15 contracts: Transpiling AvmTest::set_opcode_really_big_field with size 15 => 15 contracts: Transpiling AvmTest::set_opcode_small_field with size 15 => 15 contracts: Transpiling AvmTest::set_opcode_u32 with size 15 => 15 contracts: Transpiling AvmTest::set_opcode_u64 with size 15 => 15 contracts: Transpiling AvmTest::set_opcode_u8 with size 15 => 15 contracts: Transpiling AvmTest::set_read_storage_single with size 128 => 127 contracts: Transpiling AvmTest::set_storage_list with size 47 => 47 contracts: Transpiling AvmTest::set_storage_map with size 79 => 79 contracts: Transpiling AvmTest::set_storage_single with size 43 => 43 contracts: Transpiling AvmTest::sha256_hash with size 62 => 61 contracts: Transpiling AvmTest::test_get_contract_instance with size 178 => 177 contracts: Transpiling AvmTest::test_get_contract_instance_raw with size 69 => 69 contracts: Transpiling AvmTest::to_radix_le with size 40 => 39 contracts: Transpiling AvmTest::u128_addition_overflow with size 275 => 271 contracts: Transpiling AvmTest::u128_from_integer_overflow with size 140 => 140 contracts: Transpiling AvmTest::variable_base_msm with size 84 => 84 contracts: Transpiling Benchmarking::broadcast with size 113 => 112 contracts: Transpiling Benchmarking::increment_balance with size 263 => 261 contracts: Transpiling CardGame::on_card_played with size 882 => 880 contracts: Transpiling CardGame::on_cards_claimed with size 745 => 743 contracts: Transpiling CardGame::on_game_joined with size 676 => 672 contracts: Transpiling CardGame::start_game with size 1150 => 1148 contracts: Transpiling Child::pub_get_value with size 24 => 24 contracts: Transpiling Child::pub_inc_value with size 145 => 144 contracts: Transpiling Child::pub_inc_value_internal with size 150 => 149 contracts: Transpiling Child::pub_set_value with size 62 => 62 contracts: Transpiling Child::set_value_twice_with_nested_first with size 182 => 181 contracts: Transpiling Child::set_value_twice_with_nested_last with size 182 => 181 contracts: Transpiling Child::set_value_with_two_nested_calls with size 129 => 129 contracts: Transpiling Claim::constructor with size 1657 => 1652 contracts: Transpiling Crowdfunding::_publish_donation_receipts with size 153 => 151 contracts: Transpiling Crowdfunding::init with size 1763 => 1758 contracts: Transpiling DelegatedOn::public_set_value with size 46 => 46 contracts: Transpiling Delegator::public_delegate_set_value with size 94 => 93 contracts: Transpiling DocsExample::get_shared_immutable_constrained_public with size 97 => 96 contracts: Transpiling DocsExample::get_shared_immutable_constrained_public_indirect with size 86 => 86 contracts: Transpiling DocsExample::get_shared_immutable_constrained_public_multiple with size 134 => 132 contracts: Transpiling DocsExample::initialize_public_immutable with size 164 => 163 contracts: Transpiling DocsExample::initialize_shared_immutable with size 164 => 163 contracts: Transpiling DocsExample::spend_public_authwit with size 16 => 16 contracts: Transpiling DocsExample::update_leader with size 54 => 54 contracts: Transpiling EasyPrivateVoting::add_to_tally_public with size 220 => 219 contracts: Transpiling EasyPrivateVoting::constructor with size 1614 => 1609 contracts: Transpiling EasyPrivateVoting::end_vote with size 136 => 135 contracts: Transpiling FeeJuice::_increase_public_balance with size 196 => 195 contracts: Transpiling FeeJuice::balance_of_public with size 115 => 114 contracts: Transpiling FeeJuice::check_balance with size 168 => 167 contracts: Transpiling FeeJuice::set_portal with size 208 => 207 contracts: Transpiling FPC::constructor with size 1553 => 1548 contracts: Transpiling FPC::pay_refund with size 387 => 384 contracts: Transpiling FPC::pay_refund_with_shielded_rebate with size 387 => 384 contracts: Transpiling FPC::prepare_fee with size 291 => 290 contracts: Transpiling ImportTest::pub_call_public_fn with size 118 => 117 contracts: Transpiling InclusionProofs::constructor with size 1479 => 1474 contracts: Transpiling InclusionProofs::push_nullifier_public with size 20 => 20 contracts: Transpiling InclusionProofs::test_nullifier_inclusion_from_public with size 24 => 24 contracts: Transpiling KeyRegistry::register_initial_keys with size 1066 => 1056 contracts: Transpiling KeyRegistry::rotate_npk_m with size 1954 => 1941 contracts: Transpiling Lending::_borrow with size 2276 => 2273 contracts: Transpiling Lending::_deposit with size 221 => 220 contracts: Transpiling Lending::_repay with size 1358 => 1356 contracts: Transpiling Lending::_withdraw with size 2299 => 2296 contracts: Transpiling Lending::borrow_public with size 232 => 231 contracts: Transpiling Lending::deposit_public with size 501 => 500 contracts: Transpiling Lending::get_asset with size 158 => 157 contracts: Transpiling Lending::get_assets with size 179 => 177 contracts: Transpiling Lending::get_position with size 848 => 846 contracts: Transpiling Lending::init with size 300 => 299 contracts: Transpiling Lending::repay_public with size 447 => 446 contracts: Transpiling Lending::update_accumulator with size 2423 => 2419 contracts: Transpiling Lending::withdraw_public with size 232 => 231 contracts: Transpiling Parent::pub_entry_point with size 75 => 75 contracts: Transpiling Parent::pub_entry_point_twice with size 127 => 127 contracts: Transpiling Parent::public_nested_static_call with size 969 => 964 contracts: Transpiling Parent::public_static_call with size 102 => 101 contracts: Transpiling PriceFeed::get_price with size 112 => 111 contracts: Transpiling PriceFeed::set_price with size 75 => 75 contracts: Transpiling PrivateFPC::constructor with size 1556 => 1551 contracts: Transpiling Router::_check_block_number with size 163 => 157 contracts: Transpiling Router::_check_timestamp with size 166 => 160 contracts: Transpiling StatefulTest::get_public_value with size 103 => 102 contracts: Transpiling StatefulTest::increment_public_value with size 134 => 133 contracts: Transpiling StatefulTest::increment_public_value_no_init_check with size 127 => 126 contracts: Transpiling StatefulTest::public_constructor with size 1597 => 1592 contracts: Transpiling StaticChild::pub_get_value with size 27 => 27 contracts: Transpiling StaticChild::pub_illegal_inc_value with size 148 => 147 contracts: Transpiling StaticChild::pub_inc_value with size 145 => 144 contracts: Transpiling StaticChild::pub_set_value with size 62 => 62 contracts: Transpiling StaticParent::public_call with size 75 => 75 contracts: Transpiling StaticParent::public_get_value_from_child with size 142 => 141 contracts: Transpiling StaticParent::public_nested_static_call with size 266 => 265 contracts: Transpiling StaticParent::public_static_call with size 102 => 101 contracts: Transpiling Test::assert_public_global_vars with size 42 => 42 contracts: Transpiling Test::consume_message_from_arbitrary_sender_public with size 923 => 920 contracts: Transpiling Test::consume_mint_public_message with size 1145 => 1141 contracts: Transpiling Test::create_l2_to_l1_message_arbitrary_recipient_public with size 14 => 14 contracts: Transpiling Test::create_l2_to_l1_message_public with size 28 => 28 contracts: Transpiling Test::dummy_public_call with size 16 => 16 contracts: Transpiling Test::emit_nullifier_public with size 13 => 13 contracts: Transpiling Test::emit_unencrypted with size 255 => 252 contracts: Transpiling Test::is_time_equal with size 20 => 20 contracts: Transpiling TestLog::emit_unencrypted_events with size 251 => 249 contracts: Transpiling Token::_increase_public_balance with size 187 => 186 contracts: Transpiling Token::_reduce_total_supply with size 171 => 170 contracts: Transpiling Token::admin with size 92 => 91 contracts: Transpiling Token::assert_minter_and_mint with size 236 => 235 contracts: Transpiling Token::balance_of_public with size 122 => 121 contracts: Transpiling Token::burn_public with size 1618 => 1612 contracts: Transpiling Token::complete_refund with size 440 => 440 contracts: Transpiling Token::constructor with size 2016 => 2011 contracts: Transpiling Token::is_minter with size 113 => 112 contracts: Transpiling Token::mint_private with size 509 => 508 contracts: Transpiling Token::mint_public with size 358 => 357 contracts: Transpiling Token::public_get_decimals with size 95 => 94 contracts: Transpiling Token::public_get_name with size 92 => 91 contracts: Transpiling Token::public_get_symbol with size 92 => 91 contracts: Transpiling Token::set_admin with size 136 => 135 contracts: Transpiling Token::set_minter with size 156 => 155 contracts: Transpiling Token::shield with size 1800 => 1794 contracts: Transpiling Token::total_supply with size 104 => 103 contracts: Transpiling Token::transfer_public with size 1633 => 1627 contracts: Transpiling TokenBlacklist::_increase_public_balance with size 187 => 186 contracts: Transpiling TokenBlacklist::_reduce_total_supply with size 171 => 170 contracts: Transpiling TokenBlacklist::balance_of_public with size 122 => 121 contracts: Transpiling TokenBlacklist::burn_public with size 1754 => 1747 contracts: Transpiling TokenBlacklist::constructor with size 2308 => 2303 contracts: Transpiling TokenBlacklist::get_roles with size 179 => 178 contracts: Transpiling TokenBlacklist::mint_private with size 568 => 567 contracts: Transpiling TokenBlacklist::mint_public with size 537 => 536 contracts: Transpiling TokenBlacklist::shield with size 1936 => 1929 contracts: Transpiling TokenBlacklist::total_supply with size 104 => 103 contracts: Transpiling TokenBlacklist::transfer_public with size 1904 => 1897 contracts: Transpiling TokenBlacklist::update_roles with size 1074 => 1073 contracts: Transpiling TokenBridge::_assert_token_is_same with size 95 => 94 contracts: Transpiling TokenBridge::_call_mint_on_token with size 248 => 246 contracts: Transpiling TokenBridge::claim_public with size 1397 => 1392 contracts: Transpiling TokenBridge::constructor with size 1583 => 1578 contracts: Transpiling TokenBridge::exit_to_l1_public with size 810 => 807 contracts: Transpiling TokenBridge::get_portal_address_public with size 94 => 93 contracts: Transpiling TokenBridge::get_token with size 92 => 91 contracts: Transpiling Uniswap::_approve_bridge_and_exit_input_asset_to_L1 with size 2612 => 2604 contracts: Transpiling Uniswap::_assert_token_is_same with size 87 => 87 contracts: Transpiling Uniswap::constructor with size 1553 => 1548 contracts: Transpiling Uniswap::swap_public with size 3005 => 2998 contracts: Transpiling contracts... ``` </details> --------- Co-authored-by: fcarreiro <facundo@aztecprotocol.com>
1 parent 5f97351 commit ceda361

File tree

10 files changed

+292
-46
lines changed

10 files changed

+292
-46
lines changed

avm-transpiler/src/transpile.rs

+35-3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,39 @@ pub fn brillig_to_avm(
179179
],
180180
});
181181
}
182+
BrilligOpcode::Not { destination, source, bit_size } => {
183+
assert!(
184+
is_integral_bit_size(*bit_size),
185+
"Not bit size should be integral: {:?}",
186+
brillig_instr
187+
);
188+
let bits_needed =
189+
[source.0, destination.0].iter().map(bits_needed_for).max().unwrap();
190+
assert!(
191+
bits_needed == 8 || bits_needed == 16,
192+
"Not only support 8 or 16 bit encodings, got: {}",
193+
bits_needed
194+
);
195+
196+
avm_instrs.push(AvmInstruction {
197+
opcode: if bits_needed == 8 { AvmOpcode::NOT_8 } else { AvmOpcode::NOT_16 },
198+
indirect: Some(ALL_DIRECT),
199+
operands: vec![
200+
make_operand(bits_needed, &source.0),
201+
make_operand(bits_needed, &destination.0),
202+
],
203+
tag: Some(tag_from_bit_size(BitSize::Integer(*bit_size))),
204+
});
205+
if let IntegerBitSize::U1 = bit_size {
206+
// We need to cast the result back to u1
207+
handle_cast(
208+
&mut avm_instrs,
209+
destination,
210+
destination,
211+
BitSize::Integer(IntegerBitSize::U1),
212+
);
213+
}
214+
}
182215
BrilligOpcode::CalldataCopy { destination_address, size_address, offset_address } => {
183216
avm_instrs.push(AvmInstruction {
184217
opcode: AvmOpcode::CALLDATACOPY,
@@ -493,8 +526,6 @@ fn handle_cast(
493526
AvmOperand::U32 { value: /*limbs=*/ 1},
494527
],
495528
},
496-
// Then we cast back to u8 (which is what we use for u1).
497-
generate_cast_instruction(dest_offset, false, dest_offset, false, AvmTypeTag::UINT8),
498529
]);
499530
} else {
500531
let tag = tag_from_bit_size(bit_size);
@@ -1282,7 +1313,8 @@ pub fn map_brillig_pcs_to_avm_pcs(brillig_bytecode: &[BrilligOpcode<FieldElement
12821313
pc_map[0] = 0; // first PC is always 0 as there are no instructions inserted by AVM at start
12831314
for i in 0..brillig_bytecode.len() - 1 {
12841315
let num_avm_instrs_for_this_brillig_instr = match &brillig_bytecode[i] {
1285-
BrilligOpcode::Cast { bit_size: BitSize::Integer(IntegerBitSize::U1), .. } => 3,
1316+
BrilligOpcode::Cast { bit_size: BitSize::Integer(IntegerBitSize::U1), .. } => 2,
1317+
BrilligOpcode::Not { bit_size: IntegerBitSize::U1, .. } => 3,
12861318
_ => 1,
12871319
};
12881320
// next Brillig pc will map to an AVM pc offset by the

barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp

+67
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,16 @@ struct BrilligOpcode {
594594
static BinaryIntOp bincodeDeserialize(std::vector<uint8_t>);
595595
};
596596

597+
struct Not {
598+
Program::MemoryAddress destination;
599+
Program::MemoryAddress source;
600+
Program::IntegerBitSize bit_size;
601+
602+
friend bool operator==(const Not&, const Not&);
603+
std::vector<uint8_t> bincodeSerialize() const;
604+
static Not bincodeDeserialize(std::vector<uint8_t>);
605+
};
606+
597607
struct Cast {
598608
Program::MemoryAddress destination;
599609
Program::MemoryAddress source;
@@ -751,6 +761,7 @@ struct BrilligOpcode {
751761

752762
std::variant<BinaryFieldOp,
753763
BinaryIntOp,
764+
Not,
754765
Cast,
755766
JumpIfNot,
756767
JumpIf,
@@ -6107,6 +6118,62 @@ Program::BrilligOpcode::BinaryIntOp serde::Deserializable<Program::BrilligOpcode
61076118

61086119
namespace Program {
61096120

6121+
inline bool operator==(const BrilligOpcode::Not& lhs, const BrilligOpcode::Not& rhs)
6122+
{
6123+
if (!(lhs.destination == rhs.destination)) {
6124+
return false;
6125+
}
6126+
if (!(lhs.source == rhs.source)) {
6127+
return false;
6128+
}
6129+
if (!(lhs.bit_size == rhs.bit_size)) {
6130+
return false;
6131+
}
6132+
return true;
6133+
}
6134+
6135+
inline std::vector<uint8_t> BrilligOpcode::Not::bincodeSerialize() const
6136+
{
6137+
auto serializer = serde::BincodeSerializer();
6138+
serde::Serializable<BrilligOpcode::Not>::serialize(*this, serializer);
6139+
return std::move(serializer).bytes();
6140+
}
6141+
6142+
inline BrilligOpcode::Not BrilligOpcode::Not::bincodeDeserialize(std::vector<uint8_t> input)
6143+
{
6144+
auto deserializer = serde::BincodeDeserializer(input);
6145+
auto value = serde::Deserializable<BrilligOpcode::Not>::deserialize(deserializer);
6146+
if (deserializer.get_buffer_offset() < input.size()) {
6147+
throw_or_abort("Some input bytes were not read");
6148+
}
6149+
return value;
6150+
}
6151+
6152+
} // end of namespace Program
6153+
6154+
template <>
6155+
template <typename Serializer>
6156+
void serde::Serializable<Program::BrilligOpcode::Not>::serialize(const Program::BrilligOpcode::Not& obj,
6157+
Serializer& serializer)
6158+
{
6159+
serde::Serializable<decltype(obj.destination)>::serialize(obj.destination, serializer);
6160+
serde::Serializable<decltype(obj.source)>::serialize(obj.source, serializer);
6161+
serde::Serializable<decltype(obj.bit_size)>::serialize(obj.bit_size, serializer);
6162+
}
6163+
6164+
template <>
6165+
template <typename Deserializer>
6166+
Program::BrilligOpcode::Not serde::Deserializable<Program::BrilligOpcode::Not>::deserialize(Deserializer& deserializer)
6167+
{
6168+
Program::BrilligOpcode::Not obj;
6169+
obj.destination = serde::Deserializable<decltype(obj.destination)>::deserialize(deserializer);
6170+
obj.source = serde::Deserializable<decltype(obj.source)>::deserialize(deserializer);
6171+
obj.bit_size = serde::Deserializable<decltype(obj.bit_size)>::deserialize(deserializer);
6172+
return obj;
6173+
}
6174+
6175+
namespace Program {
6176+
61106177
inline bool operator==(const BrilligOpcode::Cast& lhs, const BrilligOpcode::Cast& rhs)
61116178
{
61126179
if (!(lhs.destination == rhs.destination)) {

noir/noir-repo/acvm-repo/acir/codegen/acir.cpp

+55-1
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,16 @@ namespace Program {
572572
static BinaryIntOp bincodeDeserialize(std::vector<uint8_t>);
573573
};
574574

575+
struct Not {
576+
Program::MemoryAddress destination;
577+
Program::MemoryAddress source;
578+
Program::IntegerBitSize bit_size;
579+
580+
friend bool operator==(const Not&, const Not&);
581+
std::vector<uint8_t> bincodeSerialize() const;
582+
static Not bincodeDeserialize(std::vector<uint8_t>);
583+
};
584+
575585
struct Cast {
576586
Program::MemoryAddress destination;
577587
Program::MemoryAddress source;
@@ -727,7 +737,7 @@ namespace Program {
727737
static Stop bincodeDeserialize(std::vector<uint8_t>);
728738
};
729739

730-
std::variant<BinaryFieldOp, BinaryIntOp, Cast, JumpIfNot, JumpIf, Jump, CalldataCopy, Call, Const, IndirectConst, Return, ForeignCall, Mov, ConditionalMov, Load, Store, BlackBox, Trap, Stop> value;
740+
std::variant<BinaryFieldOp, BinaryIntOp, Not, Cast, JumpIfNot, JumpIf, Jump, CalldataCopy, Call, Const, IndirectConst, Return, ForeignCall, Mov, ConditionalMov, Load, Store, BlackBox, Trap, Stop> value;
731741

732742
friend bool operator==(const BrilligOpcode&, const BrilligOpcode&);
733743
std::vector<uint8_t> bincodeSerialize() const;
@@ -5110,6 +5120,50 @@ Program::BrilligOpcode::BinaryIntOp serde::Deserializable<Program::BrilligOpcode
51105120
return obj;
51115121
}
51125122

5123+
namespace Program {
5124+
5125+
inline bool operator==(const BrilligOpcode::Not &lhs, const BrilligOpcode::Not &rhs) {
5126+
if (!(lhs.destination == rhs.destination)) { return false; }
5127+
if (!(lhs.source == rhs.source)) { return false; }
5128+
if (!(lhs.bit_size == rhs.bit_size)) { return false; }
5129+
return true;
5130+
}
5131+
5132+
inline std::vector<uint8_t> BrilligOpcode::Not::bincodeSerialize() const {
5133+
auto serializer = serde::BincodeSerializer();
5134+
serde::Serializable<BrilligOpcode::Not>::serialize(*this, serializer);
5135+
return std::move(serializer).bytes();
5136+
}
5137+
5138+
inline BrilligOpcode::Not BrilligOpcode::Not::bincodeDeserialize(std::vector<uint8_t> input) {
5139+
auto deserializer = serde::BincodeDeserializer(input);
5140+
auto value = serde::Deserializable<BrilligOpcode::Not>::deserialize(deserializer);
5141+
if (deserializer.get_buffer_offset() < input.size()) {
5142+
throw serde::deserialization_error("Some input bytes were not read");
5143+
}
5144+
return value;
5145+
}
5146+
5147+
} // end of namespace Program
5148+
5149+
template <>
5150+
template <typename Serializer>
5151+
void serde::Serializable<Program::BrilligOpcode::Not>::serialize(const Program::BrilligOpcode::Not &obj, Serializer &serializer) {
5152+
serde::Serializable<decltype(obj.destination)>::serialize(obj.destination, serializer);
5153+
serde::Serializable<decltype(obj.source)>::serialize(obj.source, serializer);
5154+
serde::Serializable<decltype(obj.bit_size)>::serialize(obj.bit_size, serializer);
5155+
}
5156+
5157+
template <>
5158+
template <typename Deserializer>
5159+
Program::BrilligOpcode::Not serde::Deserializable<Program::BrilligOpcode::Not>::deserialize(Deserializer &deserializer) {
5160+
Program::BrilligOpcode::Not obj;
5161+
obj.destination = serde::Deserializable<decltype(obj.destination)>::deserialize(deserializer);
5162+
obj.source = serde::Deserializable<decltype(obj.source)>::deserialize(deserializer);
5163+
obj.bit_size = serde::Deserializable<decltype(obj.bit_size)>::deserialize(deserializer);
5164+
return obj;
5165+
}
5166+
51135167
namespace Program {
51145168

51155169
inline bool operator==(const BrilligOpcode::Cast &lhs, const BrilligOpcode::Cast &rhs) {

noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ fn simple_brillig_foreign_call() {
214214
let bytes = Program::serialize_program(&program);
215215

216216
let expected_serialization: Vec<u8> = vec![
217-
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 49, 10, 128, 48, 12, 108, 196, 138, 224, 230,
218-
75, 226, 15, 252, 140, 131, 139, 131, 136, 239, 111, 161, 9, 28, 165, 205, 210, 28, 132,
219-
36, 119, 16, 114, 9, 133, 130, 53, 7, 73, 29, 37, 107, 143, 80, 238, 148, 204, 99, 56, 200,
220-
111, 22, 227, 190, 83, 93, 16, 146, 193, 112, 22, 225, 34, 168, 205, 142, 174, 241, 218,
221-
206, 179, 121, 49, 188, 109, 57, 84, 191, 159, 255, 122, 63, 235, 199, 189, 190, 197, 237,
222-
13, 45, 1, 20, 245, 146, 30, 92, 2, 0, 0,
217+
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 73, 10, 192, 48, 8, 140, 165, 91, 160, 183,
218+
126, 196, 254, 160, 159, 233, 161, 151, 30, 74, 200, 251, 19, 136, 130, 132, 196, 75, 28,
219+
16, 199, 17, 212, 65, 112, 5, 123, 14, 32, 190, 80, 230, 90, 130, 181, 155, 50, 142, 225,
220+
2, 187, 89, 40, 239, 157, 106, 2, 82, 116, 138, 51, 118, 239, 171, 222, 108, 232, 218, 139,
221+
125, 198, 179, 113, 83, 188, 29, 57, 86, 226, 239, 23, 159, 63, 104, 63, 238, 213, 45, 237,
222+
108, 244, 18, 195, 174, 252, 193, 92, 2, 0, 0,
223223
];
224224

225225
assert_eq!(bytes, expected_serialization)
@@ -338,17 +338,17 @@ fn complex_brillig_foreign_call() {
338338

339339
let bytes = Program::serialize_program(&program);
340340
let expected_serialization: Vec<u8> = vec![
341-
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 206, 26, 255, 60,
342-
129, 137, 30, 160, 211, 11, 120, 23, 227, 159, 70, 63, 61, 190, 146, 209, 140, 177, 46,
343-
251, 24, 77, 182, 151, 44, 116, 45, 16, 120, 64, 139, 208, 34, 252, 63, 228, 245, 134, 165,
344-
99, 73, 251, 30, 250, 72, 186, 55, 150, 113, 30, 26, 180, 243, 21, 75, 197, 232, 86, 16,
345-
163, 47, 16, 35, 136, 250, 47, 176, 222, 150, 117, 49, 229, 207, 103, 230, 167, 130, 118,
346-
190, 106, 254, 223, 178, 12, 154, 104, 50, 114, 48, 28, 188, 30, 82, 247, 236, 180, 23, 62,
347-
171, 236, 178, 185, 202, 27, 194, 216, 119, 36, 54, 142, 35, 185, 149, 203, 233, 18, 131,
348-
34, 220, 48, 167, 38, 176, 191, 18, 181, 168, 5, 63, 178, 179, 8, 123, 232, 186, 234, 254,
349-
126, 125, 158, 143, 175, 87, 148, 74, 51, 194, 73, 172, 207, 234, 28, 149, 157, 182, 149,
350-
144, 15, 70, 78, 23, 51, 122, 83, 190, 15, 208, 181, 70, 122, 152, 126, 56, 83, 244, 10,
351-
181, 6, 0, 0,
341+
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 186, 53, 241,
342+
207, 11, 152, 232, 1, 58, 189, 128, 119, 49, 254, 105, 244, 211, 227, 59, 50, 154, 49, 214,
343+
100, 31, 163, 201, 246, 146, 133, 174, 5, 10, 15, 72, 17, 122, 52, 221, 135, 188, 222, 177,
344+
116, 44, 105, 223, 195, 24, 73, 247, 206, 50, 46, 67, 139, 118, 190, 98, 169, 24, 221, 6,
345+
98, 244, 5, 98, 4, 81, 255, 21, 214, 219, 178, 46, 166, 252, 249, 204, 252, 84, 208, 207,
346+
215, 158, 255, 107, 150, 141, 38, 154, 140, 28, 76, 7, 111, 132, 212, 61, 65, 201, 116, 86,
347+
217, 101, 115, 11, 226, 62, 99, 223, 145, 88, 56, 205, 228, 102, 127, 239, 53, 6, 69, 184,
348+
97, 78, 109, 96, 127, 37, 106, 81, 11, 126, 100, 103, 17, 14, 48, 116, 213, 227, 243, 254,
349+
190, 158, 63, 175, 40, 149, 102, 132, 179, 88, 95, 212, 57, 42, 59, 109, 43, 33, 31, 140,
350+
156, 46, 102, 244, 230, 124, 31, 97, 104, 141, 244, 48, 253, 1, 180, 46, 168, 159, 181, 6,
351+
0, 0,
352352
];
353353

354354
assert_eq!(bytes, expected_serialization)

noir/noir-repo/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { WitnessMap } from '@noir-lang/acvm_js';
22

33
// See `complex_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`.
44
export const bytecode = Uint8Array.from([
5-
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 206, 26, 255, 60, 129, 137, 30, 160, 211,
6-
11, 120, 23, 227, 159, 70, 63, 61, 190, 146, 209, 140, 177, 46, 251, 24, 77, 182, 151, 44, 116, 45, 16, 120, 64, 139,
7-
208, 34, 252, 63, 228, 245, 134, 165, 99, 73, 251, 30, 250, 72, 186, 55, 150, 113, 30, 26, 180, 243, 21, 75, 197, 232,
8-
86, 16, 163, 47, 16, 35, 136, 250, 47, 176, 222, 150, 117, 49, 229, 207, 103, 230, 167, 130, 118, 190, 106, 254, 223,
9-
178, 12, 154, 104, 50, 114, 48, 28, 188, 30, 82, 247, 236, 180, 23, 62, 171, 236, 178, 185, 202, 27, 194, 216, 119,
10-
36, 54, 142, 35, 185, 149, 203, 233, 18, 131, 34, 220, 48, 167, 38, 176, 191, 18, 181, 168, 5, 63, 178, 179, 8, 123,
11-
232, 186, 234, 254, 126, 125, 158, 143, 175, 87, 148, 74, 51, 194, 73, 172, 207, 234, 28, 149, 157, 182, 149, 144, 15,
12-
70, 78, 23, 51, 122, 83, 190, 15, 208, 181, 70, 122, 152, 126, 56, 83, 244, 10, 181, 6, 0, 0,
5+
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 186, 53, 241, 207, 11, 152, 232, 1, 58, 189,
6+
128, 119, 49, 254, 105, 244, 211, 227, 59, 50, 154, 49, 214, 100, 31, 163, 201, 246, 146, 133, 174, 5, 10, 15, 72, 17,
7+
122, 52, 221, 135, 188, 222, 177, 116, 44, 105, 223, 195, 24, 73, 247, 206, 50, 46, 67, 139, 118, 190, 98, 169, 24,
8+
221, 6, 98, 244, 5, 98, 4, 81, 255, 21, 214, 219, 178, 46, 166, 252, 249, 204, 252, 84, 208, 207, 215, 158, 255, 107,
9+
150, 141, 38, 154, 140, 28, 76, 7, 111, 132, 212, 61, 65, 201, 116, 86, 217, 101, 115, 11, 226, 62, 99, 223, 145, 88,
10+
56, 205, 228, 102, 127, 239, 53, 6, 69, 184, 97, 78, 109, 96, 127, 37, 106, 81, 11, 126, 100, 103, 17, 14, 48, 116,
11+
213, 227, 243, 254, 190, 158, 63, 175, 40, 149, 102, 132, 179, 88, 95, 212, 57, 42, 59, 109, 43, 33, 31, 140, 156, 46,
12+
102, 244, 230, 124, 31, 97, 104, 141, 244, 48, 253, 1, 180, 46, 168, 159, 181, 6, 0, 0,
1313
]);
1414
export const initialWitnessMap: WitnessMap = new Map([
1515
[1, '0x0000000000000000000000000000000000000000000000000000000000000001'],

noir/noir-repo/acvm-repo/acvm_js/test/shared/foreign_call.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { WitnessMap } from '@noir-lang/acvm_js';
22

33
// See `simple_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`.
44
export const bytecode = Uint8Array.from([
5-
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 49, 10, 128, 48, 12, 108, 196, 138, 224, 230, 75, 226, 15, 252, 140, 131,
6-
139, 131, 136, 239, 111, 161, 9, 28, 165, 205, 210, 28, 132, 36, 119, 16, 114, 9, 133, 130, 53, 7, 73, 29, 37, 107,
7-
143, 80, 238, 148, 204, 99, 56, 200, 111, 22, 227, 190, 83, 93, 16, 146, 193, 112, 22, 225, 34, 168, 205, 142, 174,
8-
241, 218, 206, 179, 121, 49, 188, 109, 57, 84, 191, 159, 255, 122, 63, 235, 199, 189, 190, 197, 237, 13, 45, 1, 20,
9-
245, 146, 30, 92, 2, 0, 0,
5+
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 73, 10, 192, 48, 8, 140, 165, 91, 160, 183, 126, 196, 254, 160, 159, 233,
6+
161, 151, 30, 74, 200, 251, 19, 136, 130, 132, 196, 75, 28, 16, 199, 17, 212, 65, 112, 5, 123, 14, 32, 190, 80, 230,
7+
90, 130, 181, 155, 50, 142, 225, 2, 187, 89, 40, 239, 157, 106, 2, 82, 116, 138, 51, 118, 239, 171, 222, 108, 232,
8+
218, 139, 125, 198, 179, 113, 83, 188, 29, 57, 86, 226, 239, 23, 159, 63, 104, 63, 238, 213, 45, 237, 108, 244, 18,
9+
195, 174, 252, 193, 92, 2, 0, 0,
1010
]);
1111
export const initialWitnessMap: WitnessMap = new Map([
1212
[1, '0x0000000000000000000000000000000000000000000000000000000000000005'],

noir/noir-repo/acvm-repo/brillig/src/opcodes.rs

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ pub enum BrilligOpcode<F> {
188188
lhs: MemoryAddress,
189189
rhs: MemoryAddress,
190190
},
191+
Not {
192+
destination: MemoryAddress,
193+
source: MemoryAddress,
194+
bit_size: IntegerBitSize,
195+
},
191196
Cast {
192197
destination: MemoryAddress,
193198
source: MemoryAddress,

0 commit comments

Comments
 (0)