Skip to content

Commit

Permalink
feat(core): use TaikoL2 address as the treasury address (#141)
Browse files Browse the repository at this point in the history
* feat(core): use `TaikoL2` address as the treasury address

* feat: update l2 genesis
  • Loading branch information
davidtaikocha authored Dec 8, 2023
1 parent 19d3316 commit 6110b34
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 61 deletions.
21 changes: 16 additions & 5 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
Expand All @@ -29,10 +30,6 @@ import (
"github.com/ethereum/go-ethereum/params"
)

var (
treasury = common.HexToAddress("0xdf09A0afD09a63fb04ab3573922437e1e637dE8b")
)

// ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not.
type ExecutionResult struct {
Expand Down Expand Up @@ -451,7 +448,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// CHANGE(taiko): basefee is not burnt, but sent to a treasury instead.
if st.evm.ChainConfig().Taiko && st.evm.Context.BaseFee != nil && !st.msg.IsAnchor {
st.state.AddBalance(
treasury,
st.getTreasuryAddress(),
new(big.Int).Mul(st.evm.Context.BaseFee, new(big.Int).SetUint64(st.gasUsed())),
)
}
Expand Down Expand Up @@ -490,3 +487,17 @@ func (st *StateTransition) gasUsed() uint64 {
func (st *StateTransition) blobGasUsed() uint64 {
return uint64(len(st.msg.BlobHashes) * params.BlobTxBlobGasPerBlob)
}

// CHANGE(taiko): returns the treasury address based on chain ID.
func (st *StateTransition) getTreasuryAddress() common.Address {
var (
prefix = st.evm.ChainConfig().ChainID.String()
suffix = "10001"
)
return common.HexToAddress(
"0x" +
prefix +
strings.Repeat("0", common.AddressLength*2-len(prefix)-len(suffix)) +
suffix,
)
}
16 changes: 8 additions & 8 deletions core/taiko_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {

var allocJSON []byte
switch networkID {
case params.TaikoInternalNetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalNetworkID
allocJSON = taikoGenesis.InternalGenesisAllocJSON
case params.TaikoInternalL3NetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalL3NetworkID
allocJSON = taikoGenesis.InternalL3GenesisAllocJSON
case params.TaikoInternalL2ANetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
allocJSON = taikoGenesis.InternalL2AGenesisAllocJSON
case params.TaikoInternalL2BNetworkID.Uint64():
chainConfig.ChainID = params.TaikoInternalL2BNetworkID
allocJSON = taikoGenesis.InternalL2BGenesisAllocJSON
case params.SnaefellsjokullNetworkID.Uint64():
chainConfig.ChainID = params.SnaefellsjokullNetworkID
allocJSON = taikoGenesis.SnaefellsjokullGenesisAllocJSON
Expand All @@ -37,8 +37,8 @@ func TaikoGenesisBlock(networkID uint64) *Genesis {
chainConfig.ChainID = params.JolnirNetworkID
allocJSON = taikoGenesis.JolnirGenesisAllocJSON
default:
chainConfig.ChainID = params.TaikoInternalNetworkID
allocJSON = taikoGenesis.InternalGenesisAllocJSON
chainConfig.ChainID = params.TaikoInternalL2ANetworkID
allocJSON = taikoGenesis.InternalL2AGenesisAllocJSON
}

var alloc GenesisAlloc
Expand Down
8 changes: 4 additions & 4 deletions core/taiko_genesis/genesis_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
_ "embed"
)

//go:embed internal.json
var InternalGenesisAllocJSON []byte
//go:embed internal_l2a.json
var InternalL2AGenesisAllocJSON []byte

//go:embed internal_l3.json
var InternalL3GenesisAllocJSON []byte
//go:embed internal_l2b.json
var InternalL2BGenesisAllocJSON []byte

//go:embed snaefellsjokull.json
var SnaefellsjokullGenesisAllocJSON []byte
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,13 @@ var NetworkNames = map[string]string{
SepoliaChainConfig.ChainID.String(): "sepolia",
HoleskyChainConfig.ChainID.String(): "holesky",
// CHANGE(taiko): add Taiko network name.
TaikoInternalNetworkID.String(): "Taiko Internal Devnet",
SnaefellsjokullNetworkID.String(): "Taiko Alpha-1 (Snæfellsjökull)",
AskjaNetworkID.String(): "Taiko Alpha-2 (Askja)",
GrimsvotnNetworkID.String(): "Taiko Alpha-3 L2 (Grimsvotn)",
EldfellNetworkID.String(): "Taiko Alpha-4 L3 (Eldfell)",
JolnirNetworkID.String(): "Taiko Alpha-5 L2 (Jolnir)",
TaikoInternalL2ANetworkID.String(): "Taiko Internal L2A Devnet",
TaikoInternalL2BNetworkID.String(): "Taiko Internal L2B Devnet",
SnaefellsjokullNetworkID.String(): "Taiko Alpha-1 (Snæfellsjökull)",
AskjaNetworkID.String(): "Taiko Alpha-2 (Askja)",
GrimsvotnNetworkID.String(): "Taiko Alpha-3 L2 (Grimsvotn)",
EldfellNetworkID.String(): "Taiko Alpha-4 L3 (Eldfell)",
JolnirNetworkID.String(): "Taiko Alpha-5 L2 (Jolnir)",
}

// ChainConfig is the core config which determines the blockchain settings.
Expand Down
20 changes: 10 additions & 10 deletions params/taiko_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ func u64(val uint64) *uint64 { return &val }

// Network IDs
var (
TaikoInternalNetworkID = big.NewInt(167001)
TaikoInternalL3NetworkID = big.NewInt(167002)
SnaefellsjokullNetworkID = big.NewInt(167003)
AskjaNetworkID = big.NewInt(167004)
GrimsvotnNetworkID = big.NewInt(167005)
EldfellNetworkID = big.NewInt(167006)
JolnirNetworkID = big.NewInt(167007)
TaikoInternalL2ANetworkID = big.NewInt(167001)
TaikoInternalL2BNetworkID = big.NewInt(167002)
SnaefellsjokullNetworkID = big.NewInt(167003)
AskjaNetworkID = big.NewInt(167004)
GrimsvotnNetworkID = big.NewInt(167005)
EldfellNetworkID = big.NewInt(167006)
JolnirNetworkID = big.NewInt(167007)
)

var networkIDToChainConfig = map[*big.Int]*ChainConfig{
TaikoInternalNetworkID: TaikoChainConfig,
TaikoInternalL3NetworkID: TaikoChainConfig,
TaikoInternalL2ANetworkID: TaikoChainConfig,
TaikoInternalL2BNetworkID: TaikoChainConfig,
SnaefellsjokullNetworkID: TaikoChainConfig,
AskjaNetworkID: TaikoChainConfig,
GrimsvotnNetworkID: TaikoChainConfig,
Expand All @@ -43,7 +43,7 @@ func NetworkIDToChainConfigOrDefault(networkID *big.Int) *ChainConfig {
}

var TaikoChainConfig = &ChainConfig{
ChainID: TaikoInternalNetworkID, // Use Internal Devnet network ID by default.
ChainID: TaikoInternalL2ANetworkID, // Use Internal Devnet network ID by default.
HomesteadBlock: common.Big0,
EIP150Block: common.Big0,
EIP155Block: common.Big0,
Expand Down
8 changes: 4 additions & 4 deletions params/taiko_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func TestNetworkIDToChainConfigOrDefault(t *testing.T) {
wantChainConfig *ChainConfig
}{
{
"taikoInternal",
TaikoInternalNetworkID,
"taikoInternalL2ANetworkId",
TaikoInternalL2ANetworkID,
TaikoChainConfig,
},
{
"taikoInternalL3NetworkId",
TaikoInternalL3NetworkID,
"taikoInternalL2BNetworkId",
TaikoInternalL2BNetworkID,
TaikoChainConfig,
},
{
Expand Down

0 comments on commit 6110b34

Please sign in to comment.