Skip to content

Commit

Permalink
revert StdSignBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ylsGit committed Jul 9, 2024
1 parent 557f038 commit 27fed1c
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (suite *FakeBlockTxTestSuite) TestFakeBlockTx() {
func newTestStdTx(msgs []cosmossdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) cosmossdk.Tx {
sigs := make([]authtypes.StdSignature, len(privs))
for i, priv := range privs {
sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0))
sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/simapp/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums

for i, p := range priv {
// use a empty chainID for ease of testing
sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0))
sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) {
for _, cs := range cases {
tx := types.NewTestTxWithSignBytes(
msgs, privs, accnums, seqs, fee,
types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, "", 0),
types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, ""),
"",
)
checkInvalidTx(t, anteHandler, ctx, tx, false, cs.err)
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/ante/sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func TestVerifySig(t *testing.T) {
}

func NewSig(ctx sdk.Context, msgs []sdk.Msg, priv crypto.PrivKey, accNum uint64, seq uint64, fee types.StdFee) []types.StdSignature {
signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "", 0)
signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "")
sig, err := priv.Sign(signBytes)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
// Validate each signature
sigBytes := types.StdSignBytes(
txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(),
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0,
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(),
)
if ok := stdSig.PubKey.VerifyBytes(sigBytes, stdSig.Signature); !ok {
return fmt.Errorf("couldn't verify signature")
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func printAndValidateSigs(

sigBytes := types.StdSignBytes(
chainID, acc.GetAccountNumber(), acc.GetSequence(),
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0,
stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(),
)

if ok := sig.VerifyBytes(sigBytes, sig.Signature); !ok {
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/types/stdsignmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ type StdSignMsg struct {

// get message bytes
func (msg StdSignMsg) Bytes() []byte {
return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo, 0)
return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo)
}
15 changes: 4 additions & 11 deletions libs/cosmos-sdk/x/auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package types
import (
"encoding/json"
"fmt"
"math/big"
"strings"

ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/okex/exchain/libs/cosmos-sdk/codec"
Expand All @@ -15,9 +12,9 @@ import (
"github.com/okex/exchain/libs/tendermint/crypto"
cryptoamino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino"
"github.com/okex/exchain/libs/tendermint/crypto/multisig"
tmtypes "github.com/okex/exchain/libs/tendermint/types"
"github.com/tendermint/go-amino"
yaml "gopkg.in/yaml.v2"
"math/big"
)

var (
Expand Down Expand Up @@ -238,7 +235,7 @@ func (tx *StdTx) GetSignBytes(ctx sdk.Context, index int, acc exported.Account)
}

return StdSignBytes(
chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, ctx.BlockHeight(),
chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo,
)
}

Expand Down Expand Up @@ -436,14 +433,10 @@ type StdSignDoc struct {
}

// StdSignBytes returns the bytes to sign for a transaction.
func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string, height int64) []byte {
func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte {
msgsBytes := make([]json.RawMessage, 0, len(msgs))
for _, msg := range msgs {
msgByte := json.RawMessage(msg.GetSignBytes())
if height > 0 && !tmtypes.HigherThanJupiter(height) && msg.Type() == "edit_validator" {
msgByte = []byte(strings.ReplaceAll(string(msgByte), `,"pubkey":null`, ""))
}
msgsBytes = append(msgsBytes, msgByte)
msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes()))
}
bz, err := ModuleCdc.MarshalJSON(StdSignDoc{
AccountNumber: accnum,
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/types/stdtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestStdSignBytes(t *testing.T) {
},
}
for i, tc := range tests {
got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo, 0))
got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo))
require.Equal(t, tc.want, got, "Got unexpected result on test case i: %d", i)
}
}
Expand Down
4 changes: 2 additions & 2 deletions libs/cosmos-sdk/x/auth/types/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx {
sigs := make([]StdSignature, len(privs))
for i, priv := range privs {
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "", 0)
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "")

sig, err := priv.Sign(signBytes)
if err != nil {
Expand All @@ -52,7 +52,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums
func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx {
sigs := make([]StdSignature, len(privs))
for i, priv := range privs {
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo, 0)
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo)

sig, err := priv.Sign(signBytes)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKe
memo := "testmemotestmemo"

for i, p := range priv {
sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0))
sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/evm/watcher/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (suite *TxTestSuite) TestRecordTxAndFailedReceipt() {
func newTestStdTx(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) sdk.Tx {
sigs := make([]authtypes.StdSignature, len(privs))
for i, priv := range privs {
sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0))
sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo))
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 27fed1c

Please sign in to comment.