-
Notifications
You must be signed in to change notification settings - Fork 609
feat: FunctionSelector type
#1518
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9575ddd
WIP
benesjan bed54ab
typo
benesjan a036e65
feat: introduced FunctionData struct in C++
benesjan a4d8dd6
WIP
benesjan 2d4791b
WIP
benesjan 80d8839
WIP
benesjan 8e953ca
linter fixes
benesjan 772cd68
fix
benesjan 52f508b
fixes
benesjan 48748db
refactor: more concise naming
benesjan bdcecc0
fix
benesjan bf6ec36
Update yarn-project/foundation/src/abi/function_selector.ts
benesjan 746acad
Update yarn-project/circuits.js/src/structs/function_data.ts
benesjan 4467e55
Merge branch 'master' into janb/function-selector-type
benesjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
circuits/cpp/src/aztec3/circuits/abis/function_selector.hpp
This file contains hidden or 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,59 @@ | ||
| #pragma once | ||
|
|
||
| #include "aztec3/utils/types/circuit_types.hpp" | ||
| #include "aztec3/utils/types/convert.hpp" | ||
| #include "aztec3/utils/types/native_types.hpp" | ||
|
|
||
| #include "barretenberg/serialize/msgpack.hpp" | ||
|
|
||
| namespace aztec3::circuits::abis { | ||
|
|
||
| using aztec3::utils::types::CircuitTypes; | ||
| using aztec3::utils::types::NativeTypes; | ||
|
|
||
| template <typename NCT> struct FunctionSelector { | ||
| using uint32 = typename NCT::uint32; | ||
| using boolean = typename NCT::boolean; | ||
| using fr = typename NCT::fr; | ||
|
|
||
| uint32 value; // e.g. 1st 4-bytes of abi-encoding of function. | ||
|
|
||
| MSGPACK_FIELDS(value); | ||
|
|
||
| boolean operator==(FunctionSelector<NCT> const& other) const { return value == other.value; }; | ||
|
|
||
| template <typename Builder> FunctionSelector<CircuitTypes<Builder>> 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); }; | ||
|
|
||
| FunctionSelector<CircuitTypes<Builder>> function_selector = { | ||
| to_ct(value), | ||
| }; | ||
|
|
||
| return function_selector; | ||
| }; | ||
|
|
||
| template <typename Builder> FunctionSelector<NativeTypes> to_native_type() const | ||
| { | ||
| static_assert(std::is_same<CircuitTypes<Builder>, NCT>::value); | ||
| auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt<Builder>(e); }; | ||
|
|
||
| FunctionSelector<NativeTypes> function_selector = { | ||
| to_nt(value), | ||
| }; | ||
|
|
||
| return function_selector; | ||
| }; | ||
|
|
||
| void set_public() | ||
| { | ||
| static_assert(!(std::is_same<NativeTypes, NCT>::value)); | ||
|
|
||
| fr(value).set_public(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace aztec3::circuits::abis |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: I would think this could leave off the type and just have = { ...}
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.
Thanks Adam. Addressed in #1800 .