-
-
Notifications
You must be signed in to change notification settings - Fork 866
feat[lang]: add raw_create()
builtin
#4204
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
Conversation
raw_create()
builtin
let's also update the docs please |
vyper/builtins/functions.py
Outdated
ret.append(copy_bytes(buf, bytes_data_ptr(initcode), bytecode_len, maxlen)) | ||
|
||
argbuf = add_ofst(buf, bytecode_len) | ||
argslen = abi_encode(argbuf, to_encode, context, bufsz=bufsz, returns_len=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reminds of something: #4202
vyper/builtins/functions.py
Outdated
|
||
argbuf = add_ofst(buf, bytecode_len) | ||
argslen = abi_encode(argbuf, to_encode, context, bufsz=bufsz, returns_len=True) | ||
total_len = add_ofst(argbuf, argslen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this is wrong - isn't the length now absolute wrt 0?
shouldn't it be smth like total_len = ["sub", add_ofst(argbuf, argslen), buf]
vyper/builtins/functions.py
Outdated
bytecode_len = get_bytearray_length(initcode) | ||
|
||
maxlen = initcode.typ.maxlen | ||
ret.append(copy_bytes(buf, bytes_data_ptr(initcode), bytecode_len, maxlen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't be problematic that copy_bytes
might pad to ceil32
, right?
it might copy some dirty data, but if arguments are provided, those should overwrite it
if no args are provided, we still operate with bytecode_len
which will lead to ignoring the dirty data
can we please add tests for the rest of the kws? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4204 +/- ##
==========================================
+ Coverage 92.34% 92.35% +0.01%
==========================================
Files 123 123
Lines 17472 17499 +27
Branches 2949 2949
==========================================
+ Hits 16135 16162 +27
Misses 933 933
Partials 404 404 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Can we ship this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR is a good opportunity to discuss the following:
- How do you feel about extending the PR to include my issue here as well: #4147?
- The built-in is great but to increase the overall devex, we need to bundle it with some type information feature for contracts: i.e.
erc20.creation_code
,erc20.runtime_code
,erc20.interface_id
. Thecreation_code
information can be super useful here.
docs/built-in-functions.rst
Outdated
.. py:function:: raw_create(initcode: Bytes[...], *args, value: uint256 = 0, revert_on_failure: bool = True[, salt: bytes32]) -> address | ||
Create a physical copy of the runtime code at ``target``. The code at ``target`` is byte-for-byte copied into a newly deployed contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the target
here with us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### 🕓 Changelog Vyper has recently introduced the new `raw_create` built-in function via PR [#4204](vyperlang/vyper#4204), enabling direct contract creations using the EVM opcodes [`CREATE`](https://www.evm.codes/?fork=cancun#f0) and [`CREATE2`](https://www.evm.codes/?fork=cancun#f5). In response, this PR adds [`CREATE`](https://www.evm.codes/?fork=cancun#f0), [`CREATE2`](https://www.evm.codes/?fork=cancun#f5), and [`CREATE3`](ethereum/EIPs#3171 (i.e. without an initcode factor) utility functions to the corresponding module contracts in 🐍 snekmate. Please note that the current upper limit for the contract creation code is set to `8_192` bytes (\$2^{13}\$). ```vy from snekmate.utils import create as c1 from snekmate.utils import create2 as c2 from snekmate.utils import create3 as c3 @external @payable def deploy_create(init_code: Bytes[8_192]) -> address: return c1._deploy_create(init_code) @external @payable def deploy_create2(salt: bytes32, init_code: Bytes[8_192]) -> address: return c2._deploy_create2(salt, init_code) @external @payable def deploy_create3(salt: bytes32, init_code: Bytes[8_192]) -> address: return c3._deploy_create3(salt, init_code) ``` ###⚠️ Breaking Changes To improve clarity and maintain consistent naming conventions, the following name changes are included in this PR: - `create_address.vy` → create.vy` - `_compute_address_rlp_self` → `_compute_create_address_self` - `_compute_address_rlp` → `_compute_create_address` - `_convert_keccak256_2_address` → `_convert_keccak256_to_address` - `create2_address.vy` → `create2.vy` - `_compute_address_self` → `_compute_create2_address_self` - `_compute_address` → `_compute_create2_address` These name changes are **not** backward-compatible and may require code updates in downstream projects. Furthermore, Solidity has released its latest version [`v0.8.30`](https://github.com/ethereum/solidity/releases/tag/v0.8.30). This PR updates the Solidity test files to align with this new version (we keep `evm_version = "cancun"`). --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
### 🕓 Changelog Vyper has recently introduced the new `raw_create` built-in function via PR [#4204](vyperlang/vyper#4204), enabling direct contract creations using the EVM opcodes [`CREATE`](https://www.evm.codes/?fork=cancun#f0) and [`CREATE2`](https://www.evm.codes/?fork=cancun#f5). In response, this PR adds [`CREATE`](https://www.evm.codes/?fork=cancun#f0), [`CREATE2`](https://www.evm.codes/?fork=cancun#f5), and [`CREATE3`](ethereum/EIPs#3171 (i.e. without an initcode factor) utility functions to the corresponding module contracts in 🐍 snekmate. Please note that the current upper limit for the contract creation code is set to `8_192` bytes (\$2^{13}\$). ```vy from snekmate.utils import create as c1 from snekmate.utils import create2 as c2 from snekmate.utils import create3 as c3 @external @payable def deploy_create(init_code: Bytes[8_192]) -> address: return c1._deploy_create(init_code) @external @payable def deploy_create2(salt: bytes32, init_code: Bytes[8_192]) -> address: return c2._deploy_create2(salt, init_code) @external @payable def deploy_create3(salt: bytes32, init_code: Bytes[8_192]) -> address: return c3._deploy_create3(salt, init_code) ``` ###⚠️ Breaking Changes To improve clarity and maintain consistent naming conventions, the following name changes are included in this PR: - `create_address.vy` → create.vy` - `_compute_address_rlp_self` → `_compute_create_address_self` - `_compute_address_rlp` → `_compute_create_address` - `_convert_keccak256_2_address` → `_convert_keccak256_to_address` - `create2_address.vy` → `create2.vy` - `_compute_address_self` → `_compute_create2_address_self` - `_compute_address` → `_compute_create2_address` These name changes are **not** backward-compatible and may require code updates in downstream projects. Furthermore, Solidity has released its latest version [`v0.8.30`](https://github.com/ethereum/solidity/releases/tag/v0.8.30). This PR updates the Solidity test files to align with this new version (we keep `evm_version = "cancun"`). --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
### 🕓 Changelog Vyper has recently introduced the new `raw_create` built-in function via PR [#4204](vyperlang/vyper#4204), enabling direct contract creations using the EVM opcodes [`CREATE`](https://www.evm.codes/?fork=cancun#f0) and [`CREATE2`](https://www.evm.codes/?fork=cancun#f5). In response, this PR adds [`CREATE`](https://www.evm.codes/?fork=cancun#f0), [`CREATE2`](https://www.evm.codes/?fork=cancun#f5), and [`CREATE3`](ethereum/EIPs#3171 (i.e. without an initcode factor) utility functions to the corresponding module contracts in 🐍 snekmate. Please note that the current upper limit for the contract creation code is set to `8_192` bytes (\$2^{13}\$). ```vy from snekmate.utils import create as c1 from snekmate.utils import create2 as c2 from snekmate.utils import create3 as c3 @external @payable def deploy_create(init_code: Bytes[8_192]) -> address: return c1._deploy_create(init_code) @external @payable def deploy_create2(salt: bytes32, init_code: Bytes[8_192]) -> address: return c2._deploy_create2(salt, init_code) @external @payable def deploy_create3(salt: bytes32, init_code: Bytes[8_192]) -> address: return c3._deploy_create3(salt, init_code) ``` ###⚠️ Breaking Changes To improve clarity and maintain consistent naming conventions, the following name changes are included in this PR: - `create_address.vy` → create.vy` - `_compute_address_rlp_self` → `_compute_create_address_self` - `_compute_address_rlp` → `_compute_create_address` - `_convert_keccak256_2_address` → `_convert_keccak256_to_address` - `create2_address.vy` → `create2.vy` - `_compute_address_self` → `_compute_create2_address_self` - `_compute_address` → `_compute_create2_address` These name changes are **not** backward-compatible and may require code updates in downstream projects. Furthermore, Solidity has released its latest version [`v0.8.30`](https://github.com/ethereum/solidity/releases/tag/v0.8.30). This PR updates the Solidity test files to align with this new version (we keep `evm_version = "cancun"`). --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
What I did
implement #3710
How I did it
How to verify it
Commit message
Description for the changelog
Cute Animal Picture