def validate_tx(self): #sanity check: this is not how the economy is supposed to work! if self.amount < 0: printL(('State validation failed for', self.txhash, 'because: Negative send')) return False # cryptographic checks if self.txhash != sha256(''.join(self.txfrom + str(self.pubhash)) + self.txto + str(self.amount) + str(self.fee)): return False # SIG is a list composed of: i, s, auth_route, i_bms, pk[i], PK if self.type != 'TX': return False if merkle.xmss_verify(self.txhash, [ self.i, self.signature, self.merkle_path, self.i_bms, self.pub, self.PK ]) is False: return False if helper.xmss_checkaddress(self.PK, self.txfrom) is False: return False return True
def validate_tx(self): if self.type != 'ST': return False if self.first_hash: if sha256(self.first_hash) != self.hash[-1]: printL((' First_hash doesnt stake to hashterminator ')) return False for i in range(len(self.hash)): self.hash[i] = str(self.hash[i]) if merkle.xmss_verify(str(self.hash), [ self.i, self.signature, self.merkle_path, self.i_bms, self.pub, self.PK ]) is False: return False if helper.xmss_checkaddress(self.PK, self.txfrom) is False: return False return True
def validate_tx(self): # cryptographic checks if self.txhash != sha256(''.join(self.txfrom + str(self.pubhash)) + self.txto + str(self.amount) + str(self.fee)): return False # SIG is a list composed of: i, s, auth_route, i_bms, pk[i], PK if self.type != 'TX': return False if merkle.xmss_verify(self.txhash, [ self.i, self.signature, self.merkle_path, self.i_bms, self.pub, self.PK ]) is False: return False if helper.xmss_checkaddress(self.PK, self.txfrom) is False: return False return True
def validate_block( self, chain, verbose=0, verify_block_reveal_list=True): # check validity of new block.. b = self.blockheader last_block = b.blocknumber - 1 if merkle.xmss_verify( b.headerhash, [b.i, b.signature, b.merkle_path, b.i_bms, b.pub, b.PK]) is False: printL(('BLOCK : merkle xmss_verify failed for the block')) return False if helper.xmss_checkaddress(b.PK, b.stake_selector) is False: printL(('BLOCK : xmss checkaddress failed')) return False if b.timestamp == 0 and b.blocknumber > 0: printL(('Invalid block timestamp ')) return False if b.block_reward != b.block_reward_calc(): printL(('Block reward incorrect for block: failed validation')) return False if b.epoch != b.blocknumber / c.blocks_per_epoch: printL(('Epoch incorrect for block: failed validation')) if b.blocknumber == 1: x = 0 for st in self.stake: if st.txfrom == b.stake_selector: x = 1 hash, _ = chain.select_hashchain( chain.m_blockchain[-1].blockheader.headerhash, b.stake_selector, st.hash, blocknumber=1) if sha256(b.hash) != hash or hash not in st.hash: printL(( 'Hashchain_link does not hash correctly to terminator: failed validation' )) return False if x != 1: printL( ('Stake selector not in block.stake: failed validation')) return False else: # we look in stake_list for the hash terminator and hash to it.. y = 0 terminator = sha256(b.hash) for x in range(b.blocknumber - (b.epoch * c.blocks_per_epoch) + 1): terminator = sha256(terminator) tmp_stake_list = chain.state.stake_list_get() for st in tmp_stake_list: if st[0] == b.stake_selector: y = 1 #hash, _ = chain.select_hashchain(chain.block_chain_buffer.get_strongest_headerhash(last_block), # b.stake_selector, blocknumber=b.blocknumber) if terminator != st[1][-1]: printL(( 'Supplied hash does not iterate to terminator: failed validation' )) return False if y != 1: printL(('Stake selector not in stake_list for this epoch..')) return False ''' This condition not required, in case of a strongest block selected is not in top 3. As it may happen that top 3 winners, didn't create the block, and other node created the block who was not in the top 3 winners. ''' #if b.hash not in chain.select_winners(b.reveal_list, topN=3, blocknumber=b.blocknumber, block=self, seed=chain.block_chain_buffer.get_epoch_seed(b.blocknumber)): # printL(("Closest hash not in block selector..")) # return False if len(b.reveal_list) != len(set(b.reveal_list)): printL(('Repetition in reveal_list')) return False if verify_block_reveal_list: i = 0 for r in b.reveal_list: t = sha256(r) for x in range(b.blocknumber - (b.epoch * c.blocks_per_epoch) + 1): #+1 as reveal has 1 extra hash t = sha256(t) for s in tmp_stake_list: if t == s[1][-1]: i += 1 if i != len(b.reveal_list): printL(('Not all the reveal_hashes are valid..')) return False i = 0 target_chain = helper.select_target_hashchain( b.prev_blockheaderhash) for r in b.vote_hashes: t = sha256(r) for x in range(b.blocknumber - (b.epoch * c.blocks_per_epoch)): t = sha256(t) for s in tmp_stake_list: if t == s[1][target_chain]: i += 1 if i != len(b.vote_hashes): printL(('Not all the reveal_hashes are valid..')) return False if sha256(b.stake_selector + str(b.epoch) + str(b.stake_nonce) + str(b.block_reward) + str(b.timestamp) + str(b.hash) + str(b.blocknumber) + b.prev_blockheaderhash + str(b.number_transactions) + b.merkle_root_tx_hash + str(b.number_stake) + b.hashedstake) != b.headerhash: printL(('Headerhash false for block: failed validation')) return False tmp_last_block = chain.m_get_block(last_block) if tmp_last_block.blockheader.headerhash != b.prev_blockheaderhash: printL(('Headerhash not in sequence: failed validation')) return False if tmp_last_block.blockheader.blocknumber != b.blocknumber - 1: printL(('Block numbers out of sequence: failed validation')) return False if self.validate_tx_in_block() == False: printL(('Block validate_tx_in_block error: failed validation')) return False if self.validate_st_in_block() == False: printL(('Block validate_st_in_block error: failed validation')) return False if len(self.transactions) == 0: txhashes = sha256('') else: txhashes = [] for transaction in self.transactions: txhashes.append(transaction.txhash) if chain.merkle_tx_hash(txhashes) != b.merkle_root_tx_hash: printL(('Block hashedtransactions error: failed validation')) return False sthashes = [] for st in self.stake: sthashes.append(str(st.hash)) if sha256(''.join(sthashes)) != b.hashedstake: printL(('Block hashedstake error: failed validation')) if verbose == 1: printL((b.blocknumber, 'True')) return True