def _recv_Blocks(self, data): print("RECEIVED BLOCKS", len(data)) if len(data) < MIN_BLOCKS: return assert blocks.TransientBlock(rlp.encode( data[0])).number >= blocks.TransientBlock(rlp.encode(data[-1])).number for x in data: enc = rlp.encode(x) tb = blocks.TransientBlock(enc) print tb self.blk_counter += 1 if self.lowest_block is None: self.lowest_block = tb.number else: if self.lowest_block - 1 == tb.number: self.lowest_block = tb.number else: # i.e. newly mined block sent return if tb not in collected_blocks: collected_blocks.append(tb) # exit if we are at the genesis if tb.number == 1: print 'done' for tb in sorted(collected_blocks, key=attrgetter('number')): print 'writing', tb fh.write(tb.rlpdata.encode('hex') + '\n') # LOG line sys.exit(0) # fetch more print("ASKING FOR MORE HASHES", tb.hash.encode('hex'), tb.number) self.send_GetBlockHashes(tb.hash, NUM_BLOCKS_PER_REQUEST)
def _recv_Blocks(self, data): print("RECEIVED BLOCKS", len(data)) if len(data) < MIN_BLOCKS: return assert blocks.TransientBlock(rlp.encode(data[0])).number >= blocks.TransientBlock(rlp.encode(data[-1])).number for x in data: enc = rlp.encode(x) tb = blocks.TransientBlock(enc) print tb self.blk_counter += 1 if self.lowest_block is None: self.lowest_block = tb.number else: if self.lowest_block - 1 == tb.number: self.lowest_block = tb.number else: # i.e. newly mined block sent return if tb not in collected_blocks: collected_blocks.append(tb) # exit if we are at the genesis if tb.number == 1: print 'done' for tb in sorted(collected_blocks, key=attrgetter('number')): print 'writing', tb fh.write(tb.rlpdata.encode('hex') + '\n') # LOG line sys.exit(0) # fetch more print("ASKING FOR MORE HASHES", tb.hash.encode('hex'), tb.number) self.send_GetBlockHashes(tb.hash, NUM_BLOCKS_PER_REQUEST)
def load_raw(): "rlp and hex encoded blocks in multiline file," "each line is in wrong order, which is also expected by chainmanager" data = [] for x in open('tests/raw_remote_blocks_hex.txt'): data.extend(reversed(rlp.decode(x.strip().decode('hex')))) return rlp.encode(list(reversed(data))).encode('hex')
def load_raw(): "rlp and hex encoded blocks in multiline file," "each line is in wrong order, which is also expected by chainmanager" data = [] for x in open("tests/raw_remote_blocks_hex.txt"): data.extend(reversed(rlp.decode(x.strip().decode("hex")))) return rlp.encode(list(reversed(data))).encode("hex")
def test_genesis_hash(): set_db() genesis = blocks.genesis() """ cpp: https://github.com/ethereum/cpp-ethereum/libethereum/BlockInfo.cpp#L64 h256() << sha3EmptyList << h160() << stateRoot << h256() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42)); PoC5 etherpad: https://ethereum.etherpad.mozilla.org/11 Genesis block is: ( B32(0, 0, ...), B32(sha3(B())), B20(0, 0, ...), B32(stateRoot), B32(0, 0, ...), P(2^22), P(0), P(0), P(1000000), P(0), P(0) << B() << B32(sha3(B(42))) ) Genesis hash: 69a7356a245f9dc5b865475ada5ee4e89b18f93c06503a9db3b3630e88e9fb4e YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex 0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (), SHA3(42), (), () Where 0256 refers to the parent and state and transaction root hashes, a 256-bit hash which is all zeroes; 0160 refers to the coinbase address, a 160-bit hash which is all zeroes; 2**22 refers to the difficulty; 0 refers to the timestamp (the Unix epoch); () refers to the extradata and the sequences of both uncles and transactions, all empty. SHA3(42) refers to the SHA3 hash of a byte array of length one whose first and only byte is of value 42. SHA3RLP() values refer to the hashes of the transaction and uncle lists in RLP, both empty. The proof-of-concept series include a development premine, making the state root hash some value stateRoot. The latest documentation should be consulted for the value of the state root. """ h256 = "\x00" * 32 sr = CPP_PoC5_GENESIS_STATE_ROOT_HEX_HASH.decode('hex') genisi_block_defaults = [ ["prevhash", "bin", h256], # h256() ["uncles_hash", "bin", utils.sha3(rlp.encode([]))], # sha3EmptyList ["coinbase", "addr", "0" * 40], # h160() ["state_root", "trie_root", sr], # stateRoot ["tx_list_root", "trie_root", h256], # h256() ["difficulty", "int", 2**22], # c_genesisDifficulty ["number", "int", 0], # 0 ["min_gas_price", "int", 0], # 0 ["gas_limit", "int", 1000000], # 1000000 ["gas_used", "int", 0], # 0 ["timestamp", "int", 0], # 0 ["extra_data", "bin", ""], # "" ["nonce", "bin", utils.sha3(chr(42))], # sha3(bytes(1, 42)); ] cpp_genesis_block = rlp.decode(CPP_PoC5_GENESIS_HEX.decode('hex')) cpp_genesis_header = cpp_genesis_block[0] for i, (name, typ, genesis_default) in enumerate(genisi_block_defaults): # print name, repr(getattr(genesis, name)), repr(genesis_default) assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default assert getattr(genesis, name) == genesis_default assert genesis.hex_hash() == CPP_PoC5_GENESIS_HEX_HASH
def do_test(hex_rlp_encoded_data): from test_chain import get_chainmanager set_db() chain_manager = get_chainmanager() data = rlp.decode(hex_rlp_encoded_data.decode('hex')) transient_blocks = [blocks.TransientBlock(rlp.encode(b)) for b in data] assert len(transient_blocks) == 128 chain_manager.receive_chain(transient_blocks) print chain_manager.head
def do_test(hex_rlp_encoded_data): from test_chain import set_db, get_chainmanager set_db() chain_manager = get_chainmanager() data = rlp.decode(hex_rlp_encoded_data.decode('hex')) transient_blocks = [blocks.TransientBlock(rlp.encode(b)) for b in data] assert len(transient_blocks) == 128 chain_manager.receive_chain(transient_blocks) print chain_manager.head
def test_genesis_hash(genesis_fixture): set_db() genesis = blocks.genesis() """ YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex 0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (), SHA3(42), (), () Where 0256 refers to the parent and state and transaction root hashes, a 256-bit hash which is all zeroes; 0160 refers to the coinbase address, a 160-bit hash which is all zeroes; 2**22 refers to the difficulty; 0 refers to the timestamp (the Unix epoch); () refers to the extradata and the sequences of both uncles and transactions, all empty. SHA3(42) refers to the SHA3 hash of a byte array of length one whose first and only byte is of value 42. SHA3RLP() values refer to the hashes of the transaction and uncle lists in RLP both empty. The proof-of-concept series include a development premine, making the state root hash some value stateRoot. The latest documentation should be consulted for the value of the state root. """ h256 = '\00' * 32 sr = genesis_fixture['genesis_state_root'].decode('hex') genesis_block_defaults = [ ["prevhash", "bin", h256], # h256() ["uncles_hash", "bin", utils.sha3(rlp.encode([]))], # sha3EmptyList ["coinbase", "addr", "0" * 40], # h160() ["state_root", "trie_root", sr], # stateRoot ["tx_list_root", "trie_root", trie.BLANK_ROOT], # h256() ["difficulty", "int", 2 ** 22], # c_genesisDifficulty ["number", "int", 0], # 0 ["min_gas_price", "int", 0], # 0 ["gas_limit", "int", 10 ** 6], # 10**6 for genesis ["gas_used", "int", 0], # 0 ["timestamp", "int", 0], # 0 ["extra_data", "bin", ""], # "" ["nonce", "bin", utils.sha3(chr(42))], # sha3(bytes(1, 42)); ] cpp_genesis_block = rlp.decode( genesis_fixture['genesis_rlp_hex'].decode('hex')) cpp_genesis_header = cpp_genesis_block[0] for i, (name, typ, genesis_default) in enumerate(genesis_block_defaults): assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default assert getattr(genesis, name) == genesis_default assert genesis.hex_hash() == genesis_fixture['genesis_hash'] assert genesis.hex_hash() == utils.sha3( genesis_fixture['genesis_rlp_hex'].decode('hex') ).encode('hex')
def test_genesis_hash(genesis_fixture): set_db() genesis = blocks.genesis() """ YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex 0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (), SHA3(42), (), () Where 0256 refers to the parent and state and transaction root hashes, a 256-bit hash which is all zeroes; 0160 refers to the coinbase address, a 160-bit hash which is all zeroes; 2**22 refers to the difficulty; 0 refers to the timestamp (the Unix epoch); () refers to the extradata and the sequences of both uncles and transactions, all empty. SHA3(42) refers to the SHA3 hash of a byte array of length one whose first and only byte is of value 42. SHA3RLP() values refer to the hashes of the transaction and uncle lists in RLP both empty. The proof-of-concept series include a development premine, making the state root hash some value stateRoot. The latest documentation should be consulted for the value of the state root. """ h256 = '\00' * 32 sr = genesis_fixture['genesis_state_root'].decode('hex') genesis_block_defaults = [ ["prevhash", "bin", h256], # h256() ["uncles_hash", "bin", utils.sha3(rlp.encode([]))], # sha3EmptyList ["coinbase", "addr", "0" * 40], # h160() ["state_root", "trie_root", sr], # stateRoot ["tx_list_root", "trie_root", trie.BLANK_ROOT], # h256() ["difficulty", "int", 2**22], # c_genesisDifficulty ["number", "int", 0], # 0 ["min_gas_price", "int", 0], # 0 ["gas_limit", "int", 10**6], # 10**6 for genesis ["gas_used", "int", 0], # 0 ["timestamp", "int", 0], # 0 ["extra_data", "bin", ""], # "" ["nonce", "bin", utils.sha3(chr(42))], # sha3(bytes(1, 42)); ] cpp_genesis_block = rlp.decode( genesis_fixture['genesis_rlp_hex'].decode('hex')) cpp_genesis_header = cpp_genesis_block[0] for i, (name, typ, genesis_default) in enumerate(genesis_block_defaults): assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default assert getattr(genesis, name) == genesis_default assert genesis.hex_hash() == genesis_fixture['genesis_hash'] assert genesis.hex_hash() == utils.sha3( genesis_fixture['genesis_rlp_hex'].decode('hex')).encode('hex')
def test_genesis_hash(): set_db() genesis = blocks.genesis() """ cpp: https://github.com/ethereum/cpp-ethereum/libethereum/BlockInfo.cpp#L64 h256() << sha3EmptyList << h160() << stateRoot << h256() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42)); PoC5 etherpad: https://ethereum.etherpad.mozilla.org/11 Genesis block is: ( B32(0, 0, ...), B32(sha3(B())), B20(0, 0, ...), B32(stateRoot), B32(0, 0, ...), P(2^22), P(0), P(0), P(1000000), P(0), P(0) << B() << B32(sha3(B(42))) ) Genesis hash: 69a7356a245f9dc5b865475ada5ee4e89b18f93c06503a9db3b3630e88e9fb4e YP: https://raw.githubusercontent.com/ethereum/latexpaper/master/Paper.tex 0256 , SHA3RLP(), 0160 , stateRoot, 0256 , 2**22 , 0, 0, 1000000, 0, 0, (), SHA3(42), (), () Where 0256 refers to the parent and state and transaction root hashes, a 256-bit hash which is all zeroes; 0160 refers to the coinbase address, a 160-bit hash which is all zeroes; 2**22 refers to the difficulty; 0 refers to the timestamp (the Unix epoch); () refers to the extradata and the sequences of both uncles and transactions, all empty. SHA3(42) refers to the SHA3 hash of a byte array of length one whose first and only byte is of value 42. SHA3RLP() values refer to the hashes of the transaction and uncle lists in RLP, both empty. The proof-of-concept series include a development premine, making the state root hash some value stateRoot. The latest documentation should be consulted for the value of the state root. """ h256 = "\x00" * 32 sr = CPP_PoC5_GENESIS_STATE_ROOT_HEX_HASH.decode('hex') genisi_block_defaults = [ ["prevhash", "bin", h256], # h256() ["uncles_hash", "bin", utils.sha3(rlp.encode([]))], # sha3EmptyList ["coinbase", "addr", "0" * 40], # h160() ["state_root", "trie_root", sr], # stateRoot ["tx_list_root", "trie_root", h256], # h256() ["difficulty", "int", 2 ** 22], # c_genesisDifficulty ["number", "int", 0], # 0 ["min_gas_price", "int", 0], # 0 ["gas_limit", "int", 1000000], # 1000000 ["gas_used", "int", 0], # 0 ["timestamp", "int", 0], # 0 ["extra_data", "bin", ""], # "" ["nonce", "bin", utils.sha3(chr(42))], # sha3(bytes(1, 42)); ] cpp_genesis_block = rlp.decode(CPP_PoC5_GENESIS_HEX.decode('hex')) cpp_genesis_header = cpp_genesis_block[0] for i, (name, typ, genesis_default) in enumerate(genisi_block_defaults): # print name, repr(getattr(genesis, name)), repr(genesis_default) assert utils.decoders[typ](cpp_genesis_header[i]) == genesis_default assert getattr(genesis, name) == genesis_default assert genesis.hex_hash() == CPP_PoC5_GENESIS_HEX_HASH
def _recv_Blocks(self, data): print("RECEIVED", len(data)) for x in reversed(data): enc = rlp.encode(x) #tb = blocks.TransientBlock(enc) #print tb self.blk_counter += 1 fh.write(enc.encode('hex') + '\n') # LOG line h = utils.sha3(enc) print('received block %s %d' % (h.encode('hex'), self.blk_counter)) request(self,h)
def test_returnten(): s = tester.state() open(filename, 'w').write(mul2_code) c = s.contract(returnten_code) snapshot = s.snapshot() proof = s.mkspv(tester.k0, c, 0, []) print "Proof length %d" % len(rlp.encode(proof)) s.revert(snapshot) verify = s.verifyspv(tester.k0, c, 0, [], proof=proof) assert verify os.remove(filename)
def _recv_Blocks(self, data): print("RECEIVED", len(data)) for x in reversed(data): enc = rlp.encode(x) #tb = blocks.TransientBlock(enc) #print tb self.blk_counter += 1 fh.write(enc.encode('hex') + '\n') # LOG line h = utils.sha3(enc) print('received block %s %d' % (h.encode('hex'), self.blk_counter)) request(self, h)
def dump_packet(cls, data): """ 4-byte synchronisation token, (0x22400891), a 4-byte "payload size", to be interpreted as a big-endian integer an N-byte RLP-serialised data structure """ payload = rlp.encode(recursive_int_to_big_endian(data)) packet = ienc4(cls.SYNCHRONIZATION_TOKEN) packet += ienc4(len(payload)) packet += payload return packet
def test_hedge(): s, c = test_data_feeds() c2 = s.contract(hedge_code, sender=tester.k0) # Have the first party register, sending 10^16 wei and # asking for a hedge using currency code 500 snapshot = s.snapshot() proof = s.mkspv(tester.k0, c2, 10**16, funid=0, abi=[c, 500]) print "Proof length %d" % len(rlp.encode(proof)) s.revert(snapshot) assert s.verifyspv(tester.k0, c2, 10**16, funid=0, abi=[c, 500], proof=proof) # Have the second party register. It should receive the # amount of units of the second currency that it is # entitled to. Note that from the previous test this is # set to 726 snapshot = s.snapshot() proof = s.mkspv(tester.k2, c2, 10**16, []) print "Proof length %d" % len(rlp.encode(proof)) s.revert(snapshot) assert s.verifyspv(tester.k2, c2, 10**16, [], proof=proof) # Set the price of the asset down to 300 wei snapshot = s.snapshot() proof = s.mkspv(tester.k0, c, 0, funid=0, abi=[500, 300]) print "Proof length %d" % len(rlp.encode(proof)) s.revert(snapshot) assert s.verifyspv(tester.k0, c, 0, funid=0, abi=[500, 300], proof=proof) # Finalize the contract. Expect code 3, meaning a margin call snapshot = s.snapshot() proof = s.mkspv(tester.k0, c2, 0) print "Proof length %d" % len(rlp.encode(proof)) s.revert(snapshot) assert s.verifyspv(tester.k0, c2, 0, [], proof=proof)
def deserialize_child(parent, rlpdata): """ deserialization w/ replaying transactions """ header_args, transaction_list, uncles = rlp.decode(rlpdata) assert len(header_args) == len(blocks.block_structure) kargs = dict(transaction_list=transaction_list, uncles=uncles) # Deserialize all properties for i, (name, typ, default) in enumerate(blocks.block_structure): kargs[name] = utils.decoders[typ](header_args[i]) block = blocks.Block.init_from_parent(parent, kargs['coinbase'], extra_data=kargs['extra_data'], timestamp=kargs['timestamp']) block.finalize() # this is the first potential state change # replay transactions for tx_lst_serialized, _state_root, _gas_used_encoded in transaction_list: tx = transactions.Transaction.create(tx_lst_serialized) logger.debug("data %r", tx.data) logger.debug('applying %r', tx) logger.debug('applying %r', tx.to_dict()) logger.debug('block.gas_used before: %r', block.gas_used) success, output = processblock.apply_transaction(block, tx) logger.debug('block.gas_used after: %r', block.gas_used) logger.debug('success: %r', success) diff = utils.decode_int(_gas_used_encoded) - block.gas_used logger.debug("GAS_USED DIFF %r", diff) assert utils.decode_int(_gas_used_encoded) == block.gas_used assert _state_root.encode('hex') == block.state.root_hash.encode('hex') # checks assert block.prevhash == parent.hash assert block.tx_list_root == kargs['tx_list_root'] assert block.gas_used == kargs['gas_used'] assert block.gas_limit == kargs['gas_limit'] assert block.timestamp == kargs['timestamp'] assert block.difficulty == kargs['difficulty'] assert block.number == kargs['number'] assert block.extra_data == kargs['extra_data'] assert utils.sha3(rlp.encode(block.uncles)) == kargs['uncles_hash'] assert block.state.root_hash.encode('hex') == kargs['state_root'].encode( 'hex') block.uncles_hash = kargs['uncles_hash'] block.nonce = kargs['nonce'] block.min_gas_price = kargs['min_gas_price'] return block
def deserialize_child(parent, rlpdata): """ deserialization w/ replaying transactions """ header_args, transaction_list, uncles = rlp.decode(rlpdata) assert len(header_args) == len(blocks.block_structure) kargs = dict(transaction_list=transaction_list, uncles=uncles) # Deserialize all properties for i, (name, typ, default) in enumerate(blocks.block_structure): kargs[name] = utils.decoders[typ](header_args[i]) block = blocks.Block.init_from_parent(parent, kargs['coinbase'], extra_data=kargs['extra_data'], timestamp=kargs['timestamp']) block.finalize() # this is the first potential state change # replay transactions for tx_lst_serialized, _state_root, _gas_used_encoded in transaction_list: tx = transactions.Transaction.create(tx_lst_serialized) logger.debug("data %r", tx.data) logger.debug('applying %r', tx) logger.debug('applying %r', tx.to_dict()) logger.debug('block.gas_used before: %r', block.gas_used) success, output = processblock.apply_transaction(block, tx) logger.debug('block.gas_used after: %r', block.gas_used) logger.debug('success: %r', success) diff = utils.decode_int(_gas_used_encoded) - block.gas_used logger.debug("GAS_USED DIFF %r", diff) assert utils.decode_int(_gas_used_encoded) == block.gas_used assert _state_root.encode('hex') == block.state.root_hash.encode('hex') # checks assert block.prevhash == parent.hash assert block.tx_list_root == kargs['tx_list_root'] assert block.gas_used == kargs['gas_used'] assert block.gas_limit == kargs['gas_limit'] assert block.timestamp == kargs['timestamp'] assert block.difficulty == kargs['difficulty'] assert block.number == kargs['number'] assert block.extra_data == kargs['extra_data'] assert utils.sha3(rlp.encode(block.uncles)) == kargs['uncles_hash'] assert block.state.root_hash.encode( 'hex') == kargs['state_root'].encode('hex') block.uncles_hash = kargs['uncles_hash'] block.nonce = kargs['nonce'] block.min_gas_price = kargs['min_gas_price'] return block
def _get_block_before_tx(txhash): tx, blk, i = chain_manager.index.get_transaction(txhash.decode('hex')) # get the state we had before this transaction test_blk = Block.init_from_parent(blk.get_parent(), blk.coinbase, extra_data=blk.extra_data, timestamp=blk.timestamp, uncles=blk.uncles) pre_state = test_blk.state_root for i in range(blk.transaction_count): tx_lst_serialized, sr, _ = blk.get_transaction(i) if utils.sha3(rlp.encode(tx_lst_serialized)) == tx.hash: break else: pre_state = sr test_blk.state.root_hash = pre_state return test_blk, tx, i
def _get_block_before_tx(txhash): tx, blk = chain_manager.index.get_transaction(txhash.decode('hex')) # get the state we had before this transaction test_blk = Block.init_from_parent(blk.get_parent(), blk.coinbase, extra_data=blk.extra_data, timestamp=blk.timestamp, uncles=blk.uncles) pre_state = test_blk.state_root for i in range(blk.transaction_count): tx_lst_serialized, sr, _ = blk.get_transaction(i) if utils.sha3(rlp.encode(tx_lst_serialized)) == tx.hash: break else: pre_state = sr test_blk.state.root_hash = pre_state return test_blk, tx
def step_impl(context): total_payload_length = sum(len(rlp.encode(x)) for x in context.src) assert context.dst[0] == chr(0xc0 + total_payload_length)
def step_impl(context): context.dst = rlp.encode(context.src)
def step_impl(context, root_hash): t = context.trie rlp_root = rlp.encode(t._rlp_decode(t.root)) assert trie.sha3(rlp_root).encode('hex') == root_hash
def step_impl(context): assert context.dst[1:] == ''.join(rlp.encode(x) for x in context.src)
def step_impl(context): encodeds = [rlp.encode(x) for x in context.src] assert context.dst[1 + len(context.length_bin):] == ''.join(encodeds)
def step_impl(context): total_payload_length = sum(len(rlp.encode(x)) for x in context.src) context.length_bin = int_to_big_endian(total_payload_length) assert context.dst[0] == chr(0xf7 + len(context.length_bin))
def step_impl(context, data): context.data = data context.encoded_data = rlp.encode( recursive_int_to_big_endian(context.data))
def step_impl(context): with AssertException(TypeError): rlp.encode(context.src)
fixtures 15.10.:f68067286ddb7245c2203b18135456de1fc4ed6a24a2d9014195faa7900025bf py poc6: 08436a4d33c77e6acf013e586a3333ad152f25d31df8b68749d85046810e1f4b fixtures 19.9,: 08436a4d33c77e6acf013e586a3333ad152f25d31df8b68749d85046810e1f4b """ genesis = blocks.genesis(new_db()) assert genesis.hex_hash() == genesis_fixture['genesis_hash'] if __name__ == '__main__': cpp_genesis_rlp_hex = 'f9012ff9012aa00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0' cpp_genesis_rlp = cpp_genesis_rlp_hex.decode('hex') poc7_genesis_hash_hex = '955f36d073ccb026b78ab3424c15cf966a7563aa270413859f78702b9e8e22cb' cpp_genesis = rlp.decode(cpp_genesis_rlp) cpp_genesis_hash_hex = utils.sha3(rlp.encode(cpp_genesis[0])).encode('hex') cpp_header = cpp_genesis[0] cpp_header_hex = [x.encode('hex') for x in cpp_header] py_genesis = rlp.decode(blocks.genesis().serialize()) py_genesis_hex_hash = blocks.genesis().hex_hash() py_header = py_genesis[0] py_header_hex = [x.encode('hex') for x in py_header] print 'py genesis hash hex', py_genesis_hex_hash print 'py state_root', py_header[blocks.block_structure_rev['state_root'] [0]].encode('hex') print 'py genesis rlp', blocks.genesis().hex_serialize() assert len(py_header_hex) == len(cpp_header_hex)
def spvstorage(addr, index): prf1 = chain_manager.head.state.produce_spv_proof(addr.decode('hex')) storetree = chain_manager.head.get_storage(addr) prf2 = storetree.produce_spv_proof(utils.zpad(utils.encode_int(index), 32)) return rlp.encode(prf1 + prf2).encode('hex')