Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bytecode_hashing.cpp
Go to the documentation of this file.
2
3#include <utility>
4
9
10namespace bb::avm2::simulation {
11
25 const std::vector<uint8_t>& bytecode)
26{
27 BB_BENCH_NAME("BytecodeHasher::assert_public_bytecode_commitment");
28 auto bytecode_length_in_bytes = bytecode.size();
29
30 std::vector<FF> inputs = { compute_public_bytecode_first_field(bytecode_length_in_bytes) };
31 auto bytecode_as_fields = encode_bytecode(bytecode);
32 inputs.insert(inputs.end(), bytecode_as_fields.begin(), bytecode_as_fields.end());
33
34 FF hash = hasher.hash(inputs);
35 // This will throw an unexpected exception if it fails.
36 BB_ASSERT_EQ(hash, bytecode_id, "Public bytecode commitment hash mismatch");
37
38 events.emit({ .bytecode_id = bytecode_id,
39 .bytecode_length_in_bytes = static_cast<uint32_t>(bytecode_length_in_bytes),
40 .bytecode_fields = std::move(bytecode_as_fields) });
41}
42
43} // namespace bb::avm2::simulation
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:264
void assert_public_bytecode_commitment(const BytecodeId &bytecode_id, const std::vector< uint8_t > &bytecode) override
Verify that the given bytecode_id matches the expected bytecode commitment which is a Poseidon2 hash ...
EventEmitterInterface< BytecodeHashingEvent > & events
virtual FF hash(const std::vector< FF > &input)=0
AvmProvingInputs inputs
AVM range check gadget for witness generation.
std::vector< FF > encode_bytecode(std::span< const uint8_t > bytecode)
Encodes the bytecode into a vector of field elements. Each field element represents 31 bytes of the b...
FF compute_public_bytecode_first_field(size_t bytecode_size)
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13