Skip to content

Commit

Permalink
Remove pysha3 and use hashlib for sha3 (keccak)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekilmer committed Jan 15, 2023
1 parent 808d006 commit 19bd0be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions manticore/ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid

import re
import sha3
import hashlib

from . import abitypes
from ..core.smtlib import (
Expand Down Expand Up @@ -198,7 +198,7 @@ def function_selector(method_name_and_signature):
"""
Makes a function hash id from a method signature
"""
s = sha3.keccak_256()
s = hashlib.sha3_256()
s.update(method_name_and_signature.encode())
return bytes(s.digest()[:4])

Expand Down
14 changes: 7 additions & 7 deletions manticore/platforms/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import pyevmasm as EVMAsm
import logging
from collections import namedtuple
import sha3
import hashlib
import rlp

logger = logging.getLogger(__name__)
Expand All @@ -60,7 +60,7 @@
def globalsha3(data):
if issymbolic(data):
return None
return int(sha3.keccak_256(data).hexdigest(), 16)
return int(hashlib.sha3_256(data).hexdigest(), 16)


def globalfakesha3(data):
Expand Down Expand Up @@ -1647,7 +1647,7 @@ def SHA3_gas(self, start, size):

@concretized_args(size="ALL")
def SHA3(self, start, size):
"""Compute Keccak-256 hash
"""Compute Keccak-256 (sha3-256) hash
If the size is symbolic the potential solutions will be sampled as
defined by the default policy and the analysis will be forked.
The `size` can be considered concrete in this handler.
Expand Down Expand Up @@ -2511,7 +2511,7 @@ def symbolic_function(self, func, data):
self._publish("will_solve", self.constraints, data, "get_value")
data_c = SelectedSolver.instance().get_value(self.constraints, data)
self._publish("did_solve", self.constraints, data, "get_value", data_c)
return int(sha3.keccak_256(data_c).hexdigest(), 16)
return int(hashlib.sha3_256(data_c).hexdigest(), 16)

@property
def PC(self):
Expand Down Expand Up @@ -3040,7 +3040,7 @@ def block_hash(self, block_number=None, force_recent=True):

# We are not maintaining an actual -block-chain- so we just generate
# some hashes for each virtual block
value = sha3.keccak_256((repr(block_number) + "NONCE").encode()).hexdigest()
value = hashlib.sha3_256((repr(block_number) + "NONCE").encode()).hexdigest()
value = int(value, 16)

if force_recent:
Expand Down Expand Up @@ -3095,7 +3095,7 @@ def calculate_new_address(sender=None, nonce=None):
if nonce is None:
# assume that the sender is a contract account, which is initialized with a nonce of 1
nonce = 1
new_address = int(sha3.keccak_256(rlp.encode([sender, nonce])).hexdigest()[24:], 16)
new_address = int(hashlib.sha3_256(rlp.encode([sender, nonce])).hexdigest()[24:], 16)
return new_address

def execute(self):
Expand Down Expand Up @@ -3173,7 +3173,7 @@ def create_account(self, address=None, balance=0, code=None, storage=None, nonce

# adds hash of new address
data = binascii.unhexlify("{:064x}{:064x}".format(address, 0))
value = sha3.keccak_256(data).hexdigest()
value = hashlib.sha3_256(data).hexdigest()
value = int(value, 16)
self._publish("on_concrete_sha3", data, value)

Expand Down
4 changes: 2 additions & 2 deletions tests/auto_generators/make_VMTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def gen_header(testcases):

if any("logs" in testcase for testcase in testcases.values()):
body += """
import sha3
import hashlib
import rlp
from rlp.sedes import (
CountableList,
Expand Down Expand Up @@ -240,7 +240,7 @@ def did_close_transaction_callback(self, state, tx):
# check logs
logs = [Log(unhexlify('{'{'}:040x{'}'}'.format(l.address)), l.topics, solve(l.memlog)) for l in world.logs]
data = rlp.encode(logs)
self.assertEqual(sha3.keccak_256(data).hexdigest(), '{testcase['logs'][2:]}')"""
self.assertEqual(hashlib.sha3_256(data).hexdigest(), '{testcase['logs'][2:]}')"""

return body

Expand Down

0 comments on commit 19bd0be

Please sign in to comment.