-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(avm): constrain sha256 #11048
base: master
Are you sure you want to change the base?
feat(avm): constrain sha256 #11048
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
edd1c61
to
1f4a5bf
Compare
1f4a5bf
to
87cef77
Compare
sel * (1 - sel) = 0; | ||
// For the XOR lookups | ||
pol commit xor_sel; | ||
perform_round * (xor_sel - 2) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should introduce constant for op_id of OR, AND, XOR and use it instead of hardcoded '2'.
perform_round * (xor_sel - 2) = 0; | ||
// For the AND lookups | ||
pol commit and_sel; | ||
and_sel = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
Maybe add a note that, once we support constant in a tuple member of a lookup, we will not need to define this column anymore.
|
||
// Counter | ||
pol commit rounds_remaining; | ||
start * (rounds_remaining - 64) + perform_round * (rounds_remaining - rounds_remaining' - 1) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define a constant for 64.
}; | ||
|
||
template <typename DestRow> | ||
void merge_into(DestRow& dest, FixedSha256ConstantsTable::Sha256ConstantsRow const& src, uint32_t multiplicity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void merge_into(DestRow& dest, FixedSha256ConstantsTable::Sha256ConstantsRow const& src, uint32_t multiplicity) | |
void merge_into(DestRow& dest, const FixedSha256ConstantsTable::Sha256ConstantsRow& src, uint32_t multiplicity) |
}; | ||
|
||
template <typename DestRow> | ||
void merge_into(DestRow& dest, FixedSha256ConstantsTable::Sha256ConstantsRow const& src, uint32_t multiplicity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void merge_into(DestRow& dest, FixedSha256ConstantsTable::Sha256ConstantsRow const& src, uint32_t multiplicity) | |
void merge_into(DestRow& dest, const FixedSha256ConstantsTable::Sha256ConstantsRow& src, uint32_t multiplicity) |
return output; | ||
} | ||
|
||
static std::tuple<uint32_t, uint32_t> bit_limbs(uint32_t const& a, uint8_t const b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static std::tuple<uint32_t, uint32_t> bit_limbs(uint32_t const& a, uint8_t const b) | |
static std::tuple<uint32_t, uint32_t> bit_limbs(const uint32_t a, const uint8_t b) |
{ | ||
|
||
for (size_t i = 0; i < sha256_trace.size(); i++) { | ||
auto const& src = sha256_trace.at(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto const& src = sha256_trace.at(i); | |
const auto& src = sha256_trace.at(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but have a look at my feedback. Cool work!
87cef77
to
eb03f46
Compare
eb03f46
to
8c6e5a8
Compare
1f891fb
to
c6ffba9
Compare
c6ffba9
to
c3f7087
Compare
c3f7087
to
6f9fbd0
Compare
barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp
Show resolved
Hide resolved
|
||
check_relation<sha256>(rows); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No negative tests now or no negative tests ever? :)
} | ||
|
||
// Computes and returns the message schedule (w) value for that round, and inserts witness data into the trace. | ||
uint32_t Sha256TraceBuilder::compute_w_with_witness(std::array<uint32_t, 16> prev_w_helpers, TraceContainer& trace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will consider taking the trace in the constructor so that we can eventually avoid passing it everywhere.
namespace sha256; | ||
|
||
// Memory ops | ||
pol commit state_offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not indenting in the other files, since there is only 1 namespace expected, does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the indentation - i feel like it makes things easier to read tbh
// Load 8 elements representing the state from memory. | ||
for (uint32_t i = 0; i < 8; ++i) { | ||
auto memory_value = memory.get(state_addr + i).value; | ||
/*Check Tag is U32 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing " ", same below in the other check tag
// Load 16 elements representing the input from memory. | ||
for (uint32_t i = 0; i < 16; ++i) { | ||
auto memory_value = memory.get(input_addr + i).value; | ||
/*Check Tag is U32 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an error handling TODO? Do you need to check the tags here? if yes please make explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add the TODO, the tag check is dependent on where we expect to enforce it (i.e in the memory trace or in the calling trace).
I guess we havent landed on what the approach will be yet
MemoryAddress output_addr) override; | ||
|
||
private: | ||
EventEmitterInterface<Sha256CompressionEvent>& events; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a TODO that we should be using "deduplicating events" here. I'll build the infra at some point.
Sorry, that was wrong. This is memory aware.
Most of the sha256 constraints. The main things missing are:
We'll delay this until vm2 re-design