Skip to content

Commit

Permalink
ensure 10-byte addresses are right-aligned in pedersen_hash (ethereum#99
Browse files Browse the repository at this point in the history
)

Co-authored-by: Tanishq Jasoria <jasoriatanishq@gmail.com>
  • Loading branch information
gballet and tanishqjasoria authored Apr 13, 2022
1 parent 439be0c commit 4b36e66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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)
}
}

0 comments on commit 4b36e66

Please sign in to comment.