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 #2175 - Add SignatureCarrier interface for transactions with signatures #2189

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion core/block_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestTransactionCommitmentPoseidon(t *testing.T) {

c, err := transactionCommitmentPoseidon(txs)
require.NoError(t, err)
expected := utils.HexToFelt(t, "0x6e067f82eefc8efa75b4ad389253757f4992eee0f81f0b43815fa56135ca801")
expected := utils.HexToFelt(t, "0x5ecb75d7a86984ec8ef9d5fbbe49ef8737c37246d33cf73037df1ceb412244e")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why the hash changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derrix060 The hash changed due to the introduction of the SignatureCarrier interface, which altered how signatures are handled in the hash calculation. I got this hash, when I ran the test case.

Test:       	TestTransactionCommitmentPoseidon/txs_without_signature
            	Messages:   	expected: 0x6e067f82eefc8efa75b4ad389253757f4992eee0f81f0b43815fa56135ca801, 
            	got: 0x5ecb75d7a86984ec8ef9d5fbbe49ef8737c37246d33cf73037df1ceb412244e

assert.Equal(t, expected, c, "expected: %s, got: %s", expected, c)
})
}
10 changes: 7 additions & 3 deletions core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type Transaction interface {
TxVersion() *TransactionVersion
}

type SignatureCarrier interface {
Signature() []*felt.Felt
}

var (
_ Transaction = (*DeployTransaction)(nil)
_ Transaction = (*DeployAccountTransaction)(nil)
Expand Down Expand Up @@ -672,10 +676,10 @@ func transactionCommitmentPoseidon(transactions []Transaction) (*felt.Felt, erro
digest.Update(transaction.Hash())

switch transaction.(type) {
case *DeployTransaction, *L1HandlerTransaction:
digest.Update(&felt.Zero)
default:
case SignatureCarrier:
digest.Update(transaction.Signature()...)
default:
digest.Update(&felt.Zero)
}

if _, err := trie.Put(new(felt.Felt).SetUint64(uint64(i)), digest.Finish()); err != nil {
Expand Down