Skip to content
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

Implement selector_id!, selector_bytes! and blake2x256! macros #947

Merged
merged 16 commits into from
Oct 4, 2021

Conversation

Robbepop
Copy link
Collaborator

@Robbepop Robbepop commented Oct 2, 2021

Inspired by the METIS library utility macros this PR adds those macros (different implementation and API) to ink! as built-ins.

Link: /~https://github.com/patractlabs/metis/blob/main/crates/lang/macro/src/lib.rs

Adds the following proc. macros to ink_lang_macro crate that are exposed from ink_lang:

  • selector_id!: Takes a string or byte string literal as input and computes the selector ID of type u32.
  • selector_bytes!: Takes a string or byte string literal as input and computes the selector bytes of type [u8; 4].
  • blake2x256!: Takes a string or byte string literal as input and computes the BLAKE2b 256-bit hash of type [u8; 32].

ToDo List

  • Write UI tests for ...
    • selector_id!
    • selector_bytes!
    • blake2x256!

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2021

Codecov Report

Merging #947 (a4abc4d) into master (7c19f63) will decrease coverage by 1.12%.
The diff coverage is 88.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #947      +/-   ##
==========================================
- Coverage   82.86%   81.73%   -1.13%     
==========================================
  Files         177      190      +13     
  Lines        8055     8165     +110     
==========================================
- Hits         6675     6674       -1     
- Misses       1380     1491     +111     
Impacted Files Coverage Δ
crates/lang/codegen/src/generator/mod.rs 100.00% <ø> (ø)
crates/lang/codegen/src/lib.rs 100.00% <ø> (ø)
crates/lang/ir/src/ir/selector.rs 74.28% <73.68%> (-0.72%) ⬇️
crates/lang/ir/src/ir/blake2.rs 79.16% <75.00%> (-20.84%) ⬇️
crates/lang/macro/src/blake2b.rs 85.71% <85.71%> (ø)
crates/lang/macro/src/selector.rs 85.71% <85.71%> (ø)
crates/lang/codegen/src/generator/blake2b.rs 100.00% <100.00%> (ø)
crates/lang/codegen/src/generator/selector.rs 100.00% <100.00%> (ø)
crates/lang/macro/src/lib.rs 100.00% <100.00%> (ø)
...ng/macro/tests/ui/blake2b/pass/bytestring_input.rs 100.00% <100.00%> (ø)
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c19f63...a4abc4d. Read the comment docs.

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 2, 2021

Maybe will be useful to add a method that will return 'u32' from the hash. It is possible to get from the selector by 'into_be_u32' method. But it is not clear for a new developer:)

@Robbepop
Copy link
Collaborator Author

Robbepop commented Oct 2, 2021

Maybe will be useful to add a method that will return 'u32' from the hash. It is possible to get from the selector by 'into_be_u32' method. But it is not clear for a new developer:)

From what I understood this is equal to selector_id! and therefore duplicate API. I would like to keep the API minimal.
I think your stated problem should be tackled with proper documentation where necessary.

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 2, 2021

Oh, I see, you've already returned a u32. I thought that it is Selector, but it is u32 or [u8; 4] . Then cool!:)

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 2, 2021

Maybe selector_u32 is more clear than selector_id?:)

@Robbepop
Copy link
Collaborator Author

Robbepop commented Oct 2, 2021

Maybe selector_u32 is more clear than selector_id?:)

Maybe but I thought that selector_id is a high level concept as is Selector in itself.
So calling it selector_u32! would be a half baked solution.
The opposite would be to name it blake2x256_first4_as_u32 but that is way too concrete.

@Robbepop Robbepop marked this pull request as ready for review October 2, 2021 11:42
@Robbepop
Copy link
Collaborator Author

Robbepop commented Oct 2, 2021

Added all the UI tests for the new macros.
Ready for review! :)

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 2, 2021

What do you think about selector_id_u32 and selector_id_bytes?:D - Joke:)

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants