Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
class_id_derivation.test.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
6
14
15using ::testing::IsEmpty;
16using ::testing::SizeIs;
17
18namespace bb::avm2::simulation {
19
20namespace {
21
22using simulation::PurePoseidon2;
23
24TEST(AvmSimulationClassIdDerivationTest, Positive)
25{
26 EventEmitter<ClassIdDerivationEvent> class_id_derivation_event_emitter;
27 PurePoseidon2 poseidon2 = PurePoseidon2();
28
29 ClassIdDerivation class_id_derivation(poseidon2, class_id_derivation_event_emitter);
30
31 ContractClassWithCommitment klass = {
32 .id = FF::random_element(),
33 .artifact_hash = FF::random_element(),
34 .private_functions_root = FF::random_element(),
35 .packed_bytecode = { 0x01, 0x02, 0x03, 0x04 },
36 .public_bytecode_commitment = FF::random_element(),
37 };
38 ContractClassId expected_class_id = poseidon2.hash(std::vector<FF>{ GENERATOR_INDEX__CONTRACT_LEAF,
39 klass.artifact_hash,
40 klass.private_functions_root,
41 klass.public_bytecode_commitment });
42 // Update the klass.id to match the computed value
43 klass.id = expected_class_id;
44
45 class_id_derivation.assert_derivation(klass);
46
47 auto events = class_id_derivation_event_emitter.dump_events();
48 EXPECT_THAT(events, SizeIs(1));
49 EXPECT_EQ(events[0].klass.id, expected_class_id);
50 EXPECT_EQ(events[0].klass.artifact_hash, klass.artifact_hash);
51
52 // Second derivation for the same class ID should be a cache hit and should not emit an event
53 class_id_derivation.assert_derivation(klass);
54 events = class_id_derivation_event_emitter.dump_events();
55 EXPECT_THAT(events, IsEmpty());
56}
57
58} // namespace
59} // namespace bb::avm2::simulation
#define GENERATOR_INDEX__CONTRACT_LEAF
StrictMock< MockClassIdDerivation > class_id_derivation
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
FF ContractClassId
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
static field random_element(numeric::RNG *engine=nullptr) noexcept