rooch-network / rooch

VApp Container with Move Language
https://rooch.network
Apache License 2.0
128 stars 54 forks source link

[gh-509 and gh-531] improve `rooch init`, `rooch account import`, and `rooch account create` to ECDSA and Schnorr, refactor ETH signature to Rooch signature. #532

Closed feliciss closed 9 months ago

feliciss commented 10 months ago

Resolves #509 and closes #531

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **rooch** | ⬜️ Ignored ([Inspect](https://vercel.com/rooch/rooch/Tnpb4a5juh5pyqPwhVSbiPfNJ5hd)) | | | Jul 27, 2023 0:58am |
feliciss commented 9 months ago

@wow-sven I have added command args for init.rs, create.rs and import.rs according to #509

However, there are several implementation errors, for instance, I can successfully command rooch account create with Ed25519 while others resulting errors:

rooch account create --scheme 3
0x661b491fa5bb7d6c287c2039647c481e97b3d30b46f6f5a74041771c77d27c74
Generated new keypair for address with scheme "schnorr" [0x661b491fa5bb7d6c287c2039647c481e97b3d30b46f6f5a74041771c77d27c74]
Secret Recovery Phrase : [census sudden knife document sick disease flush brand sport head genius warrior]
Sign message error: Cannot find key for address:[0x661b491fa5bb7d6c287c2039647c481e97b3d30b46f6f5a74041771c77d27c74]

rooch account create --scheme 2
0x616aa7030c13095f8966c23c54d1445397672f703eb1b83fea1d23f572f40190
Generated new keypair for address with scheme "ecdsa" [0x616aa7030c13095f8966c23c54d1445397672f703eb1b83fea1d23f572f40190]
Secret Recovery Phrase : [arrive scheme chunk mutual hip twenty tunnel correct fee sign bag high]
Sign message error: Cannot find key for address: [0x616aa7030c13095f8966c23c54d1445397672f703eb1b83fea1d23f572f40190]

rooch account create --scheme 1
thread 'main' panicked at 'not yet implemented', crates/rooch-key/src/key_derive.rs:113:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

rooch account create --scheme 0
0xf19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab1
Generated new keypair for address with scheme "ed25519" [0xf19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab1]
Secret Recovery Phrase : [onion armor erase curtain obvious wear virtual danger used usual leopard hurt]
{
  "sequence_info": {
    "tx_order": "2",
    "tx_order_signature": {
      "scheme": "3",
      "payload": "0x0305da1cd2bfe328183f68231fea70a3b01ce4f80e0804623eff5ff179d889b3c66bb32351a1fedbceb488fe2d35dae29e61d97c09912bf8c40290a9f1afaddd10e81833ca50327fc46910231bf58f2adfac9c3373f4b02b60dbad530b1373dcf2"
    },
    "tx_accumulator_root": "0x046ff90a9897cbbf0fe32119b99275291e67642b1ca526a5733859774f3c8c9d"
  },
  "execution_info": {
    "tx_hash": "0xb75c7ba9db709f23b14e57a4573f8f6f5543876d868da573b8a6fe48a6a0d57a",
    "state_root": "0x6df0ba561d675f171d4c345c791d67852fe003849ce6c17b1b54085f6372762d",
    "event_root": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
    "gas_used": 0,
    "status": {
      "type": "moveabort",
      "location": "0000000000000000000000000000000000000000000000000000000000000002::account_storage",
      "abort_code": "1"
    }
  },
  "output": {
    "status": {
      "type": "moveabort",
      "location": "0000000000000000000000000000000000000000000000000000000000000002::account_storage",
      "abort_code": "1"
    },
    "table_changeset": {
      "new_tables": {},
      "removed_tables": [],
      "changes": {
        "0x0000000000000000000000000000000000000000000000000000000000000000": {
          "entries": {
            "0xf19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab1": {
              "type": "new",
              "value": "0xf19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab1f19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab14aaece3a8934b49892dc3d46591dfd24c2c423760f45328ff9acf7040346169a9d728fd8828095c63dd49afd8947c646f0a749b0fc4257f7cbec74df75bc8f7f",
              "value_type": "0x2::object::Object<0x2::account_storage::AccountStorage>"
            }
          }
        },
        "0x4aaece3a8934b49892dc3d46591dfd24c2c423760f45328ff9acf7040346169a": {
          "entries": {
            "0x52303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030333a3a6163636f756e743a3a4163636f756e74": {
              "type": "new",
              "value": "0x0100000000000000",
              "value_type": "0x3::account::Account"
            }
          }
        }
      }
    },
    "events": [],
    "gas_used": 0
  }
}

Regardless of successfully creating key pair with schnorr and ecdsa schemes in the above examples, when I issue command rooch account list, there is only ed25519 key scheme in the key store:

rooch account list
                          Rooch Address                            |              Public Key (Base64)              | Scheme  | Active
--------------------------------------------------------------------------------------------------------------------------------------
0x18152bf5a89d4cb01fb47b9b2731ddc6034ada02ff72b03d34bb2e32b0de23f3 | AFXbLkeEPQSVE3dX58BScy92ioHYCPVno+Msje1HmtVq  | ed25519 |       
0x324ea18c103aa1b0d7d1631db18ee33b5b928e19fbce2d5475c8db1d012adc53 | AGvGjvPmtZSw+Zze29iYKVof9WLgYnci58pIu6oOhWsU  | ed25519 |       
0x363f6d7738c39a73014639659562ecd2bc931ecc9a260c74bf922d4d5488eb17 | AGoLToYqEFOv725/zMLhrssLZpssMO89FDZ5fO546ifN  | ed25519 |       
0x42797f90b083f6c0e95d734651c0016683a6e4654bc578a407ebbb536d406bd5 | AH/h8G8Nj1OE7mhBUhMhZSqhLRvZSoM/LsYsCrTuln9y  | ed25519 |       
0x677f0bf7cbb5e09045d4c0ccd419205fd671179ce9dc193a24d9cafa26007682 | AP+dVrhGdbfn1IXCJaRoTKCRfZdfXbKB9WCMnpOsNEma  | ed25519 |       
0xc634422187c519504826604ace5b44323b0c9a64501ccf505d05033e3747bf9f | AOK2m78MBrq7NWb03f5m5BICsuYCVpDGVoBz7IRQUeWS  | ed25519 |       
0xf19440a886870fbbc37d3294b80d8270497a8a69795eea26f0db6864fd06aab1 | ADc6VrQvmZ3tHFptABx8TRpI5hZUuTNsRhOmdeYXv4LO  | ed25519 |    

It seems like that the corresponding keys to the addresses have not been saved. Please help review and if it's possible, give me some hints. @wow-sven @jolestar

feliciss commented 9 months ago

Still struggling with the VM validation error for ECDSA:

Transaction error: RPC call failed: ErrorObject { code: ServerError(-32000), message: "validate failed: VMError with status ABORTED with sub status 1 at location Module ModuleId { address: 0000000000000000000000000000000000000000000000000000000000000003, name: Identifier(\"ecdsa_k1\") } at code offset 0 in function definition 3", data: None }

But now it can init, create, although with VM errors for ECDSA and Schnorr, and import with ECDSA, Schnorr and Ed25519 key pairs.

Examples from initiating, creating and importing ECDSA key pair:

  1. Init:
rooch init --scheme 2                                                                                
Creating config file ["/Users/system/.rooch/rooch_config/rooch.yaml"] with custom server and Ecdsa crypto scheme.
Rooch server URL: http://0.0.0.0:50051
Environment alias for [http://0.0.0.0:50051] : de
Generated new keypair for address with scheme "ecdsa" [0xc1741c186205427b8114217fd97d4c3d788644d12bed2584749899ffc53a1c5e]
Secret Recovery Phrase : [fly reduce south sheriff repair round reflect recall purpose benefit family rotate]
"Rooch config file generated at /Users/system/.rooch/rooch_config/rooch.yaml"
rooch account list                                

                          Rooch Address                            |              Public Key (Base64)              | Scheme  | Active
--------------------------------------------------------------------------------------------------------------------------------------
0xc1741c186205427b8114217fd97d4c3d788644d12bed2584749899ffc53a1c5e | AgPfxgvzDhu4+g+lWzQXjTIOqDt29fNRXC2o/lHEuszMAg== | ecdsa  |  True 
  1. Create:
rooch account create --scheme 2                                                                      
0x667c272f6fbefc1905416f36529a8b1df759adcb20fcf24e69751fc0091856a3
Generated new keypair for address with scheme "ecdsa" [0x667c272f6fbefc1905416f36529a8b1df759adcb20fcf24e69751fc0091856a3]
Secret Recovery Phrase : [beauty lonely black garbage soup help guess alone major engine swear admit]
[102, 124, 39, 47, 111, 190, 252, 25, 5, 65, 111, 54, 82, 154, 139, 29, 247, 89, 173, 203, 32, 252, 242, 78, 105, 117, 31, 192, 9, 24, 86, 163]
0x667c272f6fbefc1905416f36529a8b1df759adcb20fcf24e69751fc0091856a3
Transaction error: RPC call failed: ErrorObject { code: ServerError(-32000), message: "validate failed: VMError with status ABORTED with sub status 1 at location Module ModuleId { address: 0000000000000000000000000000000000000000000000000000000000000003, name: Identifier(\"ecdsa_k1\") } at code offset 0 in function definition 3", data: None }
rooch account list 

                          Rooch Address                            |              Public Key (Base64)              | Scheme  | Active
--------------------------------------------------------------------------------------------------------------------------------------
0x667c272f6fbefc1905416f36529a8b1df759adcb20fcf24e69751fc0091856a3 | AgNggb4JyvUuPy49xD7EYeGlix1rfPFyFYNqypu3j07E0g== | ecdsa  |       
0xc1741c186205427b8114217fd97d4c3d788644d12bed2584749899ffc53a1c5e | AgPfxgvzDhu4+g+lWzQXjTIOqDt29fNRXC2o/lHEuszMAg== | ecdsa  |  True 
  1. Import:
rooch account import --scheme 2 "rib remove bar public eager glow image push call surge over alcohol"
"rib remove bar public eager glow image push call surge over alcohol"
Key imported for address [0x50111db264b6de16cd6016417f5fc37452bfad1d4aceb949bf3a3ba9a708b103]
rooch account list                                                                                   

                          Rooch Address                            |              Public Key (Base64)              | Scheme  | Active
--------------------------------------------------------------------------------------------------------------------------------------
0x50111db264b6de16cd6016417f5fc37452bfad1d4aceb949bf3a3ba9a708b103 | AgNo7sat+5yIf9Fprzz8NPsamG+CdT7u8uYw4QAPyg6qyA== | ecdsa  |       
0x667c272f6fbefc1905416f36529a8b1df759adcb20fcf24e69751fc0091856a3 | AgNggb4JyvUuPy49xD7EYeGlix1rfPFyFYNqypu3j07E0g== | ecdsa  |       
0xc1741c186205427b8114217fd97d4c3d788644d12bed2584749899ffc53a1c5e | AgPfxgvzDhu4+g+lWzQXjTIOqDt29fNRXC2o/lHEuszMAg== | ecdsa  |  True 
  1. Keystore:
cat ~/.rooch/rooch_config/rooch.keystore                                                             
[
  "Avh6W01Ie4orlzvQ9Qmhrl5s5fKEwDkwbsCDfyGEcx9g",
  "Ajn8HrgbdsMFS9D3m9brSkTdLU74cY77nhE7ODcz0boR",
  "AqN+D7gFtAaoj6AsT35XY3Ap6TARY194ul2ErPvwLLbz"
]
feliciss commented 9 months ago

You can just implement and test the import command. The account create command need to do some refactor to auth validator.

Ah sad. I'm on a half way implementing account create with correct VM validation. Other commands, such as account import and rooch init, are supported for Ed25519, ECDSA and Schnorr.

jolestar commented 9 months ago

skip the account create command test, and merge this PR.

feliciss commented 9 months ago

skip the account create command test, and merge this PR.

It seems like there's no test for rooch account create command except the ones in cmd.feature file, and merge this PR will result in TransactionError like the above:

Transaction error: RPC call failed: ErrorObject { code: ServerError(-32000), message: "validate failed: VMError with status ABORTED with sub status 1 at location Module ModuleId { address: 0000000000000000000000000000000000000000000000000000000000000003, name: Identifier(\"ecdsa_k1\") } at code offset 0 in function definition 3", data: None }

However, the tests for account create I disabled in cmd.feature file will likely to be passed for the CI.

I also unified the ECDSA crypto scheme just like the others and disabled the serialisation test of ECDSA due to incompatible conversion from Ethereum signature to Rooch signature:

https://github.com/rooch-network/rooch/pull/532/files#diff-e2b13bff975b6a03ca701eef7fd8ca0dc1c002cdb5a9aac583dfcabcbf8142fcR255

feliciss commented 9 months ago

I made it ready for review.

feliciss commented 9 months ago

Unbound module error. Need to rerun the CI and merge.