Skip to content

Commit

Permalink
feat: if ask empty l1infotree returns 0 leaves (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr authored Nov 15, 2024
1 parent 4cbc189 commit d289356
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
10 changes: 2 additions & 8 deletions config/environments/cardona/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
Environment = "development" # "production" or "development"
Level = "info"
Outputs = ["stderr"]
[DB]
Name = "sync"
User = "test_user"
Password = "test_password"
Host = "localhost"
Port = "5436"
MaxConns = 10
[Synchronizer]
SyncInterval = "10s"
SyncChunkSize = 100
Expand All @@ -19,4 +12,5 @@
[Etherman.Contracts]
GlobalExitRootManagerAddr = "0xAd1490c248c5d3CbAE399Fd529b79B42984277DF"
RollupManagerAddr = "0x32d33D5137a7cFFb54c5Bf8371172bcEc5f310ff"
ZkEVMAddr = "0xA13Ddb14437A8F34897131367ad3ca78416d6bCa"
ZkEVMAddr = "0xA13Ddb14437A8F34897131367ad3ca78416d6bCa"

19 changes: 19 additions & 0 deletions l1infotree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package l1infotree_test
import (
"encoding/hex"
"encoding/json"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -128,3 +129,21 @@ func TestAddLeaf2(t *testing.T) {
require.Equal(t, testVector.NewRoot, newRoot)
}
}

func Test1Leave(t *testing.T) {
mt, err := l1infotree.NewL1InfoTree(uint8(32), [][32]byte{})
require.NoError(t, err)
leaves := [][32]byte{
common.HexToHash("0x6a617315ffc0a6831d2de6331f8d3e053889e9385696c13f11853fdcba50e123"),
common.HexToHash("0x1cff355b898cf285bcc3f84a8d6ed51c19fe87ab654f4146f2dc7723a59fc741"),
}
//require.Equal(t, 26, len(leaves))
siblings, root, err := mt.ComputeMerkleProof(2, leaves)
require.NoError(t, err)
fmt.Printf("Root: %s\n", root.String())
for i := 0; i < len(siblings); i++ {
hash := common.BytesToHash(siblings[i][:])
fmt.Printf("Sibling %d: %s\n", i, hash.String())
}

}
5 changes: 5 additions & 0 deletions state/model/l1infotree_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
const (
// SkipL1InfoTreeLeaf is special index that skip the change of GlobalExitRoot, so the value of this leaf is never used
SkipL1InfoTreeLeaf = uint32(0)
emptyL1InfoRoot = "0x27ae5ba08d7291c96c8cbddcc148bf48a6d68c7974b94356f53754ef6171d757"
)

type L1InfoTreeLeaf = entities.L1InfoTreeLeaf
Expand Down Expand Up @@ -149,6 +150,10 @@ func (s *L1InfoTreeState) GetL1InfoTreeLeaves(ctx context.Context, indexLeaves [
}

func (s *L1InfoTreeState) GetLeafsByL1InfoRoot(ctx context.Context, l1InfoRoot common.Hash, dbTx stateTxType) ([]L1InfoTreeLeaf, error) {
if l1InfoRoot == common.HexToHash(emptyL1InfoRoot) {
res := make([]L1InfoTreeLeaf, 0)
return res, nil
}
leaves, err := s.storage.GetLeafsByL1InfoRoot(ctx, l1InfoRoot, dbTx)
if err != nil {
log.Error("error getting leaves by L1InfoRoot. Error: ", err)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var (
Version = "v1.0.5"
Version = "v1.0.6"
)

// PrintVersion prints version info into the provided io.Writer.
Expand Down

0 comments on commit d289356

Please sign in to comment.