Skip to content

Commit

Permalink
Merge branch 'taiko' into preconfs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Aug 8, 2024
2 parents bf451ad + 6315fd4 commit b96e4b7
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 56 deletions.
32 changes: 12 additions & 20 deletions beacon/engine/gen_blockmetadata.go

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

6 changes: 2 additions & 4 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ type payloadAttributesMarshaling struct {
// CHANGE(taiko): BlockMetadata represents a `BlockMetadata` struct defined in
// protocol.
type BlockMetadata struct {
// Fields defined in `LibData.blockMetadata`.
Beneficiary common.Address `json:"beneficiary" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
Timestamp uint64 `json:"timestamp" gencodec:"required"`
MixHash common.Hash `json:"mixHash" gencodec:"required"`

// Extra fields required in taiko-geth.
TxList []byte `json:"txList" gencodec:"required"`
HighestBlockID *big.Int `json:"highestBlockID" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
TxList []byte `json:"txList" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
}

// CHANGE(taiko): JSON type overrides for BlockMetadata.
Expand Down
5 changes: 3 additions & 2 deletions consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
GoldenTouchAccount = common.HexToAddress("0x0000777735367b36bC9B61C50022d9D0700dB4Ec")
TaikoL2AddressSuffix = "10001"
AnchorSelector = crypto.Keccak256([]byte("anchor(bytes32,bytes32,uint64,uint32)"))[:4]
AnchorV2Selector = crypto.Keccak256([]byte("anchorV2(uint64,bytes32,uint32,uint32,uint8)"))[:4]
AnchorGasLimit = uint64(250_000)
)

Expand Down Expand Up @@ -274,7 +275,7 @@ func (t *Taiko) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, p
return common.Big0
}

// ValidateAnchorTx checks if the given transaction is a valid TaikoL2.anchor transaction.
// ValidateAnchorTx checks if the given transaction is a valid TaikoL2.anchor or TaikoL2.anchorV2 transaction.
func (t *Taiko) ValidateAnchorTx(tx *types.Transaction, header *types.Header) (bool, error) {
if tx.Type() != types.DynamicFeeTxType {
return false, nil
Expand All @@ -284,7 +285,7 @@ func (t *Taiko) ValidateAnchorTx(tx *types.Transaction, header *types.Header) (b
return false, nil
}

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

Expand Down
5 changes: 5 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
if err != nil {
return nil, err
}
// CHANGE(taiko): decode the basefeeSharingPctg config from the extradata, and
// add it to the Message, if its an ontake block.
if config.IsOntake(header.Number) {
msg.BasefeeSharingPctg = DecodeOntakeExtraData(header.Extra)
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)
txContext := NewEVMTxContext(msg)
Expand Down
21 changes: 17 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Message struct {

// CHANGE(taiko): whether the current transaction is the first TaikoL2.anchor transaction in a block.
IsAnchor bool
// CHANGE(taiko): basefeeSharingPctg of the basefee will be sent to the block.coinbase,
// the remaining will be sent to the treasury address.
BasefeeSharingPctg uint8
}

// TransactionToMessage converts a transaction into a Message.
Expand Down Expand Up @@ -467,12 +470,16 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
fee := new(uint256.Int).SetUint64(st.gasUsed())
fee.Mul(fee, effectiveTipU256)
st.state.AddBalance(st.evm.Context.Coinbase, fee)
// CHANGE(taiko): basefee is not burnt, but sent to a treasury instead.
// CHANGE(taiko): basefee is not burnt, but sent to a treasury and block.coinbase instead.
if st.evm.ChainConfig().Taiko && st.evm.Context.BaseFee != nil && !st.msg.IsAnchor {
st.state.AddBalance(
st.getTreasuryAddress(),
uint256.MustFromBig(new(big.Int).Mul(st.evm.Context.BaseFee, new(big.Int).SetUint64(st.gasUsed()))),
totalFee := new(big.Int).Mul(st.evm.Context.BaseFee, new(big.Int).SetUint64(st.gasUsed()))
feeCoinbase := new(big.Int).Div(
new(big.Int).Mul(totalFee, new(big.Int).SetUint64(uint64(st.msg.BasefeeSharingPctg))),
new(big.Int).SetUint64(100),
)
feeTreasury := new(big.Int).Sub(totalFee, feeCoinbase)
st.state.AddBalance(st.getTreasuryAddress(), uint256.MustFromBig(feeTreasury))
st.state.AddBalance(st.evm.Context.Coinbase, uint256.MustFromBig(feeCoinbase))
}
}

Expand Down Expand Up @@ -530,3 +537,9 @@ func (st *StateTransition) getTreasuryAddress() common.Address {
suffix,
)
}

// DecodeOntakeExtraData decodes an ontake block's extradata, returns basefeeSharingPctg configurations,
// the corresponding enocding function in protocol is `LibProposing._encodeGasConfigs`.
func DecodeOntakeExtraData(extradata []byte) uint8 {
return uint8(new(big.Int).SetBytes(extradata).Uint64())
}
10 changes: 10 additions & 0 deletions core/taiko_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/ethereum/go-ethereum/params"
)

var (
InternalDevnetOntakeBlock = new(big.Int).SetUint64(374_400)
HeklaOntakeBlock = new(big.Int).SetUint64(720_000)
MainnetOntakeBlock = new(big.Int).SetUint64(374_400)
)

// TaikoGenesisBlock returns the Taiko network genesis block configs.
func TaikoGenesisBlock(networkID uint64) *Genesis {
chainConfig := params.TaikoChainConfig
Expand All @@ -17,9 +23,11 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
switch networkID {
case params.TaikoMainnetNetworkID.Uint64():
chainConfig.ChainID = params.TaikoMainnetNetworkID
chainConfig.OntakeBlock = MainnetOntakeBlock
allocJSON = taikoGenesis.MainnetGenesisAllocJSON
case params.TaikoInternalL2ANetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
chainConfig.OntakeBlock = InternalDevnetOntakeBlock
allocJSON = taikoGenesis.InternalL2AGenesisAllocJSON
case params.TaikoInternalL2BNetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalL2BNetworkID
Expand All @@ -44,12 +52,14 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
allocJSON = taikoGenesis.KatlaGenesisAllocJSON
case params.HeklaNetworkID.Uint64():
chainConfig.ChainID = params.HeklaNetworkID
chainConfig.OntakeBlock = HeklaOntakeBlock
allocJSON = taikoGenesis.HeklaGenesisAllocJSON
case params.PreconfsNetworkID.Uint64():
chainConfig.ChainID = params.PreconfsNetworkID
allocJSON = taikoGenesis.PreconfsGenesisAllocJSON
default:
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
chainConfig.OntakeBlock = InternalDevnetOntakeBlock
allocJSON = taikoGenesis.InternalL2AGenesisAllocJSON
}

Expand Down
Loading

0 comments on commit b96e4b7

Please sign in to comment.