Skip to content

Commit 74c804d

Browse files
authored
Merge pull request #11765 from ethereum/fix_byte_formal
Fix implementation of BYTE
2 parents a356059 + f6789de commit 74c804d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

test/formal/byte_big.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from rule import Rule
2+
from opcodes import *
3+
4+
"""
5+
byte(A, X) -> 0
6+
given A >= WordSize / 8
7+
"""
8+
9+
rule = Rule()
10+
11+
n_bits = 256
12+
13+
# Input vars
14+
X = BitVec('X', n_bits)
15+
A = BitVec('A', n_bits)
16+
17+
rule.require(A >= n_bits / 8)
18+
rule.check(BYTE(A, X), 0)

test/formal/opcodes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ def SAR(x, y):
5959

6060
def BYTE(i, x):
6161
bit = (i + 1) * 8
62-
return If(UGT(bit, x.size()), BitVecVal(0, x.size()), (LShR(x, (x.size() - bit))) & 0xff)
62+
return If(
63+
UGT(i, x.size() / 8 - 1),
64+
BitVecVal(0, x.size()),
65+
(LShR(x, (x.size() - bit))) & 0xff
66+
)

0 commit comments

Comments
 (0)