From 5508cb81b60cd9f899072220b27416dfa5d13bb8 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:03:45 +0100 Subject: [PATCH] feat: if ask empty l1infotree returns 0 leaves --- config/environments/cardona/config.toml | 10 ++-------- l1infotree/tree_test.go | 19 +++++++++++++++++++ state/model/l1infotree_state.go | 5 +++++ version.go | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config/environments/cardona/config.toml b/config/environments/cardona/config.toml index 7d98be8..c5604fb 100644 --- a/config/environments/cardona/config.toml +++ b/config/environments/cardona/config.toml @@ -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 @@ -19,4 +12,5 @@ [Etherman.Contracts] GlobalExitRootManagerAddr = "0xAd1490c248c5d3CbAE399Fd529b79B42984277DF" RollupManagerAddr = "0x32d33D5137a7cFFb54c5Bf8371172bcEc5f310ff" - ZkEVMAddr = "0xA13Ddb14437A8F34897131367ad3ca78416d6bCa" \ No newline at end of file + ZkEVMAddr = "0xA13Ddb14437A8F34897131367ad3ca78416d6bCa" + diff --git a/l1infotree/tree_test.go b/l1infotree/tree_test.go index ccc4159..230b743 100644 --- a/l1infotree/tree_test.go +++ b/l1infotree/tree_test.go @@ -3,6 +3,7 @@ package l1infotree_test import ( "encoding/hex" "encoding/json" + "fmt" "os" "testing" @@ -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()) + } + +} diff --git a/state/model/l1infotree_state.go b/state/model/l1infotree_state.go index d58c446..659cf4d 100644 --- a/state/model/l1infotree_state.go +++ b/state/model/l1infotree_state.go @@ -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 @@ -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) diff --git a/version.go b/version.go index 13f2388..27e66dc 100644 --- a/version.go +++ b/version.go @@ -7,7 +7,7 @@ import ( ) var ( - Version = "v1.0.5" + Version = "v1.0.6" ) // PrintVersion prints version info into the provided io.Writer.