0LNetworkCommunity / libra-framework

9 stars 32 forks source link

[tools] reconcile duplicate accounts #230

Closed coin1111 closed 5 months ago

coin1111 commented 5 months ago

Some users have accidentally created duplicate accounts. One with a v5 format, and one in a v6 format. The authentication key is the same on both. However, only one of them would be reachable with CLI tools given how the Authkey lookup works. In short we need a procedure for these users to send a key rotation transaction and possibly combine accounts.

How to split legacy (v5) and v6 accounts sharing the same mnemonic

Background

In v5 libra account names were 16 bytes. With an upgrade to v6, new accounts became 32 byte in length, while existing v5 style accounts were upgraded by prepending 16 bytes of zeros to it. E.g. a legacy v5 account looks like as following

00000000000000000000000000000000<16 legacy bytes> 

In Libra v6 or v7, some users created v6 style accounts by using the same mnemonic used to create v5 accounts in the past. However they didn't indicate that this is a legacy v5 account. Instead they supplied the old mnemonic and obtained a new 32 byte v6 account address without leading zeros. If any funds were sent to this v6 style address, then a user ended up with having 2 accounts (v5 and v6) with the same mnemonic. While funds on both accounts are accessible not all tools can work with both accounts at the same time. So we recommend separating these 2 accounts by replacing a mnemonic on one of them. A mnemonic can be replaced by using a builtin key rotatrion mechanism.

To check that a user has indeed 2 accounts with the same mnemonic use whoami tool:

# to get address v5 legacy account
libra-wallet --legacy-address whoami
<enter mnemonic>
owner address: 00000000000000000000000000000000xxxxxxxxxxxxxxxxxxxxx
owner authentication key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# to get address v6 legacy account
libra-wallet  whoami
<enter mnemonic>
owner address: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
owner authentication key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# to check balance on either of the accounts:
libra-query balance <address from whoami>

Note if a balance check shows that only one account exists (v5 or v6), then a key rotation is not needed. A v5 style account can still be used with libra, but a user needs to indicate that this is a legacy account while working with libra tools or carpe.

How to set a new mnemonic for a legacy v5 account

A new mnemonic can be set using a key rotation machanism. This will keep an existing account address. All acounts funds will be accessible with the new mnemonic. An example below shows a key rotation for a legacy account (v5). To rotate key for a v6 account use libra txs WITHOUT --legacy-address option. To obtain a new mnemonic use carpe "create new account" option or use libra-wallet keygen. MAKE SURE TO STORE A NEW MNEMONIC IN A SAFE PLACE.

libra txs --legacy-address  user rotate-key                                                                                                        
Enter your 0L mnemonic:                                                                                  
๐Ÿ”‘                                                                                                       
2024-04-28T17:42:56.514062Z [main] INFO tools/txs/src/submit_transaction.rs:109 using address 00000000000
0000000000000000000007xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                                                    
Enter your 0L mnemonic:                                                                                  
๐Ÿ”‘                                                                                                       
[00:00:00] awaiting transaction response ยท                                                               
2024-04-28T17:45:14.932491Z [main] INFO tools/txs/src/submit_transaction.rs:277 pending tx hash: 0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                                               
transaction success  ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท โœ“                                       
SUCCESS: private key rotated  

Now the v5 account can be accessed using new mnemonic.

0o-de-lally commented 5 months ago

This all looks good. For your documentation above I would replace libra-txs bins with the bundled libra txs ... @coin1111

coin1111 commented 5 months ago

This all looks good. For your documentation above I would replace libra-txs bins with the bundled libra txs ... @coin1111

done