Skip to content

Commit

Permalink
optimize identity precompile (vyperlang#2488)
Browse files Browse the repository at this point in the history
If we use staticcall, we don't need to pass value=0, saving 2 bytes in
bytecode / 3 gas at runtime

Also, we do not need to have an assert after call to identity (the only
way failure can happen is OOG and by that time it is too late to do
anything anyway).

Related: vyperlang#1929, vyperlang#1930
  • Loading branch information
charles-cooper authored Oct 19, 2021
1 parent 9560c70 commit 93a9579
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vyper/old_codegen/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def make_byte_array_copier(destination, source, pos=None):
if destination.location == "memory" and source.location in ("memory", "code", "calldata"):
if source.location == "memory":
# TODO turn this into an LLL macro: memorycopy
copy_op = ["assert", ["call", ["gas"], 4, 0, "src", "sz", destination, "sz"]]
copy_op = ["staticcall", "gas", 4, "src", "sz", destination, "sz"]
gas_bound = _identity_gas_bound(source.typ.maxlen)
elif source.location == "calldata":
copy_op = ["calldatacopy", destination, "src", "sz"]
Expand Down Expand Up @@ -179,7 +179,7 @@ def make_byte_slice_copier(destination, source, length, max_length, pos=None):
"with",
"_l",
max_length, # CMC 20210917 shouldn't this just be length
["pop", ["call", ["gas"], 4, 0, source, "_l", destination, "_l"]],
["staticcall", "gas", 4, source, "_l", destination, "_l"]
],
typ=None,
annotation=f"copy byte slice dest: {str(destination)}",
Expand Down

0 comments on commit 93a9579

Please sign in to comment.