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

Basic support for create and create2 #239

Merged
merged 1 commit into from
Feb 10, 2021

Conversation

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

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

What was wrong?

There was no support for contract creation.

How was it fixed?

  • Built out support for type attribute calls and added create functions to the contract type.
  • The analyzer now records contract types that are created and the compiler adds their Yul objects to the contract's runtime.
  • Added a compiler flag for Yul optimization.

To-Do

  • Update Spec if applicable

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

  • Clean up commit history

analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
compiler/src/yul/mappers/module.rs Outdated Show resolved Hide resolved
compiler/src/yul/operations/contracts.rs Outdated Show resolved Hide resolved
compiler/src/yul/runtime/functions/contract.rs Outdated Show resolved Hide resolved
compiler/src/yul/runtime/mod.rs Outdated Show resolved Hide resolved
compiler/tests/fixtures/create2_contract.fe Show resolved Hide resolved
@g-r-a-n-t g-r-a-n-t force-pushed the contract-creation branch 2 times, most recently from 7111501 to c74be43 Compare February 8, 2021 22:22
analyzer/src/namespace/scopes.rs Show resolved Hide resolved
compiler/src/yul/mappers/contracts.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
analyzer/src/traversal/expressions.rs Outdated Show resolved Hide resolved
compiler/src/yul/mappers/expressions.rs Outdated Show resolved Hide resolved
compiler/src/yul/mappers/expressions.rs Outdated Show resolved Hide resolved
@g-r-a-n-t g-r-a-n-t force-pushed the contract-creation branch 2 times, most recently from 98e90b5 to 7c166a0 Compare February 9, 2021 17:32
@codecov-io
Copy link

Codecov Report

Merging #239 (7c166a0) into master (584f5ac) will decrease coverage by 0.13%.
The diff coverage is 88.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #239      +/-   ##
==========================================
- Coverage   94.08%   93.94%   -0.14%     
==========================================
  Files          54       54              
  Lines        3701     3768      +67     
==========================================
+ Hits         3482     3540      +58     
- Misses        219      228       +9     
Impacted Files Coverage Δ
compiler/src/yul/mappers/expressions.rs 97.16% <0.00%> (ø)
compiler/src/yul/mappers/module.rs 78.57% <75.00%> (+3.57%) ⬆️
analyzer/src/traversal/expressions.rs 92.95% <83.05%> (-1.93%) ⬇️
analyzer/src/namespace/scopes.rs 95.93% <85.71%> (-0.87%) ⬇️
analyzer/src/lib.rs 91.93% <100.00%> (+0.06%) ⬆️
analyzer/src/traversal/declarations.rs 96.77% <100.00%> (ø)
compiler/src/evm/mod.rs 95.83% <100.00%> (+0.83%) ⬆️
compiler/src/lib.rs 88.88% <100.00%> (ø)
compiler/src/yul/constructor.rs 100.00% <100.00%> (ø)
compiler/src/yul/mod.rs 100.00% <100.00%> (ø)
... and 5 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 584f5ac...7c166a0. Read the comment docs.

analyzer/src/builtins.rs Outdated Show resolved Hide resolved
spec/index.md Outdated Show resolved Hide resolved
pub def create2_foo() -> address:
# `0` is the value being sent and `52` is the address salt
foo: Foo = Foo.create2(0, 52)
return address(foo)
Copy link
Collaborator

@cburgdorf cburgdorf Feb 10, 2021

Choose a reason for hiding this comment

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

Should we consider giving contracts a special attribute to obtain the address such so that the above could be written as:

pub def create2_foo() -> address:
        # `0` is the value being sent and `52` is the address salt
        foo: Foo = Foo.create2(0, 52)
        return foo.__address__

With the cast, a bug such as the following would be possible that would result in returning the wrong address.

pub def create2_foo() -> address:
        # `0` is the value being sent and `52` is the address salt
        foo: Foo = Foo.create2(0, 52)
        bar: Bar = Bar.create2(0, 11)
        return address(bar)

In the example above, we mean to return the address of the newly created foo but we accidentally return the address of bar instead. Sure, one can also accidentially return bar.__address__ but it feels to me that having the address accessible as a property removes one layer of error potential. That said, I really dislike the __address__ syntax but wouldn't know a good way to get around the potential for naming conflicts. At least not until we have something like traits that we could bring into scope conditionally to expose special functions/attributes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure how to deal with this.

We can discuss this more in #179 and if we come up with a better idea, it can be changed. For now, I'm inclined to just merge this as is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, should be good for now. 👍

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.

Looks good! Left some comments inline.

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