From 4ebef602f0f0fccc9b9cc50f676ce5acab5be353 Mon Sep 17 00:00:00 2001 From: davidchocholaty Date: Tue, 5 Nov 2024 22:55:41 +0100 Subject: [PATCH] Fix ecdsa error --- requirements.txt | 1 - run.sh | 6 +++++- src/script.py | 6 ++++-- src/transaction.py | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index ed2a25e..746c8a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ ecdsa==0.19.0 pycryptodome==3.20.0 -#sha3==0.2.1 \ No newline at end of file diff --git a/run.sh b/run.sh index f0c97c6..da26132 100755 --- a/run.sh +++ b/run.sh @@ -4,4 +4,8 @@ #venv/bin/pip install --upgrade pip #venv/bin/pip install -r requirements.txt #source /venv/bin/activate -python3 src/main.py --mempool=mempool > output.txt \ No newline at end of file +python3 -m venv venv +venv/bin/pip install --upgrade pip +venv/bin/pip install -r requirements.txt +source venv/bin/activate +python3 src/main.py --mempool=mempool > output.txt diff --git a/src/script.py b/src/script.py index 471a34e..f2304a0 100644 --- a/src/script.py +++ b/src/script.py @@ -3,6 +3,7 @@ import hashlib import ecdsa from src.op_codes import OP_CODES +from Crypto.Hash import RIPEMD160 class InvalidScriptException(Exception): """Custom exception for Script execution errors""" @@ -301,8 +302,9 @@ def op_hash160(self) -> None: raise InvalidScriptException("Cannot HASH160 empty stack") value = self.stack.pop() sha256 = hashlib.sha256(value).digest() - ripemd160 = hashlib.new('ripemd160', sha256).digest() - self.stack.push(ripemd160) + ripemd160 = RIPEMD160.new() + ripemd160.update(sha256) + self.stack.push(ripemd160.digest()) def op_equalverify(self) -> None: """Verify top two stack items are equal""" diff --git a/src/transaction.py b/src/transaction.py index cb905f1..616d1e2 100644 --- a/src/transaction.py +++ b/src/transaction.py @@ -1,7 +1,7 @@ import hashlib import json -from ecdsa import VerifyingKey, SECP256k1, BadSignatureError +#from ecdsa import VerifyingKey, SECP256k1, BadSignatureError from src.script import Script, InvalidScriptException from src.serialize import serialize_transaction @@ -307,4 +307,4 @@ def validate_p2sh_p2wpkh(self, vin_idx, vin): except BadSignatureError: return False - return True """ \ No newline at end of file + return True """