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

feat: if ask empty l1infotree returns 0 leaves #133

Merged
merged 1 commit into from
Nov 15, 2024
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
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
Loading