Skip to content

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Aug 8, 2024

What I did

implement #3710

How I did it

How to verify it

Commit message

this commit adds a `raw_create()` builtin, which executes the
corresponding `CREATE` or `CREATE2` opcode on the provided bytes, as
well as ABI-encoding the provided arguments and appending them to the
provided initcode.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@charles-cooper charles-cooper marked this pull request as draft August 8, 2024 14:01
@charles-cooper charles-cooper added this to the v0.4.1 milestone Aug 8, 2024
@charles-cooper charles-cooper changed the title feat: implement raw_create feat[lang]: add raw_create() builtin Aug 8, 2024
@cyberthirst
Copy link
Collaborator

let's also update the docs please

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)
Copy link
Collaborator

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


argbuf = add_ofst(buf, bytecode_len)
argslen = abi_encode(argbuf, to_encode, context, bufsz=bufsz, returns_len=True)
total_len = add_ofst(argbuf, argslen)
Copy link
Collaborator

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]

@charles-cooper charles-cooper marked this pull request as ready for review August 27, 2024 14:58
bytecode_len = get_bytearray_length(initcode)

maxlen = initcode.typ.maxlen
ret.append(copy_bytes(buf, bytes_data_ptr(initcode), bytecode_len, maxlen))
Copy link
Collaborator

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

@cyberthirst
Copy link
Collaborator

can we please add tests for the rest of the kws?

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.35%. Comparing base (18d0787) to head (48e2039).
Report is 88 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pcaversaccio
Copy link
Collaborator

Can we ship this PR?

Copy link
Collaborator

@pcaversaccio pcaversaccio left a 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. The creation_code information can be super useful here.

@cyberthirst cyberthirst modified the milestones: v0.4.1, v0.4.2 Mar 10, 2025
@charles-cooper charles-cooper added the release - must release blocker label Mar 17, 2025
.. 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.
Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

@charles-cooper charles-cooper enabled auto-merge (squash) March 22, 2025 16:37
@charles-cooper charles-cooper merged commit 61d259a into vyperlang:master Mar 22, 2025
159 checks passed
pcaversaccio added a commit to pcaversaccio/snekmate that referenced this pull request May 15, 2025
### 🕓 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>
willbrown84 added a commit to willbrown84/snekmate that referenced this pull request Sep 23, 2025
### 🕓 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>
void-rider5560p added a commit to void-rider5560p/snekmate that referenced this pull request Sep 28, 2025
### 🕓 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release - must release blocker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants