From d43c776e84fbbab0df3b330ab590fe4b80279665 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 20 May 2015 19:36:55 -0400 Subject: [PATCH] add bonder's signature to BondTx --- rpc/core/txs.go | 7 +++++-- state/execution.go | 3 +++ state/state_test.go | 2 ++ types/tx.go | 7 ++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rpc/core/txs.go b/rpc/core/txs.go index 30d4dce7e..e0c40a55e 100644 --- a/rpc/core/txs.go +++ b/rpc/core/txs.go @@ -99,9 +99,12 @@ func SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseS callTx.Input.Signature = privAccounts[0].Sign(callTx) case *types.BondTx: bondTx := tx.(*types.BondTx) + // the first privaccount corresponds to the BondTx pub key. + // the rest to the inputs + bondTx.Signature = privAccounts[0].Sign(bondTx).(account.SignatureEd25519) for i, input := range bondTx.Inputs { - input.PubKey = privAccounts[i].PubKey - input.Signature = privAccounts[i].Sign(bondTx) + input.PubKey = privAccounts[i+1].PubKey + input.Signature = privAccounts[i+1].Sign(bondTx) } case *types.UnbondTx: unbondTx := tx.(*types.UnbondTx) diff --git a/state/execution.go b/state/execution.go index dcccbaf81..870d463a1 100644 --- a/state/execution.go +++ b/state/execution.go @@ -497,6 +497,9 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea if err := tx.PubKey.ValidateBasic(); err != nil { return err } + if !tx.PubKey.VerifyBytes(signBytes, tx.Signature) { + return types.ErrTxInvalidSignature + } outTotal, err := validateOutputs(tx.UnbondTo) if err != nil { return err diff --git a/state/state_test.go b/state/state_test.go index 08120cb11..d11c5cc5c 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -288,6 +288,7 @@ func TestTxs(t *testing.T) { }, }, } + tx.Signature = privAccounts[0].Sign(tx).(account.SignatureEd25519) tx.Inputs[0].Signature = privAccounts[0].Sign(tx) err := execTxWithState(state, tx, true) if err != nil { @@ -344,6 +345,7 @@ func TestAddValidator(t *testing.T) { }, }, } + bondTx.Signature = acc0.Sign(bondTx).(account.SignatureEd25519) bondTx.Inputs[0].Signature = acc0.Sign(bondTx) // Make complete block and blockParts diff --git a/types/tx.go b/types/tx.go index 55aa15ff4..3331eafa1 100644 --- a/types/tx.go +++ b/types/tx.go @@ -179,9 +179,10 @@ func (tx *CallTx) String() string { //----------------------------------------------------------------------------- type BondTx struct { - PubKey account.PubKeyEd25519 `json:"pub_key"` - Inputs []*TxInput `json:"inputs"` - UnbondTo []*TxOutput `json:"unbond_to"` + PubKey account.PubKeyEd25519 `json:"pub_key"` + Signature account.SignatureEd25519 `json:"signature"` + Inputs []*TxInput `json:"inputs"` + UnbondTo []*TxOutput `json:"unbond_to"` } func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {