Files
txspector-new/check_stack.py
T
2024-06-15 11:27:29 +08:00

33 lines
1.2 KiB
Python

import sys
import json
need_check = [
"ADD", "MUL", "SUB", "DIV", "SDIV", "MOD", "SMOD", "ADDMOD", "MULMOD", "EXP", "SIGNEXTEND", "LT", "GT", "SLT",
"SGT", "EQ", "ISZERO", "AND", "OR", "XOR", "NOT", "BYTE", "SHL", "SHR", "SAR",
"CALLDATACOPY", "CODECOPY", "EXTCODECOPY", "RETURNDATACOPY", "PREVRANDAO", "POP", "SSTORE", "JUMPI", "LOG0"
]
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python3 check_stack.py <path_to_reconstruct_json>")
sys.exit(1)
filepath = sys.argv[1]
codes = {
}
vars = {
}
with open(filepath, 'r') as f:
value = f.read()
codes = json.loads(value)
for code in codes:
if codes[code]["opcode"] in need_check:
arg_count = len(codes[code]["args"])
if codes[code]["args"] != codes[code]["stacks"][-arg_count:]:
if codes[code]["opcode"] == "CALLDATACOPY":
continue
print(codes[code]["args"], codes[code]["stacks"][-arg_count:])
print(codes[code])
print("=====================================")
exit(1)