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

ABI refactor and removal of bytes #472

Merged

Conversation

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

@g-r-a-n-t g-r-a-n-t commented Jun 29, 2021

What was wrong?

The original ABI encoding/decoding implementation made it difficult to do two things:

  • insert runtime checks
  • add support for recursive encodings

How was it fixed?

insert runtime checks

These checks have not been added yet, but this makes it easier to add them.

add support for recursive encodings

Also not implemented, but I think it should be somewhat easier now.

Some other changes:

  • got rid of the bytes type. u8[n] is now encoded as a dynamically sized bytes array.
  • made yulc panics readable
  • changed the type of msg.sig to u256

To-Do

  • OPTIONAL: Update Spec if applicable

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

  • Clean up commit history

analyzer/src/namespace/types.rs Outdated Show resolved Hide resolved
compiler/src/yul/constructor.rs Outdated Show resolved Hide resolved
compiler/src/yul/constructor.rs Outdated Show resolved Hide resolved
compiler/src/yul/runtime/abi_dispatcher.rs Outdated Show resolved Hide resolved
compiler/src/yul/runtime/functions/abi.rs Outdated Show resolved Hide resolved
@g-r-a-n-t g-r-a-n-t force-pushed the abi-refactor-and-removal-of-bytes branch 2 times, most recently from 43907c4 to 0403161 Compare June 30, 2021 05:03
@codecov-commenter
Copy link

codecov-commenter commented Jun 30, 2021

Codecov Report

Merging #472 (9dfb446) into master (ff5df97) will increase coverage by 0.00%.
The diff coverage is 97.77%.

❗ Current head 9dfb446 differs from pull request most recent head 9af614a. Consider uploading reports for the commit 9af614a to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master     #472   +/-   ##
=======================================
  Coverage   87.31%   87.32%           
=======================================
  Files          76       77    +1     
  Lines        5046     5081   +35     
=======================================
+ Hits         4406     4437   +31     
- Misses        640      644    +4     
Impacted Files Coverage Δ
crates/analyzer/src/traversal/types.rs 100.00% <ø> (ø)
crates/driver/src/lib.rs 75.67% <0.00%> (-4.33%) ⬇️
crates/lowering/src/names.rs 78.57% <ø> (ø)
crates/yulgen/src/lib.rs 100.00% <ø> (ø)
crates/yulgen/src/mappers/contracts.rs 100.00% <ø> (ø)
crates/yulgen/src/mappers/expressions.rs 90.00% <ø> (ø)
crates/yulgen/src/mappers/functions.rs 97.50% <ø> (ø)
crates/yulgen/src/utils.rs 100.00% <ø> (+6.89%) ⬆️
crates/analyzer/src/namespace/types.rs 81.06% <91.17%> (-1.85%) ⬇️
crates/yulgen/src/names/abi.rs 98.64% <98.64%> (ø)
... and 13 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 ff5df97...9af614a. Read the comment docs.

crates/analyzer/src/namespace/types.rs Outdated Show resolved Hide resolved
crates/yulgen/src/operations/abi.rs Show resolved Hide resolved
crates/analyzer/src/namespace/types.rs Show resolved Hide resolved
crates/analyzer/src/namespace/types.rs Show resolved Hide resolved
crates/analyzer/src/namespace/types.rs Show resolved Hide resolved
crates/yulgen/src/runtime/functions/abi.rs Show resolved Hide resolved
crates/yulgen/src/runtime/functions/abi.rs Outdated Show resolved Hide resolved
crates/yulgen/src/runtime/functions/abi.rs Show resolved Hide resolved
crates/yulgen/src/utils.rs Outdated Show resolved Hide resolved
@g-r-a-n-t
Copy link
Member Author

Here's a sample of the new yulc panic formatting:

Error: DeclarationError: Identifier "params_start_code" not found.
 --> input.yul:5:49:
  |
5 |         let params_size := sub(params_end_code, params_start_code)
  |                                                 ^^^^^^^^^^^^^^^^^


Error: DeclarationError: Identifier "params_start_code" not found.
 --> input.yul:8:36:
  |
8 |         codecopy(params_start_mem, params_start_code, params_size)
  |                                    ^^^^^^^^^^^^^^^^^


thread 'main' panicked at 'Yul compilation failed with the above errors', crates/driver/src/lib.rs:86:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

You've hit an internal compiler error. This is a bug in the Fe compiler.
Fe is still under heavy development, and isn't yet ready for production use.

If you would, please report this bug at the following URL:
  https://github.com/ethereum/fe/issues/new

crates/yulgen/src/names/abi.rs Outdated Show resolved Hide resolved
crates/yulgen/src/runtime/functions/abi.rs Outdated Show resolved Hide resolved
@g-r-a-n-t g-r-a-n-t force-pushed the abi-refactor-and-removal-of-bytes branch from 381e37f to ce1db94 Compare July 1, 2021 02:13
@@ -0,0 +1,9 @@
---
Copy link
Member Author

Choose a reason for hiding this comment

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

the snapshots are worth looking at

@g-r-a-n-t g-r-a-n-t force-pushed the abi-refactor-and-removal-of-bytes branch from ce1db94 to 6e4eefc Compare July 1, 2021 02:18
vec![function.return_type],
let decoding_operation = abi_operations::decode_data(
&[function.return_type],
identifier_expression! { outstart },
identifier_expression! { outstart },
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be outstart + outsize. it's not an issue rn since the data_end parameter is ignored, so Im just going to fix it in #440

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.

I just glanced over it but seems fine to me :)

crates/analyzer/src/namespace/types.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@sbillig sbillig left a comment

Choose a reason for hiding this comment

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

👍

AbiType::Bool => "bool".to_string(),
AbiType::Address => "address".to_string(),
AbiType::StaticArray { size, inner } => format!("array_{}_{}", size, typ(inner)),
AbiType::Tuple { components } => format!("tuple_{}", types(components)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will presumably allow for naming collisions when we support nested tuples and structs. Doesn't necessarily have to be addressed now, but we need standard method for collision-avoidance everywhere code is generated (as we discussed yesterday). In the lowering pass, I added a trailing underscore to the tuple name, but maybe we should just add an incrementing number to every generated identifier (eg add a $N suffix, which I think @Y-Nak suggested), rather than trying to differentiate between different nestings by adding a character that stands in for the parentheses.
eg
(A, (B, C), D) -> abi_decode_component_tuple_A_tuple_B_C_D$0
(A, (B, C, D)) -> abi_decode_component_tuple_A_tuple_B_C_D$1

@g-r-a-n-t g-r-a-n-t force-pushed the abi-refactor-and-removal-of-bytes branch from 6e4eefc to 9af614a Compare July 2, 2021 20:21
@g-r-a-n-t g-r-a-n-t merged commit 618f267 into ethereum:master Jul 2, 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.

4 participants