Skip to content

Commit 38c4eff

Browse files
committed
fix: genesis state root commit workaround
1 parent 6fa0f86 commit 38c4eff

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

rollup/internal/utils/utils.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/ethereum/go-ethereum/log"
89
"github.com/scroll-tech/da-codec/encoding"
910
"github.com/scroll-tech/go-ethereum/common"
1011
"github.com/scroll-tech/go-ethereum/crypto"
@@ -138,6 +139,26 @@ func encodeBatchHeaderValidium(b *encoding.Batch, codecVersion encoding.CodecVer
138139
// TODO: This is a temporary solution, we might use a larger commitment in the future
139140
lastBlock := b.Blocks[len(b.Blocks)-1]
140141
commitment := lastBlock.Header.Hash()
142+
stateRoot := b.StateRoot()
143+
144+
// Temporary workaround for the wrong genesis state root configuration issue.
145+
if lastBlock.Header.Number.Uint64() == 0 {
146+
if commitment == common.HexToHash("0x76a8e1359fe1a51ec3917ca98dec95ba005f1a73bcdbc2c7f87c7683e828fbb1") && stateRoot == common.HexToHash("0x08d535cc60f40af5dd3b31e0998d7567c2d568b224bed2ba26070aeb078d1339") {
147+
// cloak-xen/sepolia
148+
stateRoot = common.HexToHash("0x0711f02d6f85b0597c4705298e01ee27159fdd8bd8bdeda670ae8b9073091246")
149+
} else if commitment == common.HexToHash("0x8005a02271085eaded2565f3e252013cd9d3cd0a4775d89f9ba4224289671276") && stateRoot == common.HexToHash("0x08d535cc60f40af5dd3b31e0998d7567c2d568b224bed2ba26070aeb078d1339") {
150+
// cloak-xen/mainnet
151+
stateRoot = common.HexToHash("0x8da1aaf41660ddf7870ab5ff4f6a3ab4b2e652568d341ede87ada56aad5fb097")
152+
} else if commitment == common.HexToHash("0xa7e50dfc812039410c2009c74cdcb0c0797aa5485dec062985eaa43b17d333ea") && stateRoot == common.HexToHash("0x08d535cc60f40af5dd3b31e0998d7567c2d568b224bed2ba26070aeb078d1339") {
153+
// cloak-etherfi/sepolia
154+
stateRoot = common.HexToHash("0x7b44ea23770dda8810801779eb6847d56be0399e35de7c56465ccf8b7578ddf6")
155+
} else if commitment == common.HexToHash("0xeccf4fab24f8b5dd3b72667c6bf5e28b17ccffdea01e3e5c08f393edaa9e7657") && stateRoot == common.HexToHash("0x08d535cc60f40af5dd3b31e0998d7567c2d568b224bed2ba26070aeb078d1339") {
156+
// cloak-shiga/sepolia
157+
stateRoot = common.HexToHash("0x05973227854ac82c22f164ed3d4510b7df516a0eecdfd9bed5f2446efc9994b9")
158+
}
159+
160+
log.Warn("Using genesis state root", "stateRoot", stateRoot.Hex())
161+
}
141162

142163
// Batch header field sizes
143164
const (
@@ -179,7 +200,7 @@ func encodeBatchHeaderValidium(b *encoding.Batch, codecVersion encoding.CodecVer
179200
batchBytes[versionOffset] = version // version
180201
binary.BigEndian.PutUint64(batchBytes[indexOffset:indexOffset+indexSize], b.Index) // batch index
181202
copy(batchBytes[parentHashOffset:parentHashOffset+parentHashSize], b.ParentBatchHash[0:parentHashSize]) // parentBatchHash
182-
copy(batchBytes[stateRootOffset:stateRootOffset+stateRootSize], b.StateRoot().Bytes()[0:stateRootSize]) // postStateRoot
203+
copy(batchBytes[stateRootOffset:stateRootOffset+stateRootSize], stateRoot.Bytes()[0:stateRootSize]) // postStateRoot
183204
copy(batchBytes[withdrawRootOffset:withdrawRootOffset+withdrawRootSize], b.WithdrawRoot().Bytes()[0:withdrawRootSize]) // postWithdrawRoot
184205
copy(batchBytes[commitmentOffset:commitmentOffset+commitmentSize], commitment[0:commitmentSize]) // data commitment
185206

0 commit comments

Comments
 (0)