Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Builtin for runtime code / creation code #278

Open
obatirou opened this issue May 11, 2023 · 3 comments
Open

Builtin for runtime code / creation code #278

obatirou opened this issue May 11, 2023 · 3 comments

Comments

@obatirou
Copy link

A builtin to get the runtime code could make sense, especially with contracts having jumptable / immutable variables. Creation code could also have use cases.

cc @Philogy
First suggested by @Maddiaa0

@Philogy
Copy link
Contributor

Philogy commented May 11, 2023

Isn't this already possible with __codesize(MAIN) and __codesize(CONSTRUCTOR)? Would be cool to have a built-in for the sum of the two tho i.e. deploy code, which would be very useful for determining the position of constructor arguments.

Also, a builtin to get the code offset for certain constants/placeholders would help immensely, have had to write a script to find that manually in METH: https://github.com/Philogy/meth-weth/blob/main/script/build-helpers/immutable-offsets.py

@obatirou
Copy link
Author

Isn't this already possible with __codesize(MAIN) and __codesize(CONSTRUCTOR)? Would be cool to have a built-in for the sum of the two tho i.e. deploy code, which would be very useful for determining the position of constructor arguments.

Also, a builtin to get the code offset for certain constants/placeholders would help immensely, have had to write a script to find that manually in METH: https://github.com/Philogy/meth-weth/blob/main/script/build-helpers/immutable-offsets.py

__codesize(MAIN) + __codesize(CONSTRUCTOR) will work for contracts that do not have a jumptable: they are appended at end of the MAIN bytecode but are not considered part of the MAIN macro leading to differences between __codesize(MAIN) and deploy code.
I agree with you, would be nice to have a built-in for deploy code size.

Interesting idea for the code offset of placeholders !

@Philogy
Copy link
Contributor

Philogy commented May 11, 2023

Oh I see, yeah that'd be helpful. Not to mention __codesize(MAIN) __codesize(CONSTRUCTOR) add costs 9 gas and is 7-bytes vs if it was a single push instruction (3-bytes and 3 gas).

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

No branches or pull requests

2 participants