|
| 1 | +"""Independent EOS updateauth wire vector; no emulator or protobuf required. |
| 2 | +
|
| 3 | +Public key: test mnemonic from common.py, path m/48'/4'/1'/0'/0'. |
| 4 | +The legacy firmware serialized one zero wait because it used accounts_count |
| 5 | +instead of waits_count. Both digests below prove the exact discrepancy. |
| 6 | +""" |
| 7 | +import hashlib |
| 8 | +import struct |
| 9 | +import unittest |
| 10 | + |
| 11 | +pub = bytes.fromhex("037eca30dbc22ecc6d38d95a7e4b49f6b77fa87be608250319b75e2564ccb60143") |
| 12 | + |
| 13 | +def name(s): |
| 14 | + alphabet='.12345abcdefghijklmnopqrstuvwxyz';value=0 |
| 15 | + for x in range(13):value=(value << (5 if x<12 else 4)) | (alphabet.index(s[x]) if x<len(s) else 0) |
| 16 | + return struct.pack('<Q',value) |
| 17 | +def var(x): |
| 18 | + b=bytearray() |
| 19 | + while x>=128:b.append((x&127)|128);x>>=7 |
| 20 | + b.append(x);return bytes(b) |
| 21 | +auth=struct.pack('<I',1)+b'\x01\x01'+pub+struct.pack('<H',1)+b'\x01'+name('memememememe')+name('active')+struct.pack('<H',1)+b'\0' |
| 22 | +prefix=name('memememememe')+name('active')+name('momomomomom') |
| 23 | +header=struct.pack('<IHI',1544644800,0,0)+b'\0\0'+var(13337)+b'\0\x01' |
| 24 | +common=name('eosio')+name('updateauth')+b'\x01'+name('eosio')+name('owner') |
| 25 | +chain=bytes.fromhex('aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906') |
| 26 | + |
| 27 | +class UpdateAuthVector(unittest.TestCase): |
| 28 | + def test_zero_waits(self): |
| 29 | + for extra, expected in [ |
| 30 | + (b"", "5938294e65cf9e8b5dd5f2b204503b4825f277e6f4a2d5ab7a55a31065a23af1"), |
| 31 | + (bytes(6), "fb936ef1be4bda680d93bd10b6d062357d8dd7272038a706dc0d61a91f39c5ee"), |
| 32 | + ]: |
| 33 | + data = prefix + auth + extra |
| 34 | + preimage = chain + header + common + var(len(data)) + data + b"\0" + bytes(32) |
| 35 | + self.assertEqual(hashlib.sha256(preimage).hexdigest(), expected) |
| 36 | + |
| 37 | +if __name__ == "__main__": |
| 38 | + unittest.main() |
0 commit comments