-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(simulator): simulator allows noir to read pending commitments (#926
) * ACIR simulator tracks pending notes and allows Noir contracts to "get" them * Kernel rejects all transient reads for now (until read<>commitment matching logic is there) * New test contract added along with ACIR simulator tests and e2e tests for pending commitments * New type ReadRequestMembershipWitness added which is a normal membership witness with a "kernel hint" * Temporary hack in Noir to force strict dependency and ordering between notifyCreatedNote and subsequent getNotes oracles
- Loading branch information
Showing
43 changed files
with
1,532 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
circuits/cpp/src/aztec3/circuits/abis/read_request_membership_witness.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
|
||
#include "aztec3/circuits/abis/membership_witness.hpp" | ||
#include "aztec3/utils/types/circuit_types.hpp" | ||
#include "aztec3/utils/types/convert.hpp" | ||
|
||
namespace aztec3::circuits::abis { | ||
|
||
using aztec3::utils::types::CircuitTypes; | ||
using aztec3::utils::types::NativeTypes; | ||
using std::is_same; | ||
|
||
/** | ||
* A ReadRequestMembershipWitness is similar to a MembershipWitness but includes | ||
* some additional fields used to direct the kernel regarding whether a read is transient | ||
* and if so which commitment it corresponds to. | ||
*/ | ||
template <typename NCT, unsigned int N> struct ReadRequestMembershipWitness { | ||
using fr = typename NCT::fr; | ||
using boolean = typename NCT::boolean; | ||
|
||
fr leaf_index = 0; | ||
std::array<fr, N> sibling_path{}; | ||
boolean is_transient = false; // whether or not the read request corresponds to a pending commitment | ||
fr hint_to_commitment = 0; // hint to point kernel to the commitment this rr corresponds to | ||
|
||
MSGPACK_FIELDS(leaf_index, sibling_path, is_transient, hint_to_commitment); | ||
|
||
boolean operator==(ReadRequestMembershipWitness<NCT, N> const& other) const | ||
{ | ||
return leaf_index == other.leaf_index && sibling_path == other.sibling_path && | ||
is_transient == other.is_transient && hint_to_commitment == other.hint_to_commitment; | ||
}; | ||
|
||
template <typename Builder> | ||
ReadRequestMembershipWitness<CircuitTypes<Builder>, N> to_circuit_type(Builder& builder) const | ||
{ | ||
static_assert((std::is_same<NativeTypes, NCT>::value)); | ||
|
||
// Capture the circuit builder: | ||
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; | ||
|
||
ReadRequestMembershipWitness<CircuitTypes<Builder>, N> witness = { | ||
to_ct(leaf_index), to_ct(sibling_path), to_ct(is_transient), to_ct(hint_to_commitment) | ||
}; | ||
|
||
return witness; | ||
} | ||
}; | ||
|
||
template <typename NCT, unsigned int N> void read(uint8_t const*& it, ReadRequestMembershipWitness<NCT, N>& obj) | ||
{ | ||
using serialize::read; | ||
|
||
read(it, obj.leaf_index); | ||
read(it, obj.sibling_path); | ||
read(it, obj.is_transient); | ||
read(it, obj.hint_to_commitment); | ||
}; | ||
|
||
template <typename NCT, unsigned int N> | ||
void write(std::vector<uint8_t>& buf, ReadRequestMembershipWitness<NCT, N> const& obj) | ||
{ | ||
using serialize::write; | ||
|
||
write(buf, obj.leaf_index); | ||
write(buf, obj.sibling_path); | ||
write(buf, obj.is_transient); | ||
write(buf, obj.hint_to_commitment); | ||
}; | ||
|
||
template <typename NCT, unsigned int N> | ||
std::ostream& operator<<(std::ostream& os, ReadRequestMembershipWitness<NCT, N> const& obj) | ||
{ | ||
return os << "leaf_index: " << obj.leaf_index << "\n" | ||
<< "sibling_path: " << obj.sibling_path << "\n" | ||
<< "is_transient: " << obj.is_transient << "\n" | ||
<< "hint_to_commitment_index: " << obj.hint_to_commitment << "\n"; | ||
} | ||
|
||
} // namespace aztec3::circuits::abis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.