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

Invalid jumpdest analysis for EOFv0 #105

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c35ae4e
script for max call depth analysis
chfast Apr 25, 2024
c7d2a73
analyze malicious bytes
chfast Apr 25, 2024
d82bad0
get top 1000 bytecodes
chfast Apr 29, 2024
1023987
chunk analysis
chfast Apr 29, 2024
4c46f1e
print analysis
chfast Apr 29, 2024
4ff1d18
list of jumpdests
chfast Apr 29, 2024
6e9edc3
intro code analysis
chfast Apr 29, 2024
eae15eb
count totals?
chfast May 7, 2024
7fe70b4
Add initial EOFv0 code
axic Apr 25, 2024
e284b45
delete snapscan
chfast May 7, 2024
ee8e50f
rename → code_analysis.py
chfast May 7, 2024
7a5a663
copy Operations
chfast May 7, 2024
0b91f1b
print chunk index diff
chfast May 7, 2024
92a31ac
fix encoding and print distribution
chfast May 7, 2024
53c1313
compute encoding length
chfast May 7, 2024
e0c3407
dump analysis to csv
chfast May 7, 2024
fa62f48
add csv
chfast May 7, 2024
33a5486
refactor
chfast May 7, 2024
3777ccd
validate encoding
chfast May 7, 2024
ff81327
compute the length in Scheme
chfast May 7, 2024
f013f7b
convert to list[int]
chfast May 7, 2024
19570f9
abstract fixed scheme
chfast May 7, 2024
378a346
cleanup
chfast May 7, 2024
8974bad
leave some skip for value nodes
chfast May 7, 2024
7aaae04
print encoding
chfast May 7, 2024
8c55548
add SKIP_BIAS
chfast May 7, 2024
bbf7022
extract spec constants
chfast May 7, 2024
317fbb4
VALUE_MOD
chfast May 7, 2024
c14a4f8
loop over all schemes
chfast May 7, 2024
6f467d0
provide files as arguments
chfast May 8, 2024
6c17ff3
analyze bytecodes since block 17M
chfast May 8, 2024
04c0ef5
count PUSH1 with zeros
chfast May 8, 2024
f224593
move encoding loop to Scheme.encode()
chfast May 8, 2024
eac6a77
add encoding unit tests
chfast May 8, 2024
86271e7
refactor encode(): dict[int, int]
chfast May 8, 2024
18b5518
refactor: encode_entry()
chfast May 9, 2024
6ec4a84
use VLQ for delta encoding
chfast May 9, 2024
0158cdd
value entry +1
chfast May 9, 2024
3365749
skip +1 (no difference?)
chfast May 9, 2024
979916c
print distribution of encoding chunks
chfast May 9, 2024
3a1a1d3
VLQM33
chfast May 10, 2024
209ccdf
fixup! print distribution of encoding chunks
chfast May 10, 2024
e8a9631
fix logs and record the PUSH with invalid jumpdest
chfast May 13, 2024
b838076
analyze BLOCKHASH
chfast May 13, 2024
1796233
git varint decode
chfast May 21, 2024
a43718e
use git VLQ varint encoding
chfast May 21, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
__pycache__
/corpus
/venv
Empty file added analysis/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions analysis/call_depth_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import matplotlib.pyplot as plt

CALL_COST = 100


def legacy_call_gas(g):
return g - g // 64 - CALL_COST


def eof_call_gas(r, g):
return g - max(g // 64, r) - CALL_COST


def compute_max_depth(call_gas_fn, gas_limit):
g = gas_limit
depth = 0
while g > 0:
g = call_gas_fn(g)
depth += 1
return depth


retaineds = (0, 2300 // 2, 2300, 2 * 2300, 5000, 5000 * 3 // 2, 10000, 15000, 20000, 20000 * 3 // 2)
gas_limits = list(reversed((0.1, 0.5, 1, 2, 5, 30, 60, 120)))
depths = []

for gas_limit in gas_limits:
gl = int(gas_limit * 1_000_000)
depths.append([])
dd = depths[len(depths) - 1]
for r in retaineds:
dd.append(compute_max_depth(lambda g: eof_call_gas(r, g), gl))

plt.figure(figsize=(12, 8))

for i, dd in enumerate(depths):
line = plt.plot(retaineds, dd)
plt.setp(line, label=f"{gas_limits[i]}M")

plt.xlabel("caller min retained gas")
plt.ylabel("max call depth")
plt.xticks(range(0, 30001, 2500))
plt.legend()
plt.grid(True)
plt.show()
Loading
Loading