-
-
Notifications
You must be signed in to change notification settings - Fork 836
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[lang]: add raw_create()
builtin
#4204
base: master
Are you sure you want to change the base?
Changes from 2 commits
af85a5c
a4f2935
dc3e377
2704208
394b637
e7025ae
f6caecc
2870bd9
513de70
f77c64a
961c406
26698e6
49ccb9b
8a07ccb
c25430a
b6a6079
6fe48c9
1982adf
96dc6a9
12c1944
080b436
af446b0
eafd506
1aa4e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ | |
from vyper.utils import ( | ||
DECIMAL_DIVISOR, | ||
EIP_170_LIMIT, | ||
EIP_3860_LIMIT, | ||
SHA3_PER_WORD, | ||
MemoryPositions, | ||
bytes_to_int, | ||
|
@@ -1679,6 +1680,45 @@ def build_IR(self, expr, args, kwargs, context): | |
) | ||
|
||
|
||
class RawCreate(_CreateBase): | ||
_id = "raw_create" | ||
_inputs = [("bytecode", BytesT(EIP_3860_LIMIT))] | ||
_has_varargs = True | ||
|
||
def _add_gas_estimate(self, args, should_use_create2): | ||
return _create_addl_gas_estimate(EIP_170_LIMIT, should_use_create2) | ||
|
||
def _build_create_IR(self, expr, args, context, value, salt, revert_on_failure): | ||
initcode = args[0] | ||
ctor_args = args[1:] | ||
|
||
ctor_args = [ensure_in_memory(arg, context) for arg in ctor_args] | ||
|
||
# encode the varargs | ||
to_encode = ir_tuple_from_args(ctor_args) | ||
bufsz = initcode.typ.maxlen + to_encode.typ.abi_type.size_bound() | ||
|
||
buf = context.new_internal_variable(get_type_for_exact_size(bufsz)) | ||
|
||
ret = ["seq"] | ||
|
||
with scope_multi((initcode, value, salt), ("initcode", "value", "salt")) as ( | ||
b1, | ||
(initcode, value, salt), | ||
): | ||
bytecode_len = get_bytearray_length(initcode) | ||
|
||
maxlen = initcode.typ.maxlen | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. this reminds of something: #4202 |
||
total_len = add_ofst(argbuf, argslen) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
ret.append(_create_ir(value, buf, total_len, salt, revert_on_failure)) | ||
|
||
return b1.resolve(IRnode.from_list(ret)) | ||
|
||
|
||
class CreateMinimalProxyTo(_CreateBase): | ||
# create an EIP1167 "minimal proxy" to the target contract | ||
|
||
|
@@ -2683,6 +2723,7 @@ def _try_fold(self, node): | |
"breakpoint": Breakpoint(), | ||
"selfdestruct": SelfDestruct(), | ||
"raw_call": RawCall(), | ||
"raw_create": RawCreate(), | ||
"raw_log": RawLog(), | ||
"raw_revert": RawRevert(), | ||
"create_minimal_proxy_to": CreateMinimalProxyTo(), | ||
|
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 toceil32
, 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