immutability-io / vault-ethereum

A plugin that turns Vault into an Ethereum wallet.
243 stars 65 forks source link

Incorrect signature length (wanted 65, got 132) #5

Closed john-osullivan closed 6 years ago

john-osullivan commented 6 years ago

I'm trying to make a geth node call out to Vault for generating private keys and signing transactions. The key pieces are bridged up, but I'm not getting back signatures of the right size -- test cases are failing saying that the signature has size 132 when it needs size 65. Size 65 also seems correct if the signature formula is two length-32 sequences followed by a recovery byte.

This seems like it must be a configuration issue given that you're using it successfully, though. What am I missing here? Probably an encoding issue somewhere down the line.

Detailed Description

I'm connecting vault-ethereum to a fork of quorum in two key places:

  1. /accounts/key#newKey() - This is already behaving -- Vault generates the keys and, for now, hands them back for quorum to put into its keystore.
  2. /crypto/crypto#Sign() is being called without issue, the data is being signed, but the resulting signatures are too large. My replacement implementation makes a barebones call to this library's sign endpoint:
    func (v *VaultDriver) Sign(txHash []byte) (signature []byte, err error) {
    vault := v.client.Logical()
    resp, err := vault.Write(
        v.scopedPath("sign"),
        map[string]interface{}{
            "data": txHash,
        })
    if err != nil {
        fmt.Println("err on Sign:", err.Error())
        return nil, err
    }
    signature = []byte(resp.Data["signature"].(string))
    return
    }

    The txHash is, as you might expect, the already-hashed transaction. I've tried a few different versions of that sign call and run into different bugs.

  3. The above call ("data": txHash) successfully returns a signature, but it is too large.
  4. If I add "raw": true to the call, then the call fails with a hex string without 0x prefix error
  5. If I then change txHash to append([]string{"0x"}, string(txHash)), then the call fails with error converting input [0x �N�axoCA��t�hnU�J�����#�)���qg�] for field "data": '' expected type 'string', got unconvertible type '[]interface {}'

I've been trying alternate approaches to get around the hex string without 0x prefix error, but nothing's working. Would appreciate any guidance!

Context

I'm trying to plug vault-ethereum into a forked version of quorum so that the node can sign transactions without ever actually holding the private keys itself. If this was easy, people could easily spin up nodes without worrying about safely managing the private credentials on them.

Environment

john-osullivan commented 6 years ago

Solved this issue! Just in case somebody comes across this in the future, the key was just over twice as large because it was encoded with go-ethereum/common/hexutils which both doubles the size and adds two bytes on the front for the 0x.

There was a fix for both the send and the receive. The way my code was setup made it inconvenient to use the same hexutils library, so I just used the standard encoding/hex library:

Worked like a charm, I'll close this out.

cypherhat commented 6 years ago

Thanks for this!