Skip to content

Conversation

@KenLoong
Copy link

@KenLoong KenLoong commented Dec 5, 2024

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())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant