Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
origin_tag.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
10
11namespace bb {
12using namespace numeric;
13#ifndef AZTEC_NO_ORIGIN_TAGS
14
23void check_child_tags(const uint256_t& tag_a, const uint256_t& tag_b)
24{
25 const uint128_t* challenges_a = (const uint128_t*)(&tag_a.data[2]);
26 const uint128_t* challenges_b = (const uint128_t*)(&tag_b.data[2]);
27
28 const uint128_t* submitted_a = (const uint128_t*)(&tag_a.data[0]);
29 const uint128_t* submitted_b = (const uint128_t*)(&tag_b.data[0]);
30
31 if (*challenges_a == 0 && *challenges_b == 0 && *submitted_a != 0 && *submitted_b != 0 &&
32 *submitted_a != *submitted_b) {
33 throw_or_abort("Submitted values from 2 different rounds are mixing without challenges");
34 }
35}
36
37bool OriginTag::operator==(const OriginTag& other) const
38{
39 return this->parent_tag == other.parent_tag && this->child_tag == other.child_tag &&
40 this->instant_death == other.instant_death;
41}
42OriginTag::OriginTag(const OriginTag& tag_a, const OriginTag& tag_b)
43{
44 // Elements with instant death should not be touched
45 if (tag_a.instant_death || tag_b.instant_death) {
46 throw_or_abort("Touched an element that should not have been touched");
47 }
48 // If one of the tags is a constant, just use the other tag
49 if (tag_a.parent_tag == CONSTANT) {
50 *this = tag_b;
51 return;
52 }
53 if (tag_b.parent_tag == CONSTANT) {
54 *this = tag_a;
55 return;
56 }
57
58 // A free witness element should not interact with an element that has an origin
59 if (tag_a.is_free_witness()) {
60 if (!tag_b.is_free_witness() && !tag_b.is_empty()) {
61 throw_or_abort("A free witness element should not interact with an element that has an origin");
62 } else {
63 // If both are free witnesses or one of them is empty, just use tag_a
64 *this = tag_a;
65 return;
66 }
67 }
68 if (tag_b.is_free_witness()) {
69 if (!tag_a.is_free_witness() && !tag_a.is_empty()) {
70 throw_or_abort("A free witness element should not interact with an element that has an origin");
71 } else {
72 // If both are free witnesses or one of them is empty, just use tag_b
73 *this = tag_b;
74 return;
75 }
76 }
77 // Elements from different transcripts shouldn't interact
78#ifndef DISABLE_DIFFERENT_TRANSCRIPT_CHECKS
79 if (tag_a.parent_tag != tag_b.parent_tag) {
80 throw_or_abort("Tags from different transcripts were involved in the same computation");
81 }
82#endif
83#ifndef DISABLE_CHILD_TAG_CHECKS
85#endif
86 parent_tag = tag_a.parent_tag;
87 child_tag = tag_a.child_tag | tag_b.child_tag;
88}
89
90#else
91bool OriginTag::operator==(const OriginTag&) const
92{
93 return true;
94}
95
96#endif
97} // namespace bb
Entry point for Barretenberg command-line interface.
void check_child_tags(const uint256_t &tag_a, const uint256_t &tag_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 parent_tag
OriginTag()=default
numeric::uint256_t child_tag
static constexpr size_t CONSTANT
bool is_empty() const
bool is_free_witness() const
bool operator==(const OriginTag &other) const
void throw_or_abort(std::string const &err)