Skip to content

Commit 7bf5c0d

Browse files
davidtaikochamask-ppcyberhorsey
authored
feat(eth): changes based on protocol Pacaya fork (#367)
* chore(taiko_genesis): update devnet Pacaya genesis JSONs * feat: update ValidateAnchorTx * feat: update ValidateAnchorTx * feat: update l1Origin * Revert "feat: update l1Origin" This reverts commit 1337b37. * feat: update L1Origin * feat: update genesis json * feat: add DepositTxType * feat: add DepositTxType * chore: update ci * feat: new defs * feat: new defs for op-services * feat: new defs for op-services * feat: new defs for op-services * feat: new defs for op-services * feat: new defs for op-services * feat: new defs for op-services * feat: update L1Origin * fix: fix lint errors * add preconf devent configs back in * Update core/rawdb/taiko_l1_origin.go Co-authored-by: maskpp <[email protected]> * feat: two more APIs * feat: update api backend * feat: update api backend * feat: rename an API * feat: rename an API * feat: rename an API * feat: update `BuildPayloadArgs` * feat: update `BuildPayloadArgs` * feat: update `BuildPayloadArgs` * chore: update ci * update preconf genesis * build * feat!: update ci * feat: update devnet json --------- Co-authored-by: maskpp <[email protected]> Co-authored-by: Jeffery Walsh <[email protected]>
1 parent 02597d7 commit 7bf5c0d

File tree

19 files changed

+445
-54
lines changed

19 files changed

+445
-54
lines changed

.github/workflows/docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Push multi-arch docker image to GAR"
22

33
on:
44
push:
5-
branches: [ taiko ]
5+
branches: [taiko]
66
tags:
77
- "v*"
88

@@ -19,9 +19,9 @@ jobs:
1919
platform: linux/amd64
2020
- runner: arc-runner-set-arm64
2121
platform: linux/arm64
22-
22+
2323
runs-on: ${{ matrix.runner }}
24-
24+
2525
steps:
2626
- name: Prepare Environment
2727
run: |
@@ -80,7 +80,7 @@ jobs:
8080
with:
8181
context: .
8282
cache-from: type=gha
83-
cache-to: type=gha,mode=max
83+
cache-to: type=gha,mode=max
8484
platforms: ${{ matrix.platform }}
8585
push: true
8686
tags: ${{ env.REGISTRY_IMAGE }}

consensus/taiko/consensus.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/consensus"
13+
"github.com/ethereum/go-ethereum/core/rawdb"
1314
"github.com/ethereum/go-ethereum/core/state"
1415
"github.com/ethereum/go-ethereum/core/tracing"
1516
"github.com/ethereum/go-ethereum/core/types"
1617
"github.com/ethereum/go-ethereum/crypto"
18+
"github.com/ethereum/go-ethereum/ethdb"
1719
"github.com/ethereum/go-ethereum/log"
1820
"github.com/ethereum/go-ethereum/params"
1921
"github.com/ethereum/go-ethereum/rpc"
@@ -34,18 +36,22 @@ var (
3436
AnchorV2Selector = crypto.Keccak256(
3537
[]byte("anchorV2(uint64,bytes32,uint32,(uint8,uint8,uint32,uint64,uint32))"),
3638
)[:4]
39+
AnchorV3Selector = crypto.Keccak256(
40+
[]byte("anchorV3(uint64,bytes32,bytes32,uint32,(uint8,uint8,uint32,uint64,uint32),bytes32[])"),
41+
)[:4]
3742
AnchorGasLimit = uint64(250_000)
3843
)
3944

4045
// Taiko is a consensus engine used by L2 rollup.
4146
type Taiko struct {
4247
chainConfig *params.ChainConfig
4348
taikoL2Address common.Address
49+
chainDB ethdb.Database
4450
}
4551

4652
var _ = new(Taiko)
4753

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

5157
return &Taiko{
@@ -56,6 +62,7 @@ func New(chainConfig *params.ChainConfig) *Taiko {
5662
strings.Repeat("0", common.AddressLength*2-len(taikoL2AddressPrefix)-len(TaikoL2AddressSuffix)) +
5763
TaikoL2AddressSuffix,
5864
),
65+
chainDB: chainDB,
5966
}
6067
}
6168

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

8895
// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
@@ -109,7 +116,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
109116
if parent == nil {
110117
err = consensus.ErrUnknownAncestor
111118
} else {
112-
err = t.verifyHeader(chain, header, parent, unixNow)
119+
err = t.verifyHeader(header, parent, unixNow)
113120
}
114121
select {
115122
case <-abort:
@@ -121,11 +128,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
121128
return abort, results
122129
}
123130

124-
func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header, unixNow int64) error {
125-
if header.Time > uint64(unixNow) {
126-
return consensus.ErrFutureBlock
127-
}
128-
131+
func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error {
129132
// Ensure that the header's extra-data section is of a reasonable size (<= 32 bytes)
130133
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
131134
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
@@ -171,6 +174,16 @@ func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *
171174
return ErrEmptyWithdrawalsHash
172175
}
173176

177+
l1Origin, err := rawdb.ReadL1Origin(t.chainDB, header.Number)
178+
if err != nil {
179+
return err
180+
}
181+
182+
// If the current block is not a preconfirmation block, then check the timestamp.
183+
if l1Origin != nil && !l1Origin.IsPreconfBlock() && header.Time > uint64(unixNow) {
184+
return consensus.ErrFutureBlock
185+
}
186+
174187
return nil
175188
}
176189

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

293-
if !bytes.HasPrefix(tx.Data(), AnchorSelector) && !bytes.HasPrefix(tx.Data(), AnchorV2Selector) {
306+
if !bytes.HasPrefix(tx.Data(), AnchorSelector) &&
307+
!bytes.HasPrefix(tx.Data(), AnchorV2Selector) &&
308+
!bytes.HasPrefix(tx.Data(), AnchorV3Selector) {
294309
return false, nil
295310
}
296311

consensus/taiko/consensus_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func init() {
3939
config.ArrowGlacierBlock = nil
4040
config.Ethash = nil
4141
config.Taiko = true
42-
testEngine = taiko.New(config)
42+
testEngine = taiko.New(config, rawdb.NewMemoryDatabase())
4343

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

core/rawdb/gen_taiko_l1_origin.go

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/rawdb/taiko_l1_origin.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ func l1OriginKey(blockID *big.Int) []byte {
3131
type L1Origin struct {
3232
BlockID *big.Int `json:"blockID" gencodec:"required"`
3333
L2BlockHash common.Hash `json:"l2BlockHash"`
34-
L1BlockHeight *big.Int `json:"l1BlockHeight" gencodec:"required"`
35-
L1BlockHash common.Hash `json:"l1BlockHash" gencodec:"required"`
34+
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
35+
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
3636
}
3737

3838
type l1OriginMarshaling struct {
3939
BlockID *math.HexOrDecimal256
4040
L1BlockHeight *math.HexOrDecimal256
4141
}
4242

43+
// IsPreconfBlock returns true if the L1Origin is for a preconfirmation block.
44+
func (l *L1Origin) IsPreconfBlock() bool {
45+
return l.L1BlockHeight == nil
46+
}
47+
4348
// WriteL1Origin stores a L1Origin into the database.
4449
func WriteL1Origin(db ethdb.KeyValueWriter, blockID *big.Int, l1Origin *L1Origin) {
4550
data, err := rlp.EncodeToBytes(l1Origin)

core/taiko_genesis.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
var (
1313
InternalDevnetOntakeBlock = new(big.Int).SetUint64(0)
14+
PreconfDevnetOntakeBlock = common.Big0
1415
HeklaOntakeBlock = new(big.Int).SetUint64(840_512)
1516
MainnetOntakeBlock = new(big.Int).SetUint64(538_304)
1617
)
@@ -54,6 +55,10 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
5455
chainConfig.ChainID = params.HeklaNetworkID
5556
chainConfig.OntakeBlock = HeklaOntakeBlock
5657
allocJSON = taikoGenesis.HeklaGenesisAllocJSON
58+
case params.PreconfDevnetNetworkID.Uint64():
59+
chainConfig.ChainID = params.PreconfDevnetNetworkID
60+
chainConfig.OntakeBlock = PreconfDevnetOntakeBlock
61+
allocJSON = taikoGenesis.PreconfDevnetGenesisAllocJSON
5762
default:
5863
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
5964
chainConfig.OntakeBlock = InternalDevnetOntakeBlock

core/taiko_genesis/genesis_alloc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ var HeklaGenesisAllocJSON []byte
3333

3434
//go:embed mainnet.json
3535
var MainnetGenesisAllocJSON []byte
36+
37+
//go:embed preconf_devnet.json
38+
var PreconfDevnetGenesisAllocJSON []byte

core/taiko_genesis/internal_l2a.json

Lines changed: 20 additions & 25 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)