Skip to content

Commit

Permalink
fix(types): fix some withdrawRoot related issues (taikoxyz#69)
Browse files Browse the repository at this point in the history
* fix(types): fix some `withdrawRoot` related issues

* chore: update workflow

* chore: update workflow configs

* feat: update `ExecutableDataToBlock`

* chore: update workflow configs
  • Loading branch information
davidtaikocha authored May 11, 2023
1 parent e6412c5 commit edb10f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type ExecutableData struct {
Transactions [][]byte `json:"transactions" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
TxHash common.Hash `json:"txHash"` // CHANGE(taiko): allow passing txHash directly instead of transactions list
TaikoBlock bool // CHANGE(taiko): whether this is a Taiko L2 block, only used by ExecutableDataToBlock
}

// JSON type overrides for executableData.
Expand Down Expand Up @@ -209,7 +210,12 @@ func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
// Withdrawals as the json null value.
var withdrawalsRoot *common.Hash
if params.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
var h common.Hash
if params.TaikoBlock {
h = types.CalcWithdrawalsRootTaiko(params.Withdrawals)
} else {
h = types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
}
withdrawalsRoot = &h
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (t *Taiko) Prepare(chain consensus.ChainHeaderReader, header *types.Header)
// consensus rules that happen at finalization (e.g. block rewards).
func (t *Taiko) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
// no block rewards in l2
header.Root = state.IntermediateRoot(true)
header.UncleHash = types.CalcUncleHash(nil)
header.Difficulty = common.Big0
// Withdrawals processing.
Expand All @@ -224,6 +223,7 @@ func (t *Taiko) Finalize(chain consensus.ChainHeaderReader, header *types.Header
amount = amount.Mul(amount, big.NewInt(params.GWei))
state.AddBalance(w.Address, amount)
}
header.Root = state.IntermediateRoot(true)
}

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
Expand Down
10 changes: 9 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package core
import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -73,7 +74,14 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if block.Withdrawals() == nil {
return fmt.Errorf("missing withdrawals in block body")
}
if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash {

var hash common.Hash
if v.config.Taiko {
hash = types.CalcWithdrawalsRootTaiko(block.Withdrawals())
} else {
hash = types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil))
}
if hash != *header.WithdrawalsHash {
return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash)
}
} else if block.Withdrawals() != nil {
Expand Down
1 change: 1 addition & 0 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData) (engine.Payloa
block *types.Block
err error
)
params.TaikoBlock = api.eth.BlockChain().Config().Taiko
if api.eth.BlockChain().Config().Taiko && params.Transactions == nil {
h := types.CalcWithdrawalsRootTaiko(params.Withdrawals)
block = types.NewBlockWithHeader(&types.Header{
Expand Down

0 comments on commit edb10f7

Please sign in to comment.