Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
origin_tag.cpp
Go to the documentation of this file.
4
5namespace bb {
6using namespace numeric;
7#ifndef AZTEC_NO_ORIGIN_TAGS
8
17void check_round_provenance(const uint256_t& provenance_a, const uint256_t& provenance_b)
18{
19 const uint128_t* challenges_a = (const uint128_t*)(&provenance_a.data[2]);
20 const uint128_t* challenges_b = (const uint128_t*)(&provenance_b.data[2]);
21
22 const uint128_t* submitted_a = (const uint128_t*)(&provenance_a.data[0]);
23 const uint128_t* submitted_b = (const uint128_t*)(&provenance_b.data[0]);
24
25 if (*challenges_a == 0 && *challenges_b == 0 && *submitted_a != 0 && *submitted_b != 0 &&
26 *submitted_a != *submitted_b) {
27 throw_or_abort("Submitted values from 2 different rounds are mixing without challenges");
28 }
29}
30
31bool OriginTag::operator==(const OriginTag& other) const
32{
33 return this->transcript_index == other.transcript_index && this->round_provenance == other.round_provenance &&
34 this->instant_death == other.instant_death;
35}
36OriginTag::OriginTag(const OriginTag& tag_a, const OriginTag& tag_b)
37{
38 // Elements with instant death should not be touched
39 if (tag_a.instant_death || tag_b.instant_death) {
40 throw_or_abort("Touched an element that should not have been touched");
41 }
42 // If one of the tags is a constant, just use the other tag
43 if (tag_a.transcript_index == CONSTANT) {
44 *this = tag_b;
45 return;
46 }
47 if (tag_b.transcript_index == CONSTANT) {
48 *this = tag_a;
49 return;
50 }
51
52 // A free witness element should not interact with an element that has an origin
53 if (tag_a.is_free_witness()) {
54 if (!tag_b.is_free_witness() && !tag_b.is_empty()) {
55 throw_or_abort("A free witness element should not interact with an element that has an origin");
56 } else {
57 // If both are free witnesses or one of them is empty, just use tag_a
58 *this = tag_a;
59 return;
60 }
61 }
62 if (tag_b.is_free_witness()) {
63 if (!tag_a.is_free_witness() && !tag_a.is_empty()) {
64 throw_or_abort("A free witness element should not interact with an element that has an origin");
65 } else {
66 // If both are free witnesses or one of them is empty, just use tag_b
67 *this = tag_b;
68 return;
69 }
70 }
71 // Elements from different transcripts shouldn't interact
72 if (tag_a.transcript_index != tag_b.transcript_index) {
73 throw_or_abort("Tags from different transcripts were involved in the same computation");
74 }
75 // Check that submitted values from different rounds don't mix without challenges
77
80}
81
82#else
83bool OriginTag::operator==(const OriginTag&) const
84{
85 return true;
86}
87
88#endif
89} // namespace bb
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void check_round_provenance(const uint256_t &provenance_a, const uint256_t &provenance_b)
Detect if two elements from the same transcript are performing a suspicious interaction.
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
unsigned __int128 uint128_t
Definition serialize.hpp:44
size_t transcript_index
OriginTag()=default
static constexpr size_t CONSTANT
bool is_empty() const
bool is_free_witness() const
numeric::uint256_t round_provenance
bool operator==(const OriginTag &other) const
void throw_or_abort(std::string const &err)