projectx icon indicating copy to clipboard operation
projectx copied to clipboard

Fix transaction sign

Open KenLoong opened this issue 1 year ago • 0 comments

Since transaction's hash function returns the cached version of hash, it won't calculate the latest hash of tracsaction's data. When we temper one transaction's data and call Verify() again, it still pass! Because transaction's Hash function returns the cached version of hash.

func TestTemperTxData(t *testing.T) {
	userA := crypto.GeneratePrivateKey()
	userB := crypto.GeneratePrivateKey()
	tx := &Transaction{
		From:  userA.PublicKey(),
		To:    userB.PublicKey(),
		Value: 666,
		Data:  []byte("user a send 666 to user b"),
	}
	assert.Nil(t, tx.Sign(userA))
	assert.Nil(t, tx.Verify())
	tx.Data = []byte("hhh")
	assert.NotNil(t, tx.Verify())
}

KenLoong avatar Dec 05 '24 04:12 KenLoong