Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove empty timestamp from the tx signature payload #1939

Merged
merged 7 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gno.land/pkg/gnoclient/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
}

// Derive sign doc bytes.
signbz := tx.GetSignBytes(chainID, accountNumber, sequenceNumber)
signbz, err := tx.GetSignBytes(chainID, accountNumber, sequenceNumber)
if err != nil {
return nil, fmt.Errorf("unable to get tx signature payload, %w", err)

Check warning on line 101 in gno.land/pkg/gnoclient/signer.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/signer.go#L101

Added line #L101 was not covered by tests
}

sig, pub, err := s.Keybase.Sign(account, password, signbz)
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions tm2/pkg/crypto/keys/client/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,21 @@
signOpts signOpts,
keyOpts keyOpts,
) error {
signBytes, err := tx.GetSignBytes(
signOpts.chainID,
signOpts.accountNumber,
signOpts.accountSequence,
)
if err != nil {
return fmt.Errorf("unable to get signature bytes, %w", err)

Check warning on line 194 in tm2/pkg/crypto/keys/client/sign.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/sign.go#L194

Added line #L194 was not covered by tests
}

// Sign the transaction data
sig, pub, err := kb.Sign(
keyOpts.keyName,
keyOpts.decryptPass,
tx.GetSignBytes(
signOpts.chainID,
signOpts.accountNumber,
signOpts.accountSequence,
))
signBytes,
)
if err != nil {
return fmt.Errorf("unable to sign transaction bytes, %w", err)
}
Expand Down
10 changes: 8 additions & 2 deletions tm2/pkg/crypto/keys/client/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ func TestSign_SignTx(t *testing.T) {
require.NoError(t, err)

// Generate the signature
signature, pubKey, err := kb.Sign(anotherKey, encryptPassword, tx.GetSignBytes("id", 1, 0))
signBytes, err := tx.GetSignBytes("id", 1, 0)
require.NoError(t, err)

signature, pubKey, err := kb.Sign(anotherKey, encryptPassword, signBytes)
require.NoError(t, err)

tx.Signatures = []std.Signature{
Expand Down Expand Up @@ -554,7 +557,10 @@ func TestSign_SignTx(t *testing.T) {
require.NoError(t, err)

// Generate the signature
signature, pubKey, err := kb.Sign(keyName, encryptPassword, tx.GetSignBytes("id", 0, 0))
signBytes, err := tx.GetSignBytes("id", 0, 0)
require.NoError(t, err)

signature, pubKey, err := kb.Sign(keyName, encryptPassword, signBytes)
require.NoError(t, err)

tx.Signatures = []std.Signature{
Expand Down
21 changes: 16 additions & 5 deletions tm2/pkg/sdk/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@
// No signatures are needed for genesis.
} else {
// Check signature
signBytes := GetSignBytes(newCtx.ChainID(), tx, sacc, isGenesis)
signBytes, err := GetSignBytes(newCtx.ChainID(), tx, sacc, isGenesis)
if err != nil {
return newCtx, res, true

Check warning on line 158 in tm2/pkg/sdk/auth/ante.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/sdk/auth/ante.go#L158

Added line #L158 was not covered by tests
}

signerAccs[i], res = processSig(newCtx, sacc, stdSigs[i], signBytes, simulate, params, sigGasConsumer)
if !res.IsOK() {
return newCtx, res, true
Expand Down Expand Up @@ -430,15 +434,22 @@

// GetSignBytes returns a slice of bytes to sign over for a given transaction
// and an account.
func GetSignBytes(chainID string, tx std.Tx, acc std.Account, genesis bool) []byte {
func GetSignBytes(chainID string, tx std.Tx, acc std.Account, genesis bool) ([]byte, error) {
var accNum uint64
if !genesis {
accNum = acc.GetAccountNumber()
}
signbz := std.SignBytes(
chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo,

return std.GetSignaturePayload(
std.SignDoc{
ChainID: chainID,
AccountNumber: accNum,
Sequence: acc.GetSequence(),
Fee: tx.Fee,
Msgs: tx.Msgs,
Memo: tx.Memo,
},
)
return signbz
}

func abciResult(err error) sdk.Result {
Expand Down
Loading
Loading