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

Expose abi encoding #266

Merged
merged 1 commit into from
Feb 24, 2021
Merged

Conversation

g-r-a-n-t
Copy link
Member

@g-r-a-n-t g-r-a-n-t commented Feb 22, 2021

What was wrong?

The main goal of this PR is to implement ABI encoding for structs and expose it the user via a builtin attribute function abi_encode().

How was it fixed?

  • Implemented the AbiEncoding trait for structs. This was quite easy since structs are already encoded following the ABI standard.
  • Implemented the abi_encode() attribute function for structs.

There were a few other things that I ran into and fixed/changed.

  • Ordered struct fields. #263
  • We're using the struct field pointer getter operations for storage too now.
  • Field value offsets are now calculated using field_index * 32 + (32 - field_size) instead of field_index * 32, which fixed a bug I was seeing.
  • Changed the array field dimension to size. This should be correct terminology.
  • Some refactoring to the struct implementation and more testing.

To-Do

  • Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@g-r-a-n-t g-r-a-n-t marked this pull request as draft February 22, 2021 23:48
Struct,
};
use yultsur::*;

#[test]
fn test_new() {
let mut val = Struct::new("Foo");
val.add_field("bar", &Base::Bool);
val.add_field("bar2", &Base::Bool);
val.add_field("bar", &FixedSize::Base(Base::Bool));
Copy link
Member Author

Choose a reason for hiding this comment

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

we could add functions like FixedSize::bool() to make tests cleaner

@codecov-io
Copy link

codecov-io commented Feb 24, 2021

Codecov Report

Merging #266 (c1b5404) into master (fd9f78e) will decrease coverage by 0.20%.
The diff coverage is 78.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #266      +/-   ##
==========================================
- Coverage   93.94%   93.73%   -0.21%     
==========================================
  Files          54       54              
  Lines        3798     3816      +18     
==========================================
+ Hits         3568     3577       +9     
- Misses        230      239       +9     
Impacted Files Coverage Δ
analyzer/src/namespace/operations.rs 84.84% <ø> (ø)
analyzer/src/traversal/assignments.rs 96.66% <ø> (ø)
compiler/src/yul/mappers/assignments.rs 97.82% <ø> (ø)
compiler/src/yul/mappers/declarations.rs 100.00% <ø> (ø)
compiler/src/yul/mappers/functions.rs 100.00% <ø> (ø)
compiler/src/yul/names.rs 100.00% <ø> (ø)
compiler/src/yul/operations/abi.rs 88.23% <0.00%> (-2.68%) ⬇️
compiler/src/yul/runtime/functions/abi.rs 91.61% <41.66%> (-4.20%) ⬇️
compiler/src/yul/utils.rs 93.75% <66.66%> (-2.92%) ⬇️
analyzer/src/namespace/types.rs 81.94% <71.42%> (+0.46%) ⬆️
... and 11 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 fd9f78e...c1b5404. Read the comment docs.

@g-r-a-n-t g-r-a-n-t marked this pull request as ready for review February 24, 2021 02:30
// less than 32 bytes. So, when we get the pointer to the value of a struct
// field, we must take into consideration the left-padding. The left-padding is
// equal to the difference between the value's size and 32 bytes, so we end up
// adding the word offset and the byte offset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

0, 0, 0, 0, 1, 244, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like how the nitty gritty details exposed by this test!

@@ -303,3 +309,58 @@ fn test_runtime_set_zero() {
);
})
}

#[test]
fn test_runtime_house_struct() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is such a cool test 👏

Copy link
Collaborator

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

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

Super cool PR! Looks great 👍

@g-r-a-n-t g-r-a-n-t merged commit ced35db into ethereum:master Feb 24, 2021
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.

3 participants