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

feat: constructor support #31

Merged
merged 21 commits into from
Feb 11, 2025

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Dec 29, 2024

implements contract constructors with with the following design choices:

  • constructors must stick to the std rust fn new(..constructor_args) -> Self nomenclature. Note that returning Self is irrelevant (therefore not enforced) and was simply used in the ERC20 example to make it feel more familiar for readers.
  • updates fn deploy_contract(db: &mut InMemoryDB, bytecode: Bytes) to also take encoded_args: Option<Vec<u8>> as an argument.
    • personally i like using Option cause it feels more explicit, but we could also use Vec<u8> and check whether it is empty or not
    • note that since deployments must use the deploy feature flag, no function selector is needed, hence why i decided to only use the encoded args (to minimize initcode size)

leonardoalt
leonardoalt previously approved these changes Feb 6, 2025
Copy link
Collaborator

@leonardoalt leonardoalt 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! Has some conflicts now

@0xrusowsky
Copy link
Contributor Author

Looks good! Has some conflicts now

thanks Leo, will push something before eod

Comment on lines +10 to +18
SECTIONS
{
/DISCARD/ : {
*(.eh_frame)
*(.eh_frame_hdr)
*(.eh_frame.*)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leonardoalt apparently newer rustc versions create an llvm section for exception handling (.eh_frame) which they didn't use to.

this section caused me a lot of compilation issues because it was being allocated in a "forbidden" memory region by our interpreter.

it took me a while, but thanks to some AI help i ended up with this modification of the linker script, which maintains the same elf codegen as before the version bump (it simply discard the .eh_frame).

"-C", "link-arg=-T../r5-rust-rt.x",
"-C", "inline-threshold=275"
"-C", "link-arg=-T../../r5-rust-rt.x",
"-C", "llvm-args=--inline-threshold=275"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fyi, i also updated the rustflags as i was getting deprecation warnings

@0xrusowsky
Copy link
Contributor Author

and last but not least, i also moved all the contracts under an examples/ folder, as your suggested next step is to generate several examples to show r55 usage 🙂

@leonardoalt leonardoalt merged commit c26ef70 into r55-eth:main Feb 11, 2025
13 checks passed
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.

2 participants