atomkraft icon indicating copy to clipboard operation
atomkraft copied to clipboard

Upon starting testnet from Atomkraft " unsupported hash type ripemd160" error is received

Open dalmirel opened this issue 2 years ago • 1 comments

Environment:

  • Ubuntu 22.04 with python 3.10.6 version (as default)
  • atomkraft 0.1.1
  • openssl 3.0 version

Once I tried to run the testnet for osmosisd and simd with: atomkraft chain testnet

I've encountered the "unsupported hash type ripemd160" error, which led me to openssl version and usage of certain hashlib.py package.

Atomkraft is using hdwallet.py which uses hashlib.py package which eventually uses this ripemd160 cryptographic algorithm in: hashlib.py -> def __get_builtin_constructor(name):

    constructor = cache.get(name)
    if constructor is not None:
        return constructor

    raise ValueError('unsupported hash type ' + name)

I suppose the issue is here - my Atomkraft and python packages analysis stopped with the code lines above.

ripemd160 is disabled by default in new openssl 3.0 version on 22.04 Linux.

Once I enabled the legacy provider in openssl.cfg, testnet was up and running (accounts were successfully created). Commangs for changing openssl.cfg:

$ openssl version -d
$ cd retreived_path_from_cmd_above
$ sudo nano openssl.cfg

Changes is openssl.cfg:

openssl_conf = openssl_init

[openssl_init]
providers = provider_sect

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1

Not sure it this could be a setup/installation consequence, or maybe some additional steps are necessary?

I suppose the issue would be resolved if another hash type is used in hashlib constructor (if this is possible) hdwallet.py: public_key_hash = hashlib.new("ripemd160", sha256(compressed_public_key).digest()).digest()

or installation guidelines should contain guides for setting up Linux with openssl 3.0 to be able to work with atomkraft.

dalmirel avatar Nov 15 '22 08:11 dalmirel

Thanks for the issue, Mirel :ok_hand: Looks like it is coming from terra.py. Somehow I couldn't reproduce this error at atomkraft chain testnet but when running atomkraft test trace.

I am adding reproducible steps on a docker for context.

Reproducible steps

Spawn a docker container using ubuntu image.

docker run --rm -it ubuntu

Then, execute the following commands in it.

apt update -y
apt install -y python3-pip golang git curl default-jre
python3 -m pip install atomkraft
atomkraft init transfer
cd transfer
git clone --depth=1 --branch=release/v0.46.x https://github.com/cosmos/cosmos-sdk
(cd cosmos-sdk; make build)
sed -i 's|simd|cosmos-sdk/build/simd|g' chain.toml
timeout 30 atomkraft chain testnet
curl -Lo models/transfer.tla https://raw.githubusercontent.com/informalsystems/atomkraft/dev/examples/cosmos-sdk/transfer/transfer.tla
atomkraft model apalache get
atomkraft model sample --model-path models/transfer.tla --traces-dir traces --examples Ex
curl -Lo reactors/reactor.py https://raw.githubusercontent.com/informalsystems/atomkraft/dev/examples/cosmos-sdk/transfer/reactor.py
atomkraft test trace --path traces/Ex/violation1.itf.json --reactor reactors/reactor.py --keypath action.tag

Error trace

/usr/local/lib/python3.10/dist-packages/atomkraft/chain/testnet.py:363: in broadcast_transaction
    MnemonicKey(
/usr/local/lib/python3.10/dist-packages/terra_sdk/key/mnemonic.py:63: in __init__
    root.ChildKey(44 + BIP32_HARDEN)
/usr/local/lib/python3.10/dist-packages/bip32utils/BIP32Key.py:241: in ChildKey
    return self.CKDpriv(i)
/usr/local/lib/python3.10/dist-packages/bip32utils/BIP32Key.py:193: in CKDpriv
    return BIP32Key(secret=secret, chain=Ir, depth=self.depth+1, index=i, fpr=self.Fingerprint(), public=False, testnet=self.testnet)
/usr/local/lib/python3.10/dist-packages/bip32utils/BIP32Key.py:283: in Fingerprint
    return self.Identifier()[:4]
/usr/local/lib/python3.10/dist-packages/bip32utils/BIP32Key.py:278: in Identifier
    return hashlib.new('ripemd160', sha256(cK).digest()).digest()
/usr/lib/python3.10/hashlib.py:166: in __hash_new
    return __get_builtin_constructor(name)(data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'ripemd160'

    def __get_builtin_constructor(name):
        cache = __builtin_constructor_cache
        constructor = cache.get(name)
        if constructor is not None:
            return constructor
        try:
            if name in {'SHA1', 'sha1'}:
                import _sha1
                cache['SHA1'] = cache['sha1'] = _sha1.sha1
            elif name in {'MD5', 'md5'}:
                import _md5
                cache['MD5'] = cache['md5'] = _md5.md5
            elif name in {'SHA256', 'sha256', 'SHA224', 'sha224'}:
                import _sha256
                cache['SHA224'] = cache['sha224'] = _sha256.sha224
                cache['SHA256'] = cache['sha256'] = _sha256.sha256
            elif name in {'SHA512', 'sha512', 'SHA384', 'sha384'}:
                import _sha512
                cache['SHA384'] = cache['sha384'] = _sha512.sha384
                cache['SHA512'] = cache['sha512'] = _sha512.sha512
            elif name in {'blake2b', 'blake2s'}:
                import _blake2
                cache['blake2b'] = _blake2.blake2b
                cache['blake2s'] = _blake2.blake2s
            elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512'}:
                import _sha3
                cache['sha3_224'] = _sha3.sha3_224
                cache['sha3_256'] = _sha3.sha3_256
                cache['sha3_384'] = _sha3.sha3_384
                cache['sha3_512'] = _sha3.sha3_512
            elif name in {'shake_128', 'shake_256'}:
                import _sha3
                cache['shake_128'] = _sha3.shake_128
                cache['shake_256'] = _sha3.shake_256
        except ImportError:
            pass  # no extension module, this hash is unsupported.
    
        constructor = cache.get(name)
        if constructor is not None:
            return constructor
    
>       raise ValueError('unsupported hash type ' + name)

rnbguy avatar Nov 15 '22 09:11 rnbguy