-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
482 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cancun | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
var ( | ||
// EIP 4844 | ||
GAS_PER_BLOB = uint64(0x20000) | ||
|
||
MIN_DATA_GASPRICE = uint64(1) | ||
MAX_BLOB_GAS_PER_BLOCK = uint64(786432) | ||
TARGET_BLOB_GAS_PER_BLOCK = uint64(393216) | ||
|
||
TARGET_BLOBS_PER_BLOCK = uint64(TARGET_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) | ||
MAX_BLOBS_PER_BLOCK = uint64(MAX_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) | ||
|
||
BLOB_GASPRICE_UPDATE_FRACTION = uint64(3338477) | ||
|
||
BLOB_COMMITMENT_VERSION_KZG = byte(0x01) | ||
|
||
// EIP 4788 | ||
HISTORY_STORAGE_ADDRESS = common.HexToAddress("0x000000000000000000000000000000000000000b") | ||
HISTORICAL_ROOTS_MODULUS = uint64(98304) | ||
|
||
// Test constants | ||
DATAHASH_START_ADDRESS = big.NewInt(0x20000) | ||
DATAHASH_ADDRESS_COUNT = 1000 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cancun | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
) | ||
|
||
// ConfigGenesis configures the genesis block for the Cancun fork. | ||
func ConfigGenesis(genesis *core.Genesis, forkTimestamp uint64) error { | ||
if genesis.Config.ShanghaiTime == nil { | ||
return fmt.Errorf("cancun fork requires shanghai fork") | ||
} | ||
genesis.Config.CancunTime = &forkTimestamp | ||
if *genesis.Config.ShanghaiTime > forkTimestamp { | ||
return fmt.Errorf("cancun fork must be after shanghai fork") | ||
} | ||
if genesis.Timestamp >= forkTimestamp { | ||
if genesis.BlobGasUsed == nil { | ||
genesis.BlobGasUsed = new(uint64) | ||
} | ||
if genesis.ExcessBlobGas == nil { | ||
genesis.ExcessBlobGas = new(uint64) | ||
} | ||
} | ||
|
||
// Add bytecode pre deploy to the EIP-4788 address. | ||
genesis.Alloc[HISTORY_STORAGE_ADDRESS] = core.GenesisAccount{ | ||
Balance: common.Big0, | ||
Nonce: 1, | ||
Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b42620180004206555f3562018000420662018000015500"), | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Configure specific test genesis accounts related to Cancun funtionality. | ||
func ConfigTestAccounts(genesis *core.Genesis) error { | ||
// Add accounts that use the DATAHASH opcode | ||
datahashCode := []byte{ | ||
0x5F, // PUSH0 | ||
0x80, // DUP1 | ||
0x49, // DATAHASH | ||
0x55, // SSTORE | ||
0x60, // PUSH1(0x01) | ||
0x01, | ||
0x80, // DUP1 | ||
0x49, // DATAHASH | ||
0x55, // SSTORE | ||
0x60, // PUSH1(0x02) | ||
0x02, | ||
0x80, // DUP1 | ||
0x49, // DATAHASH | ||
0x55, // SSTORE | ||
0x60, // PUSH1(0x03) | ||
0x03, | ||
0x80, // DUP1 | ||
0x49, // DATAHASH | ||
0x55, // SSTORE | ||
} | ||
|
||
for i := 0; i < DATAHASH_ADDRESS_COUNT; i++ { | ||
address := common.BigToAddress(big.NewInt(0).Add(DATAHASH_START_ADDRESS, big.NewInt(int64(i)))) | ||
// check first if the address is already in the genesis | ||
if _, ok := genesis.Alloc[address]; ok { | ||
panic(fmt.Errorf("reused address %s during genesis configuration for cancun", address.Hex())) | ||
} | ||
genesis.Alloc[address] = core.GenesisAccount{ | ||
Code: datahashCode, | ||
Balance: common.Big0, | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" | ||
) | ||
|
||
func (f *ForkConfig) ConfigGenesis(genesis *core.Genesis) error { | ||
if f.ShanghaiTimestamp != nil { | ||
shanghaiTime := f.ShanghaiTimestamp.Uint64() | ||
genesis.Config.ShanghaiTime = &shanghaiTime | ||
|
||
if genesis.Timestamp >= shanghaiTime { | ||
// Remove PoW altogether | ||
genesis.Difficulty = common.Big0 | ||
genesis.Config.TerminalTotalDifficulty = common.Big0 | ||
genesis.Config.Clique = nil | ||
genesis.ExtraData = []byte{} | ||
} | ||
} | ||
if f.CancunTimestamp != nil { | ||
if err := cancun.ConfigGenesis(genesis, f.CancunTimestamp.Uint64()); err != nil { | ||
return fmt.Errorf("failed to configure cancun fork: %v", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package globals | ||
|
||
var ( | ||
// Engine API errors | ||
SERVER_ERROR = pInt(-32000) | ||
INVALID_REQUEST = pInt(-32600) | ||
METHOD_NOT_FOUND = pInt(-32601) | ||
INVALID_PARAMS_ERROR = pInt(-32602) | ||
INTERNAL_ERROR = pInt(-32603) | ||
INVALID_JSON = pInt(-32700) | ||
|
||
UNKNOWN_PAYLOAD = pInt(-38001) | ||
INVALID_FORKCHOICE_STATE = pInt(-38002) | ||
INVALID_PAYLOAD_ATTRIBUTES = pInt(-38003) | ||
TOO_LARGE_REQUEST = pInt(-38004) | ||
UNSUPPORTED_FORK_ERROR = pInt(-38005) | ||
) | ||
|
||
func pInt(v int) *int { | ||
return &v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.