@@ -7,7 +7,7 @@ use stacks::burnchains::{BurnchainSigner, PrivateKey};
77use stacks:: chainstate:: stacks:: {
88 StacksAddress , StacksPrivateKey , StacksPublicKey , StacksTransactionSigner , TransactionAuth ,
99} ;
10- use stacks:: util:: hash:: Sha256Sum ;
10+ use stacks:: util:: hash:: { Hash160 , Sha256Sum } ;
1111use stacks:: util:: vrf:: { VRFPrivateKey , VRFProof , VRFPublicKey , VRF } ;
1212
1313#[ derive( Clone ) ]
@@ -97,14 +97,18 @@ impl Keychain {
9797 pk
9898 }
9999
100- pub fn rotate_microblock_keypair ( & mut self ) -> StacksPrivateKey {
101- let mut seed = match self . microblocks_secret_keys . last ( ) {
100+ pub fn rotate_microblock_keypair ( & mut self , burn_block_height : u64 ) -> StacksPrivateKey {
101+ let mut secret_state = match self . microblocks_secret_keys . last ( ) {
102102 // First key is the hash of the secret state
103- None => self . hashed_secret_state ,
103+ None => self . hashed_secret_state . to_bytes ( ) . to_vec ( ) ,
104104 // Next key is the hash of the last
105- Some ( last_sk) => Sha256Sum :: from_data ( & last_sk. to_bytes ( ) [ .. ] ) ,
105+ Some ( last_sk) => last_sk. to_bytes ( ) . to_vec ( ) ,
106106 } ;
107107
108+ secret_state. extend_from_slice ( & burn_block_height. to_be_bytes ( ) ) ;
109+
110+ let mut seed = Sha256Sum :: from_data ( & secret_state) ;
111+
108112 // Not every 256-bit number is a valid secp256k1 secret key.
109113 // As such, we continuously generate seeds through re-hashing until one works.
110114 let mut sk = loop {
@@ -116,6 +120,10 @@ impl Keychain {
116120 sk. set_compress_public ( true ) ;
117121 self . microblocks_secret_keys . push ( sk. clone ( ) ) ;
118122
123+ debug ! ( "Microblock keypair rotated" ;
124+ "burn_block_height" => %burn_block_height,
125+ "pubkey_hash" => %Hash160 :: from_node_public_key( & StacksPublicKey :: from_private( & sk) ) . to_string( ) , ) ;
126+
119127 sk
120128 }
121129
0 commit comments