From 8c756b0b2ac19a7dba7c574d8c5b9c5ba741575d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 12 Dec 2023 10:19:52 +0000 Subject: [PATCH] variable rename: `secp256k1_ge` -> `secp256k1_group_order` --- mmgen/protocol.py | 12 ++++++------ test/gentest.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 3328b050..9942e68c 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -189,7 +189,7 @@ class CoinProtocol(MMGenObject): """ Bitcoin and Ethereum protocols inherit from this class """ - secp256k1_ge = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + secp256k1_group_order = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 privkey_len = 32 pubkey_types = ('std',) @@ -201,19 +201,19 @@ class CoinProtocol(MMGenObject): def preprocess_key(self,sec,pubkey_type): # Key must be non-zero and less than group order of secp256k1 curve - if 0 < int.from_bytes(sec,'big') < self.secp256k1_ge: + if 0 < int.from_bytes(sec,'big') < self.secp256k1_group_order: return sec else: # chance of this is less than 1 in 2^127 from .util import die,ymsg pk = int.from_bytes(sec,'big') if pk == 0: # chance of this is 1 in 2^256 die(4,'Private key is zero!') - elif pk == self.secp256k1_ge: # ditto - die(4,'Private key == secp256k1_ge!') - else: + elif pk == self.secp256k1_group_order: # ditto + die(4,'Private key == secp256k1_group_order!') + else: # return key mod group order as the key if not self.cfg.test_suite: ymsg(f'Warning: private key is greater than secp256k1 group order!:\n {sec.hex()}') - return (pk % self.secp256k1_ge).to_bytes(self.privkey_len,'big') + return (pk % self.secp256k1_group_order).to_bytes(self.privkey_len,'big') class DummyWIF: """ diff --git a/test/gentest.py b/test/gentest.py index bf51b3f2..b9be1416 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -348,15 +348,15 @@ def do_ab_test(proto,scfg,addr_type,gen1,kg2,ag,tool,cache_data): ('\nviewkey: {v}' if 'viewkey' in addr_type.extra_attrs else '') + '\naddr: {a}\n' ) - ge = CoinProtocol.Secp256k1.secp256k1_ge + group_order = CoinProtocol.Secp256k1.secp256k1_group_order # test some important private key edge cases: edgecase_sks = ( bytes([0x00]*31 + [0x01]), # min bytes([0xff]*32), # max bytes([0x0f] + [0xff]*31), # produces same key as above for zcash-z - int.to_bytes(ge + 1, 32, 'big'), # bitcoin will reduce - int.to_bytes(ge - 1, 32, 'big'), # bitcoin will not reduce + int.to_bytes(group_order + 1, 32, 'big'), # bitcoin will reduce + int.to_bytes(group_order - 1, 32, 'big'), # bitcoin will not reduce bytes([0x00]*31 + [0xff]), # monero will reduce bytes([0xff]*31 + [0x0f]), # monero will not reduce bytes.fromhex('deadbeef'*8),