From de11c3d1cbfea0d185dc04367fac575a14fe560f Mon Sep 17 00:00:00 2001 From: Stefano Date: Wed, 11 Oct 2023 11:51:28 +0200 Subject: [PATCH 1/2] add minimal pre-commit setup --- .isort.cfg | 6 ---- .pre-commit-config.yaml | 63 +++++++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 7 +---- requirements.txt | 2 +- 4 files changed, 65 insertions(+), 13 deletions(-) delete mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 9ecf4ef..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -use_parentheses = True -line_length = 80 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..30e2c8d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,63 @@ +# Skip execution of one or more hooks using the SKIP environment variable: +# $ SKIP=pylint git commit -m "foo" +# $ SKIP=mypy,pylint pre-commit run --all-files +# +# If want to disable all hooks while committing, use the --no-verify/-n option: +# $ git commit -n -m "foo" + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: mixed-line-ending + - id: check-case-conflict + # - id: check-executables-have-shebangs + # - id: check-shebang-scripts-are-executable + # - id: fix-byte-order-marker + # - id: fix-encoding-pragma + - id: check-yaml + - id: check-json + # - id: pretty-format-json + - id: check-merge-conflict + - id: check-vcs-permalinks + - id: detect-private-key + - id: debug-statements + - id: requirements-txt-fixer + #- id: check-docstring-first + # - id: name-tests-test + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort (black profile, in place fixes) + args: ["--profile", "black", "--filter-files"] + language: python + types: [python] + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + language: python + types: [python] + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + name: black (in place fixes) + # args: [--diff, --check] + # It is recommended to specify the latest version of Python + # supported by your project here, or alternatively use + # pre-commit's default_language_version, see + # https://pre-commit.com/#top_level-default_language_version + # language_version: python3.11 + language: python + types: [python] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy + additional_dependencies: [types-requests] + language: python + types: [python] diff --git a/requirements-dev.txt b/requirements-dev.txt index 702b366..6f52a3d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,10 +1,5 @@ # packages required to develop, build, and test bbt pip +pre-commit wheel - -black -flake8 -isort -mypy -pylint diff --git a/requirements.txt b/requirements.txt index 881ac07..3ba81bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ btclib -matplot ipykernel +matplot pandas From 3fe0f267c27954e3532a8f323716379aa154a62b Mon Sep 17 00:00:00 2001 From: Stefano Date: Wed, 11 Oct 2023 11:52:50 +0200 Subject: [PATCH 2/2] commit automatic changes by pre-commit hooks --- README.md | 4 +- ipynb/PartialHashInversion.ipynb | 2 +- ipynb/field_table.ipynb | 2 +- lab-tutorial/01.md | 7 +- py-scripts/bms_example1.py | 5 +- py-scripts/curves.py | 72 +++++++++---------- py-scripts/det_keychain_type1.py | 3 +- py-scripts/det_keychain_type2.py | 3 +- py-scripts/diffie_hellman.py | 2 +- py-scripts/dsa_example1.py | 6 +- py-scripts/dsa_example2.py | 4 +- py-scripts/ec_explorer.py | 6 +- py-scripts/hash_puzzle.py | 3 +- py-scripts/rfc6979.py | 2 +- py-scripts/signature_schemes.py | 2 +- py-scripts/speedup_batchval.py | 1 - py-scripts/speedup_curvemult.py | 2 +- py-scripts/speedup_doubleandadd.py | 2 +- py-scripts/speedup_fixwind.py | 2 +- py-scripts/speedup_jacobian.py | 2 +- py-scripts/speedup_shamir.py | 2 +- py-scripts/ssa_example1.py | 2 +- regtest-lab/windows.md | 12 ++-- regtest-lab/windowsbat/mainnet-8333.bat | 2 +- .../windowsbat/regtest-18444-start-Alice.bat | 2 +- regtest-lab/windowsbat/testnet3-18333.bat | 2 +- 26 files changed, 73 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index d89d81a..00ea53a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Bitcoin and Blockchain Technology -University of Milano-Bicocca -Politecnico di Milano +University of Milano-Bicocca +Politecnico di Milano University of Milano The latest version of the course slides is available from the course page at . diff --git a/ipynb/PartialHashInversion.ipynb b/ipynb/PartialHashInversion.ipynb index 2f2ef4b..9cbb1fe 100644 --- a/ipynb/PartialHashInversion.ipynb +++ b/ipynb/PartialHashInversion.ipynb @@ -221,4 +221,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/ipynb/field_table.ipynb b/ipynb/field_table.ipynb index b0b2ac0..77c1e97 100644 --- a/ipynb/field_table.ipynb +++ b/ipynb/field_table.ipynb @@ -753,4 +753,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/lab-tutorial/01.md b/lab-tutorial/01.md index 4344262..c162f4c 100644 --- a/lab-tutorial/01.md +++ b/lab-tutorial/01.md @@ -9,7 +9,7 @@ To generate the private key on [bitaddress.org](http://bitaddress.org), we move [![bitaddress wallet](image/bitaddress_end.png)](http://bitaddress.org) -The private key is the alphanumerical string in the bottom-right of the box, in this example: +The private key is the alphanumerical string in the bottom-right of the box, in this example: `Kx6XvUyToSE1o9eWmVimdyQhrp8ANCM2HGUhXxdNUsrroNnGaRNa` @@ -35,7 +35,7 @@ We can now go to the "addresses" tab and see our Bitcoin address, that must be t ![electrum addresses](image/electrum_addresses_screen.png) ## Sign a message using Electrum -We are now ready to sign a message using our new Bitcoin wallet. +We are now ready to sign a message using our new Bitcoin wallet. To sign a message we go to "Instruments -> Sign/Verify message" and we insert the following data: - the message, for example here we will use `"My first digital signature"` - the Bitcoin address associated to our private key, in this example: `13QGCc9EBUtLCTbxDXjNok66hhWgN4SHv7` @@ -64,7 +64,7 @@ If we click on "Verify" we obtain: ![electrum start](image/electrum_signverify_screen_4.png) -Please note that if we changed even a single character in the message, the digital signature is no longer valid. +Please note that if we changed even a single character in the message, the digital signature is no longer valid. For example we remove "!" in the message: @@ -82,4 +82,3 @@ The scope of this exercise is to check the transaction history and the balance o We can even search the transaction history of the previously created Bitcoin address, in this example `13QGCc9EBUtLCTbxDXjNok66hhWgN4SHv7` . Since it is a new address, the transactions history is empty and the balance is equal to 0: ![electrum start](image/esplora_search_1.png) - diff --git a/py-scripts/bms_example1.py b/py-scripts/bms_example1.py index 906202c..4342deb 100644 --- a/py-scripts/bms_example1.py +++ b/py-scripts/bms_example1.py @@ -8,14 +8,13 @@ # No part of btclib including this file, may be copied, modified, propagated, # or distributed except according to the terms contained in the LICENSE file. -from btclib.b58 import p2pkh, p2wpkh_p2sh -from btclib.b58 import wif_from_prv_key from btclib.b32 import p2wpkh +from btclib.b58 import p2pkh, p2wpkh_p2sh, wif_from_prv_key from btclib.ecc.bms import sign, verify from btclib.to_prv_key import prv_keyinfo_from_prv_key from btclib.to_pub_key import pub_keyinfo_from_prv_key -msg = "Paolo is afraid of ephemeral random numbers".encode() +msg = b"Paolo is afraid of ephemeral random numbers" print("\n0. Message:", msg.decode()) wif = b"Kx45GeUBSMPReYQwgXiKhG9FzNXrnCeutJp4yjTd5kKxCitadm3C" diff --git a/py-scripts/curves.py b/py-scripts/curves.py index f490f9d..342178a 100644 --- a/py-scripts/curves.py +++ b/py-scripts/curves.py @@ -7,7 +7,6 @@ # # No part of btclib including this file, may be copied, modified, propagated, # or distributed except according to the terms contained in the LICENSE file. - """Elliptic curves. * SEC 2 v.2 curves @@ -20,7 +19,6 @@ * Brainpool_params standard curves https://tools.ietf.org/html/rfc5639 * test curves with very low cardinality - """ # scroll down at the end of the file for 'relevant' code @@ -35,7 +33,7 @@ # http://www.secg.org/SEC2-Ver-1.0.pdf SEC2v1_params = {} -p = (2 ** 128 - 3) // 76439 +p = (2**128 - 3) // 76439 a = 0xDB7C2ABF62E35E668076BEAD2088 b = 0x659EF8BA043916EEDE8911702B22 Gx = 0x09487239995A5EE76B55F9C2F098 @@ -44,7 +42,7 @@ h = 1 SEC2v1_params["secp112r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = (2 ** 128 - 3) // 76439 +p = (2**128 - 3) // 76439 a = 0x6127C24C05F38A0AAAF65C0EF02C b = 0x51DEF1815DB5ED74FCC34C85D709 Gx = 0x4BA30AB5E892B4E1649DD0928643 @@ -53,7 +51,7 @@ h = 4 SEC2v1_params["secp112r2"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 128 - 2 ** 97 - 1 +p = 2**128 - 2**97 - 1 a = 0xFFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC b = 0xE87579C11079F43DD824993C2CEE5ED3 Gx = 0x161FF7528B899B2D0C28607CA52C5B86 @@ -62,7 +60,7 @@ h = 1 SEC2v1_params["secp128r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 128 - 2 ** 97 - 1 +p = 2**128 - 2**97 - 1 a = 0xD6031998D1B3BBFEBF59CC9BBFF9AEE1 b = 0x5EEEFCA380D02919DC2C6558BB6D8A5D Gx = 0x7B6AA5D85E572983E6FB32A7CDEBC140 @@ -72,15 +70,15 @@ SEC2v1_params["secp128r2"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] p = ( - 2 ** 160 - - 2 ** 32 - - 2 ** 14 - - 2 ** 12 - - 2 ** 9 - - 2 ** 8 - - 2 ** 7 - - 2 ** 3 - - 2 ** 2 + 2**160 + - 2**32 + - 2**14 + - 2**12 + - 2**9 + - 2**8 + - 2**7 + - 2**3 + - 2**2 - 1 ) a = 0x0000000000000000000000000000000000000000 @@ -91,7 +89,7 @@ h = 1 SEC2v1_params["secp160k1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 160 - 2 ** 31 - 1 +p = 2**160 - 2**31 - 1 a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC b = 0x1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45 Gx = 0x4A96B5688EF573284664698968C38BB913CBFC82 @@ -101,15 +99,15 @@ SEC2v1_params["secp160r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] p = ( - 2 ** 160 - - 2 ** 32 - - 2 ** 14 - - 2 ** 12 - - 2 ** 9 - - 2 ** 8 - - 2 ** 7 - - 2 ** 3 - - 2 ** 2 + 2**160 + - 2**32 + - 2**14 + - 2**12 + - 2**9 + - 2**8 + - 2**7 + - 2**3 + - 2**2 - 1 ) a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70 @@ -128,7 +126,7 @@ # http://www.secg.org/sec2-v2.pdf SEC2v2_params = {} -p = 2 ** 192 - 2 ** 32 - 2 ** 12 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 3 - 1 +p = 2**192 - 2**32 - 2**12 - 2**8 - 2**7 - 2**6 - 2**3 - 1 a = 0 b = 3 Gx = 0xDB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D @@ -137,7 +135,7 @@ h = 1 SEC2v2_params["secp192k1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 192 - 2 ** 64 - 1 +p = 2**192 - 2**64 - 1 a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC b = 0x64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1 Gx = 0x188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012 @@ -146,7 +144,7 @@ h = 1 SEC2v2_params["secp192r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 224 - 2 ** 32 - 2 ** 12 - 2 ** 11 - 2 ** 9 - 2 ** 7 - 2 ** 4 - 2 - 1 +p = 2**224 - 2**32 - 2**12 - 2**11 - 2**9 - 2**7 - 2**4 - 2 - 1 a = 0 b = 5 Gx = 0xA1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C @@ -155,7 +153,7 @@ h = 1 SEC2v2_params["secp224k1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 224 - 2 ** 96 + 1 +p = 2**224 - 2**96 + 1 a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE b = 0xB4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4 Gx = 0xB70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21 @@ -165,7 +163,7 @@ SEC2v2_params["secp224r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] # bitcoin curve -p = 2 ** 256 - 2 ** 32 - 977 +p = 2**256 - 2**32 - 977 a = 0 b = 7 Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 @@ -174,7 +172,7 @@ h = 1 SEC2v2_params["secp256k1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 256 - 2 ** 224 + 2 ** 192 + 2 ** 96 - 1 +p = 2**256 - 2**224 + 2**192 + 2**96 - 1 a = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC b = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B Gx = 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296 @@ -183,7 +181,7 @@ h = 1 SEC2v2_params["secp256r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 384 - 2 ** 128 - 2 ** 96 + 2 ** 32 - 1 +p = 2**384 - 2**128 - 2**96 + 2**32 - 1 a = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC b = 0xB3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF Gx = 0xAA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7 @@ -192,7 +190,7 @@ h = 1 SEC2v2_params["secp384r1"] = [hex(p), hex(a), hex(b), [hex(Gx), hex(Gy)], hex(n), h] -p = 2 ** 521 - 1 +p = 2**521 - 1 a = 0x01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC b = 0x0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00 Gx = 0x00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66 @@ -399,21 +397,21 @@ if __name__ == "__main__": filename = path.join(datadir, "ec_Brainpool.json") - with open(filename, "r") as file_: + with open(filename) as file_: Brainpool_params2 = json.load(file_) assert Brainpool_params == Brainpool_params2 filename = path.join(datadir, "ec_NIST.json") - with open(filename, "r") as file_: + with open(filename) as file_: NIST_params2 = json.load(file_) assert NIST_params == NIST_params2 filename = path.join(datadir, "ec_SEC2v1_insecure.json") - with open(filename, "r") as file_: + with open(filename) as file_: SEC2v1_params2 = json.load(file_) assert SEC2v1_params == SEC2v1_params2 filename = path.join(datadir, "ec_SEC2v2.json") - with open(filename, "r") as file_: + with open(filename) as file_: SEC2v2_params2 = json.load(file_) assert SEC2v2_params == SEC2v2_params2 diff --git a/py-scripts/det_keychain_type1.py b/py-scripts/det_keychain_type1.py index 7a34246..bbaa1ce 100644 --- a/py-scripts/det_keychain_type1.py +++ b/py-scripts/det_keychain_type1.py @@ -7,8 +7,7 @@ # # No part of btclib including this file, may be copied, modified, propagated, # or distributed except according to the terms contained in the LICENSE file. - -""" Deterministic Key Sequence (Type-1)""" +"""Deterministic Key Sequence (Type-1).""" import secrets from hashlib import sha256 as hf diff --git a/py-scripts/det_keychain_type2.py b/py-scripts/det_keychain_type2.py index d594515..f3a21f4 100644 --- a/py-scripts/det_keychain_type2.py +++ b/py-scripts/det_keychain_type2.py @@ -7,8 +7,7 @@ # # No part of btclib including this file, may be copied, modified, propagated, # or distributed except according to the terms contained in the LICENSE file. - -""" Deterministic Key Sequence (Type-1)""" +"""Deterministic Key Sequence (Type-1).""" import secrets from hashlib import sha256 as hf diff --git a/py-scripts/diffie_hellman.py b/py-scripts/diffie_hellman.py index cc1ec41..632332d 100644 --- a/py-scripts/diffie_hellman.py +++ b/py-scripts/diffie_hellman.py @@ -1,9 +1,9 @@ from hashlib import sha256 as hf from btclib import dsa +from btclib.dh import ansi_x9_63_kdf from btclib.ecc.curve import mult from btclib.ecc.curve import secp256k1 as ec -from btclib.dh import ansi_x9_63_kdf # Diffie-Hellman print("\n Diffie-Hellman") diff --git a/py-scripts/dsa_example1.py b/py-scripts/dsa_example1.py index 4ab5ef5..d5b610c 100644 --- a/py-scripts/dsa_example1.py +++ b/py-scripts/dsa_example1.py @@ -10,8 +10,8 @@ from btclib.ecc.curve import mult from btclib.ecc.curve import secp256k1 as ec -from btclib.ecc.dsa import recover_pub_keys, sign, verify from btclib.ecc.der import Sig +from btclib.ecc.dsa import recover_pub_keys, sign, verify print("\n*** EC:") print(ec) @@ -25,7 +25,7 @@ print("\n1. Message to be signed") -msg1 = "Paolo is afraid of ephemeral random numbers".encode() +msg1 = b"Paolo is afraid of ephemeral random numbers" print(msg1.decode()) print("2. Sign message") @@ -53,7 +53,7 @@ print("\n1. Another message to sign") -msg2 = "and Paolo is right to be afraid".encode() +msg2 = b"and Paolo is right to be afraid" print(msg2.decode()) print("2. Sign message") diff --git a/py-scripts/dsa_example2.py b/py-scripts/dsa_example2.py index b9c05ac..ec81445 100644 --- a/py-scripts/dsa_example2.py +++ b/py-scripts/dsa_example2.py @@ -31,7 +31,7 @@ print("\n1. Message to be signed") -msg1 = "Paolo is afraid of ephemeral random numbers".encode() +msg1 = b"Paolo is afraid of ephemeral random numbers" print(msg1.decode()) print("2. Sign message") @@ -92,7 +92,7 @@ print("\n1. Another message to sign") -msg2 = "and Paolo is right to be afraid".encode() +msg2 = b"and Paolo is right to be afraid" print(msg2.decode()) print("2. Sign message") diff --git a/py-scripts/ec_explorer.py b/py-scripts/ec_explorer.py index 9e5c3c1..978a4d6 100644 --- a/py-scripts/ec_explorer.py +++ b/py-scripts/ec_explorer.py @@ -25,7 +25,7 @@ def isprime(n): i = 5 w = 2 - while i ** 2 <= n: + while i**2 <= n: if n % i == 0: return False @@ -136,7 +136,7 @@ def isprime(n): gy = -1 while gy == -1: y2 = ( - (gx ** 2 + maxorderlessthanprimea) * gx + maxorderlessthanprimeb + (gx**2 + maxorderlessthanprimea) * gx + maxorderlessthanprimeb ) % prime try: y = mod_sqrt(y2, prime) @@ -171,7 +171,7 @@ def isprime(n): gx = 0 gy = -1 while gy == -1: - y2 = ((gx ** 2 + maxordera) * gx + maxorderb) % prime + y2 = ((gx**2 + maxordera) * gx + maxorderb) % prime try: y = mod_sqrt(y2, prime) assert (y * y) % prime == y2 diff --git a/py-scripts/hash_puzzle.py b/py-scripts/hash_puzzle.py index edc53ce..f4d4f08 100644 --- a/py-scripts/hash_puzzle.py +++ b/py-scripts/hash_puzzle.py @@ -10,7 +10,6 @@ import hashlib import time -from typing import List import matplotlib.pyplot as plt # type: ignore @@ -26,7 +25,7 @@ print(f"{zeros} required zeros") # n[i] is used to count the results starting with i+1 zeros -n: List[int] = [] +n: list[int] = [] maxEval = pow(16, zeros + 1) i = j = nonce = 0 start = time.time() diff --git a/py-scripts/rfc6979.py b/py-scripts/rfc6979.py index 0f09d71..4ac9a20 100644 --- a/py-scripts/rfc6979.py +++ b/py-scripts/rfc6979.py @@ -421,6 +421,6 @@ json.dump(mydict, json_file, sort_keys=True, indent=4) if __name__ == "__main__": - with open(filename, "r") as f: + with open(filename) as f: mydict2 = json.load(f) assert mydict == mydict2 diff --git a/py-scripts/signature_schemes.py b/py-scripts/signature_schemes.py index 2d1fb49..202fce3 100644 --- a/py-scripts/signature_schemes.py +++ b/py-scripts/signature_schemes.py @@ -1,6 +1,6 @@ from btclib.ecc import bms, dsa, ssa -msg = "Hello, I'm Alice!".encode() +msg = b"Hello, I'm Alice!" print("\n", msg.decode()) # ECDSA diff --git a/py-scripts/speedup_batchval.py b/py-scripts/speedup_batchval.py index 3da946c..3957c8b 100644 --- a/py-scripts/speedup_batchval.py +++ b/py-scripts/speedup_batchval.py @@ -29,7 +29,6 @@ Q = [mult(qq, ec.G)[0] for qq in q] for n in n_sig: - # no batch start = time.time() for j in range(n): diff --git a/py-scripts/speedup_curvemult.py b/py-scripts/speedup_curvemult.py index 1589a40..7dddc6a 100644 --- a/py-scripts/speedup_curvemult.py +++ b/py-scripts/speedup_curvemult.py @@ -11,7 +11,6 @@ import random import time -from btclib.ecc.curve import secp256k1 as ec from btclib.curvegroup import ( _mult, _mult_base_3, @@ -27,6 +26,7 @@ _mult_sliding_window, _mult_w_NAF, ) +from btclib.ecc.curve import secp256k1 as ec # setup random.seed(42) diff --git a/py-scripts/speedup_doubleandadd.py b/py-scripts/speedup_doubleandadd.py index e22fb6b..6324c91 100644 --- a/py-scripts/speedup_doubleandadd.py +++ b/py-scripts/speedup_doubleandadd.py @@ -11,13 +11,13 @@ import random import time -from btclib.ecc.curve import secp256k1 as ec from btclib.curvegroup import ( _mult_aff, _mult_jac, _mult_recursive_aff, _mult_recursive_jac, ) +from btclib.ecc.curve import secp256k1 as ec # setup random.seed(42) diff --git a/py-scripts/speedup_fixwind.py b/py-scripts/speedup_fixwind.py index 06d780b..ee8d867 100644 --- a/py-scripts/speedup_fixwind.py +++ b/py-scripts/speedup_fixwind.py @@ -11,13 +11,13 @@ import random import time -from btclib.ecc.curve import secp256k1 as ec from btclib.curvegroup import ( _mult_base_3, _mult_fixed_window, _mult_jac, _mult_mont_ladder, ) +from btclib.ecc.curve import secp256k1 as ec # setup random.seed(42) diff --git a/py-scripts/speedup_jacobian.py b/py-scripts/speedup_jacobian.py index 40a1233..7cd44a1 100644 --- a/py-scripts/speedup_jacobian.py +++ b/py-scripts/speedup_jacobian.py @@ -11,8 +11,8 @@ import random import time -from btclib.ecc.curve import secp256k1 as ec from btclib.curvegroup import _mult_aff, _mult_jac +from btclib.ecc.curve import secp256k1 as ec random.seed(42) diff --git a/py-scripts/speedup_shamir.py b/py-scripts/speedup_shamir.py index 1b6d47a..a197be9 100644 --- a/py-scripts/speedup_shamir.py +++ b/py-scripts/speedup_shamir.py @@ -11,8 +11,8 @@ import random import time -from btclib.ecc.curve import secp256k1 as ec from btclib.curvegroup import _double_mult, _mult +from btclib.ecc.curve import secp256k1 as ec random.seed(42) diff --git a/py-scripts/ssa_example1.py b/py-scripts/ssa_example1.py index d896e8e..bbfe7a5 100644 --- a/py-scripts/ssa_example1.py +++ b/py-scripts/ssa_example1.py @@ -12,7 +12,7 @@ from btclib.ecc.curve import mult from btclib.ecc.curve import secp256k1 as ec -from btclib.ecc.ssa import sign, verify, Sig +from btclib.ecc.ssa import Sig, sign, verify print("\n*** EC:") print(ec) diff --git a/regtest-lab/windows.md b/regtest-lab/windows.md index 24fb352..89ee40a 100644 --- a/regtest-lab/windows.md +++ b/regtest-lab/windows.md @@ -1,21 +1,21 @@ # Bitcoin Core Setup (Windows) 1. Download and install Bitcoin Core from . You can pick one of the following two version: - * portable version (zip) ; - unzip it in your favorite location; + * portable version (zip) ; + unzip it in your favorite location; in the following `C:\your\bitcoinfolder` is where the `bin`, `include`, `lib`, and `share` folders are located - * regular version (exe) ; - execute the installer; + * regular version (exe) ; + execute the installer; in the following `C:\your\bitcoinfolder` is where the `bin`, `include`, `lib`, and `share` folders are located (usually it should be `C:\Program Files\Bitcoin\bitcoin-qt.exe`) 2. add the `C:\your\bitcoinfolder\bin folder` (the one including the `bitcoinqt`, `bitcoind`, and `bitcoin-cli` executables) to your %PATH% environment variable, so that whenever you will call the bitcoin executables from the command line, Windows will know where to find them even if you are not in the `c:\your\bitcoinfolder\bin` folder. You can do this -[permanently](https://stackoverflow.com/questions/44272416/how-to-add-a-folder-to-path-environment-variable-in-windows-10-with-screensho), or for each command prompt window +[permanently](https://stackoverflow.com/questions/44272416/how-to-add-a-folder-to-path-environment-variable-in-windows-10-with-screensho), or for each command prompt window ``` > ECHO %PATH% > SET PATH=%PATH%;c:\your\bitcoinfolder\bin > ECHO %PATH% ``` - + 3. open a command prompt window (with the `C:\your\bitcoinfolder\bin` augmented PATH) and start the Bitcoin Core GUI+deamon in regtest mode: ``` > bitcoinqt -regtest -addresstype=bech32 -walletrbf=1 -server -rpcallowip=127.0.0.1 diff --git a/regtest-lab/windowsbat/mainnet-8333.bat b/regtest-lab/windowsbat/mainnet-8333.bat index 5d3c929..0ac0c47 100644 --- a/regtest-lab/windowsbat/mainnet-8333.bat +++ b/regtest-lab/windowsbat/mainnet-8333.bat @@ -1,2 +1,2 @@ start bin\bitcoin-qt.exe -server -rpcallowip=127.0.0.1 -disablewallet -uacomment=portable -::start cmd /k cd bin \ No newline at end of file +::start cmd /k cd bin diff --git a/regtest-lab/windowsbat/regtest-18444-start-Alice.bat b/regtest-lab/windowsbat/regtest-18444-start-Alice.bat index 3d652f4..bb9e0fc 100644 --- a/regtest-lab/windowsbat/regtest-18444-start-Alice.bat +++ b/regtest-lab/windowsbat/regtest-18444-start-Alice.bat @@ -1,2 +1,2 @@ start bin\bitcoin-qt.exe -regtest -server -rpcallowip=127.0.0.1 -txindex -uacomment=Alice -addresstype=bech32 -walletrbf -::start cmd /k cd bin \ No newline at end of file +::start cmd /k cd bin diff --git a/regtest-lab/windowsbat/testnet3-18333.bat b/regtest-lab/windowsbat/testnet3-18333.bat index 1f0e9eb..fe9d48a 100644 --- a/regtest-lab/windowsbat/testnet3-18333.bat +++ b/regtest-lab/windowsbat/testnet3-18333.bat @@ -1,2 +1,2 @@ start bin\bitcoin-qt.exe -testnet -server -rpcallowip=127.0.0.1 -uacomment=portable -::start cmd /k cd bin \ No newline at end of file +::start cmd /k cd bin