gottstech / gotts

A blockchain for non-collateralized stable-coins, follow MimbleWimble protocol but with explicit amount.
https://gotts.tech
Apache License 2.0
49 stars 4 forks source link

fix: current_state.current_key_id updating should not stay outside of the lock #27

Closed garyyu closed 4 years ago

garyyu commented 4 years ago

In case of the mineable transactions in tx_pool increased, and if we're resending a updated block to miner, and if a handle_submit just found the share is a new block, there's a race condition here to use the obsoleted self.current_state.current_key_id (which was used in previous block and should be reset for next mining block).

The consequence of this bug is there's possible to update a wrong coinbase output info in miner's wallet, with wrong block rewards (different fees).

For example, I saw a happening here:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Output Commitment                                                   MMR Index  Block Height  Locked Until  Status   Coinbase?  Change?  # Confirms  Value   Tx 
=================================================================================================================================================================

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 090eb8b3fe42bd0c407f5bddd9c786523f6b7fc1589d6fe5cf1e819a9164d90f2d  None       1069          1129          Mining   true       false    0           60.015   
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

And this coinbase output in wallet suddenly change to a wrong one:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 090eb8b3fe42bd0c407f5bddd9c786523f6b7fc1589d6fe5cf1e819a9164d90f2d  None       1069          1130          Unspent  true       false    1           60.008  161 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------