Skip to content
Snippets Groups Projects
Commit 0027abed authored by vincent's avatar vincent
Browse files

BTC Symbolic EXecution: Minor changes

	* Testing timeout raised to 30 s
	* Bug fix for RIPEMD160 which can no longer be imported from
	  hashlib
	* Bug fix: some scripts were badly parsed when no else clauses
were present
parent eb105273
No related branches found
No related tags found
No related merge requests found
"""Implementation of a stack-based machine able to run Bitcoin scripts."""
from copy import deepcopy
import hashlib
from Crypto.Hash import RIPEMD160
from math import ceil, floor, log2
from typing import Any, Callable, Dict, List, Tuple
from symbolic_execution.hardware.memory.ram import Word
......@@ -98,9 +97,9 @@ def int_to_bytes(val: int) -> str:
CHECK_SINGLE_SIG = Function("check_sig", IntSort(), IntSort(), BoolSort())
CHECK_MULTI_SIG = Function("check_multi_sig", IntSort(), IntSort(), BoolSort())
HASH_FUNCTIONS = {
"ripemd160": [Function("ripemd160", IntSort(), IntSort()), RIPEMD160.new, 20],
"sha1": [Function("sha1", IntSort(), IntSort()), hashlib.sha1, 20],
"sha256": [Function("sha256", IntSort(), IntSort()), hashlib.sha256, 32],
"ripemd160": [Function("ripemd160", IntSort(), IntSort()), hashlib.new, 20],
"sha1": [Function("sha1", IntSort(), IntSort()), hashlib.new, 20],
"sha256": [Function("sha256", IntSort(), IntSort()), hashlib.new, 32],
}
......@@ -293,7 +292,7 @@ class BTCVector:
def hash_of_vector(btcVector):
if is_int_value(btcVector.val):
m = py_function(int_to_bytes(simplify(btcVector.val).as_long()))
m = py_function(hash_function_name, int_to_bytes(simplify(btcVector.val).as_long()))
h = m.hexdigest()
return BTCVector(IntVal(str_to_int(h)), IntVal(hash_size))
else:
......
......@@ -177,7 +177,7 @@ class BitcoinParser(ILanguage):
tokens["ELSE_CLAUSES"],
)
)
if "ELSE_CLAUSES" in tokens
if len(tokens["ELSE_CLAUSES"]) > 0
else [InstructionBlock()]
)
......
......@@ -92,7 +92,7 @@ class TestParser(unittest.TestCase):
def test_symbolic_execution(self):
for _, scenario in enumerate(SYMBOLIC_TESTING_SCENARII):
with self.subTest(scenario.hex_script):
_, status = find_unlocking_script(scenario.hex_script, timeout=10)
_, status = find_unlocking_script(scenario.hex_script, timeout=30)
self.assertEqual(status, scenario.execution_status)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment