Skip to content

Commit 13b2694

Browse files
authored
Merge pull request #11770 from ethereum/byte-equivalence
An equivalence check for the Byte opcode
2 parents 74c804d + a54addc commit 13b2694

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/formal/byte_equivalence.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from rule import Rule
2+
from opcodes import *
3+
4+
"""
5+
Checks that the byte opcode (implemented using shift) is equivalent to a
6+
canonical definition of byte using extract.
7+
"""
8+
9+
rule = Rule()
10+
11+
n_bits = 256
12+
x = BitVec('X', n_bits)
13+
14+
for i in range(0, 32):
15+
# For Byte, i = 0 corresponds to most significant bit
16+
# But for extract i = 0 corresponds to the least significant bit
17+
lsb = 31 - i
18+
rule.check(
19+
BYTE(BitVecVal(i, n_bits), x),
20+
Concat(BitVecVal(0, n_bits - 8), Extract(8 * lsb + 7, 8 * lsb, x))
21+
)

0 commit comments

Comments
 (0)