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: ensure 20-byte addresses are right-aligned in pedersen_hash #99

Merged
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
4 changes: 4 additions & 0 deletions trie/utils/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var (
// array. Since at most the first 5 coefficients of the polynomial will be non-zero,
// these 5 coefficients are created directly.
func GetTreeKey(address []byte, treeIndex *uint256.Int, subIndex byte) []byte {
if len(address) < 32 {
var aligned [32]byte
address = append(aligned[:32-len(address)], address...)
}
var poly [5]fr.Element

// (2 + 256 * length) little endian, length = 64 bytes
Expand Down
13 changes: 13 additions & 0 deletions trie/verkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package trie

import (
"bytes"
"encoding/hex"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/trie/utils"
"github.com/gballet/go-verkle"
)

Expand Down Expand Up @@ -381,3 +383,14 @@ func TestReproduceCondrieuPoAStemConflictWithAnotherStem(t *testing.T) {
t.Fatal("a proof-of-absence stem was declared, when there was no need")
}
}

func TestGetTreeKeys(t *testing.T) {
addr := common.Hex2Bytes("71562b71999873DB5b286dF957af199Ec94617f7")
target := common.Hex2Bytes("0e19316be898a50719b7c321005583ddab6398f4e568d8efafb0619609700f00")
key := utils.GetTreeKeyVersion(addr)
t.Logf("key=%x", key)
t.Logf("actualKey=%x", target)
if !bytes.Equal(key, target) {
t.Fatalf("differing output %x != %x", key, target)
}
}