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 transaction sign #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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