Skip to content
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

remove sha3_32 and sha3_64 pseudo instructions #4357

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions tests/unit/compiler/test_sha3_32.py

This file was deleted.

11 changes: 9 additions & 2 deletions vyper/codegen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from vyper.semantics.types.shortcuts import BYTES32_T, INT256_T, UINT256_T
from vyper.semantics.types.subscriptable import SArrayT
from vyper.semantics.types.user import FlagT
from vyper.utils import GAS_COPY_WORD, GAS_IDENTITY, GAS_IDENTITYWORD, ceil32
from vyper.utils import GAS_COPY_WORD, GAS_IDENTITY, GAS_IDENTITYWORD, MemoryPositions, ceil32

DYNAMIC_ARRAY_OVERHEAD = 1

Expand Down Expand Up @@ -610,7 +610,14 @@ def _get_element_ptr_mapping(parent, key):
if parent.location not in (STORAGE, TRANSIENT): # pragma: nocover
raise TypeCheckFailure(f"bad dereference on mapping {parent}[{key}]")

return IRnode.from_list(["sha3_64", parent, key], typ=subtype, location=parent.location)
ret = [
"seq",
["mstore", MemoryPositions.FREE_VAR_SPACE, parent],
["mstore", MemoryPositions.FREE_VAR_SPACE2, key],
["sha3", MemoryPositions.FREE_VAR_SPACE, 64],
]

return IRnode.from_list(ret, typ=subtype, location=parent.location)


# Take a value representing a memory or storage location, and descend down to
Expand Down
7 changes: 0 additions & 7 deletions vyper/ir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,6 @@ Compare or equal
`(select cond x y)` is similar to `(if cond x y)` but it may evaluate both branches. Whether or not both branches are taken is unspecified. If `cond` is not in `(0, 1)` the behavior is undefined. It is analogous to LLVM `select` and is intended to compile to branchless code.


### SHA3\_32, SHA3\_64

sha3\_32 and sha3\_64 are shortcuts to access the EVM sha3 opcode. They copy the inputs to reserved memory space and then sha3 the input.

`(sha3_32 x)` is equivalent to `(seq (mstore FREE_VAR_SPACE x) (sha3 FREE_VAR_SPACE 32))`, and `(sha3_64 x y)` is equivalent to `(seq (mstore FREE_VAR_SPACE2 y) (mstore FREE_VAR_SPACE x) (sha3 FREE_VAR_SPACE 64))`, where `FREE_VAR_SPACE` and `FREE_VAR_SPACE2` are memory locations reserved by the vyper compiler for scratch space. Their values are currently 0 and 32.


### CEIL32

ceil32 rounds its input up to the nearest multiple of 32. Its behavior is equivalent to the python function
Expand Down
31 changes: 0 additions & 31 deletions vyper/ir/compile_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,37 +564,6 @@ def _height_of(witharg):
o.extend(_assert_false())
return o

# SHA3 a single value
elif code.value == "sha3_32":
o = _compile_to_assembly(code.args[0], withargs, existing_labels, break_dest, height)
o.extend(
[
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"MSTORE",
*PUSH(32),
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"SHA3",
]
)
return o
# SHA3 a 64 byte value
elif code.value == "sha3_64":
o = _compile_to_assembly(code.args[0], withargs, existing_labels, break_dest, height)
o.extend(
_compile_to_assembly(code.args[1], withargs, existing_labels, break_dest, height + 1)
)
o.extend(
[
*PUSH(MemoryPositions.FREE_VAR_SPACE2),
"MSTORE",
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"MSTORE",
*PUSH(64),
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"SHA3",
]
)
return o
elif code.value == "select":
# b ^ ((a ^ b) * cond) where cond is 1 or 0
# let t = a ^ b
Expand Down
2 changes: 0 additions & 2 deletions vyper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ def quantize(d: decimal.Decimal, places=MAX_DECIMAL_PLACES, rounding_mode=decima
"seq",
"set",
"sge",
"sha3_32",
"sha3_64",
"sle",
"with",
"label",
Expand Down
12 changes: 0 additions & 12 deletions vyper/venom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,6 @@ Assembly can be inspected with `-f asm`, whereas an opcode view of the final byt
```
- Similar to `stop`, but used for constructor exit. The assembler is expected to jump to a special initcode sequence which returns the runtime code.
- Might translate to something like `_sym__ctor_exit JUMP`.
- `sha3_64`
- ```
out = sha3_64 x y
```
- Shortcut to access the `SHA3` EVM opcode where `out` is the result.
- Essentially translates to
```
PUSH y PUSH FREE_VAR_SPACE MSTORE
PUSH x PUSH FREE_VAR_SPACE2 MSTORE
PUSH 64 PUSH FREE_VAR_SPACE SHA3
```
where `FREE_VAR_SPACE` and `FREE_VAR_SPACE2` are locations reserved by the compiler, set to 0 and 32 respectively.

- `assert`
- ```
Expand Down
1 change: 0 additions & 1 deletion vyper/venom/ir_node_to_venom.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"smod",
"exp",
"sha3",
"sha3_64",
"signextend",
"chainid",
"basefee",
Expand Down
12 changes: 0 additions & 12 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,6 @@ def _generate_evm_for_instruction(
pass
elif opcode == "sha3":
assembly.append("SHA3")
elif opcode == "sha3_64":
assembly.extend(
[
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"MSTORE",
*PUSH(MemoryPositions.FREE_VAR_SPACE2),
"MSTORE",
*PUSH(64),
*PUSH(MemoryPositions.FREE_VAR_SPACE),
"SHA3",
]
)
elif opcode == "assert":
assembly.extend(["ISZERO", "_sym___revert", "JUMPI"])
elif opcode == "assert_unreachable":
Expand Down
Loading