Skip to content

Commit

Permalink
Merge branch 'devnet-genesis-pacaya' into devnet-pacaya-height-0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin “yoghurt” Yu committed Feb 5, 2025
2 parents fb5a553 + 8327137 commit 8406676
Show file tree
Hide file tree
Showing 18 changed files with 411 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
platform: linux/amd64
- runner: arc-runner-set-arm64
platform: linux/arm64

runs-on: ${{ matrix.runner }}

steps:
- name: Prepare Environment
run: |
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
push: true
tags: ${{ env.REGISTRY_IMAGE }}
Expand Down
33 changes: 24 additions & 9 deletions consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -34,18 +36,22 @@ var (
AnchorV2Selector = crypto.Keccak256(
[]byte("anchorV2(uint64,bytes32,uint32,(uint8,uint8,uint32,uint64,uint32))"),
)[:4]
AnchorV3Selector = crypto.Keccak256(
[]byte("anchorV3(uint64,bytes32,bytes32,uint32,(uint8,uint8,uint32,uint64,uint32),bytes32[])"),
)[:4]
AnchorGasLimit = uint64(250_000)
)

// Taiko is a consensus engine used by L2 rollup.
type Taiko struct {
chainConfig *params.ChainConfig
taikoL2Address common.Address
chainDB ethdb.Database
}

var _ = new(Taiko)

func New(chainConfig *params.ChainConfig) *Taiko {
func New(chainConfig *params.ChainConfig, chainDB ethdb.Database) *Taiko {
taikoL2AddressPrefix := strings.TrimPrefix(chainConfig.ChainID.String(), "0")

return &Taiko{
Expand All @@ -56,6 +62,7 @@ func New(chainConfig *params.ChainConfig) *Taiko {
strings.Repeat("0", common.AddressLength*2-len(taikoL2AddressPrefix)-len(TaikoL2AddressSuffix)) +
TaikoL2AddressSuffix,
),
chainDB: chainDB,
}
}

Expand All @@ -82,7 +89,7 @@ func (t *Taiko) VerifyHeader(chain consensus.ChainHeaderReader, header *types.He
return consensus.ErrUnknownAncestor
}
// Sanity checks passed, do a proper verification
return t.verifyHeader(chain, header, parent, time.Now().Unix())
return t.verifyHeader(header, parent, time.Now().Unix())
}

// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
Expand All @@ -109,7 +116,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
if parent == nil {
err = consensus.ErrUnknownAncestor
} else {
err = t.verifyHeader(chain, header, parent, unixNow)
err = t.verifyHeader(header, parent, unixNow)
}
select {
case <-abort:
Expand All @@ -121,11 +128,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
return abort, results
}

func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header, unixNow int64) error {
if header.Time > uint64(unixNow) {
return consensus.ErrFutureBlock
}

func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error {
// Ensure that the header's extra-data section is of a reasonable size (<= 32 bytes)
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
Expand Down Expand Up @@ -171,6 +174,16 @@ func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *
return ErrEmptyWithdrawalsHash
}

l1Origin, err := rawdb.ReadL1Origin(t.chainDB, header.Number)
if err != nil {
return err
}

// If the current block is not a preconfirmation block, then check the timestamp.
if l1Origin != nil && !l1Origin.IsPreconfBlock() && header.Time > uint64(unixNow) {
return consensus.ErrFutureBlock
}

return nil
}

Expand Down Expand Up @@ -290,7 +303,9 @@ func (t *Taiko) ValidateAnchorTx(tx *types.Transaction, header *types.Header) (b
return false, nil
}

if !bytes.HasPrefix(tx.Data(), AnchorSelector) && !bytes.HasPrefix(tx.Data(), AnchorV2Selector) {
if !bytes.HasPrefix(tx.Data(), AnchorSelector) &&
!bytes.HasPrefix(tx.Data(), AnchorV2Selector) &&
!bytes.HasPrefix(tx.Data(), AnchorV3Selector) {
return false, nil
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/taiko/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
config.ArrowGlacierBlock = nil
config.Ethash = nil
config.Taiko = true
testEngine = taiko.New(config)
testEngine = taiko.New(config, rawdb.NewMemoryDatabase())

taikoL2AddressPrefix := strings.TrimPrefix(config.ChainID.String(), "0")

Expand Down
18 changes: 8 additions & 10 deletions core/rawdb/gen_taiko_l1_origin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions core/rawdb/taiko_l1_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ func l1OriginKey(blockID *big.Int) []byte {
type L1Origin struct {
BlockID *big.Int `json:"blockID" gencodec:"required"`
L2BlockHash common.Hash `json:"l2BlockHash"`
L1BlockHeight *big.Int `json:"l1BlockHeight" gencodec:"required"`
L1BlockHash common.Hash `json:"l1BlockHash" gencodec:"required"`
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
}

type l1OriginMarshaling struct {
BlockID *math.HexOrDecimal256
L1BlockHeight *math.HexOrDecimal256
}

// IsPreconfBlock returns true if the L1Origin is for a preconfirmation block.
func (l *L1Origin) IsPreconfBlock() bool {
return l.L1BlockHeight == nil
}

// WriteL1Origin stores a L1Origin into the database.
func WriteL1Origin(db ethdb.KeyValueWriter, blockID *big.Int, l1Origin *L1Origin) {
data, err := rlp.EncodeToBytes(l1Origin)
Expand Down
5 changes: 5 additions & 0 deletions core/taiko_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

var (
InternalDevnetOntakeBlock = new(big.Int).SetUint64(0)
PreconfDevnetOntakeBlock = common.Big0
HeklaOntakeBlock = new(big.Int).SetUint64(840_512)
MainnetOntakeBlock = new(big.Int).SetUint64(538_304)
)
Expand Down Expand Up @@ -54,6 +55,10 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
chainConfig.ChainID = params.HeklaNetworkID
chainConfig.OntakeBlock = HeklaOntakeBlock
allocJSON = taikoGenesis.HeklaGenesisAllocJSON
case params.PreconfDevnetNetworkID.Uint64():
chainConfig.ChainID = params.PreconfDevnetNetworkID
chainConfig.OntakeBlock = PreconfDevnetOntakeBlock
allocJSON = taikoGenesis.PreconfDevnetGenesisAllocJSON
default:
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
chainConfig.OntakeBlock = InternalDevnetOntakeBlock
Expand Down
3 changes: 3 additions & 0 deletions core/taiko_genesis/genesis_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ var HeklaGenesisAllocJSON []byte

//go:embed mainnet.json
var MainnetGenesisAllocJSON []byte

//go:embed preconf_devnet.json
var PreconfDevnetGenesisAllocJSON []byte
Loading

0 comments on commit 8406676

Please sign in to comment.