Skip to content

Commit

Permalink
Merge pull request #24 from memekas/feat/update-and-fix-genesis
Browse files Browse the repository at this point in the history
Increase system contracts size. Updates for the genesis
  • Loading branch information
dmitry123 authored Feb 1, 2024
2 parents 08b5c06 + bba0075 commit 1ef706c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
42 changes: 24 additions & 18 deletions common/systemcontract/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ const (

// BAS contacts
const (
StakingPoolContract = "0x0000000000000000000000000000000000007001"
GovernanceContract = "0x0000000000000000000000000000000000007002"
ChainConfigContract = "0x0000000000000000000000000000000000007003"
RuntimeUpgradeContract = "0x0000000000000000000000000000000000007004"
DeployerProxyContract = "0x0000000000000000000000000000000000007005"
StakingPoolContract = "0x0000000000000000000000000000000000007001"
GovernanceContract = "0x0000000000000000000000000000000000007002"
ChainConfigContract = "0x0000000000000000000000000000000000007003"
RuntimeUpgradeContract = "0x0000000000000000000000000000000000007004"
DeployerProxyContract = "0x0000000000000000000000000000000000007005"
EvmHookRuntimeUpgradeContract = "0x0000000000000000000000000000000000007f01"
EvmHookDeployerProxyContract = "0x0000000000000000000000000000000000007f02"
IntermediarySystemContract = "0xfffffffffffffffffffffffffffffffffffffffe"
)

var (
StakingPoolContractAddress = common.HexToAddress(StakingPoolContract)
GovernanceContractAddress = common.HexToAddress(GovernanceContract)
ChainConfigContractAddress = common.HexToAddress(ChainConfigContract)
RuntimeUpgradeContractAddress = common.HexToAddress(RuntimeUpgradeContract)
DeployerProxyContractAddress = common.HexToAddress(DeployerProxyContract)
StakingPoolContractAddress = common.HexToAddress(StakingPoolContract)
GovernanceContractAddress = common.HexToAddress(GovernanceContract)
ChainConfigContractAddress = common.HexToAddress(ChainConfigContract)
RuntimeUpgradeContractAddress = common.HexToAddress(RuntimeUpgradeContract)
DeployerProxyContractAddress = common.HexToAddress(DeployerProxyContract)
EvmHookRuntimeUpgradeContractAddress = common.HexToAddress(EvmHookRuntimeUpgradeContract)
EvmHookDeployerProxyContractAddress = common.HexToAddress(EvmHookDeployerProxyContract)
IntermediarySystemContractAddress = common.HexToAddress(IntermediarySystemContract)
)

var systemContracts = map[common.Address]bool{
Expand All @@ -50,16 +56,16 @@ var systemContracts = map[common.Address]bool{
common.HexToAddress(CrossChainContract): false,
common.HexToAddress(TokenManagerContract): false,
// BAS smart contracts
common.HexToAddress(StakingPoolContract): true,
common.HexToAddress(GovernanceContract): true,
common.HexToAddress(ChainConfigContract): true,
common.HexToAddress(RuntimeUpgradeContract): true,
common.HexToAddress(DeployerProxyContract): true,
common.HexToAddress(StakingPoolContract): true,
common.HexToAddress(GovernanceContract): true,
common.HexToAddress(ChainConfigContract): true,
common.HexToAddress(RuntimeUpgradeContract): true,
common.HexToAddress(DeployerProxyContract): true,
common.HexToAddress(EvmHookRuntimeUpgradeContract): true,
common.HexToAddress(EvmHookDeployerProxyContract): true,
common.HexToAddress(IntermediarySystemContract): true,
}

func IsSystemContract(address common.Address) bool {
return systemContracts[address]
}

var EvmHookRuntimeUpgradeAddress = common.HexToAddress("0x0000000000000000000000000000000000007f01")
var EvmHookDeployerProxyAddress = common.HexToAddress("0x0000000000000000000000000000000000007f02")
6 changes: 6 additions & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ func (s *stateObject) GetState(key common.Hash) common.Hash {
return s.GetCommittedState(key)
}

// GetDirtyStorage returns the dirtyStorage.
// BAS. It's needed to generate the genesis.
func (s *stateObject) GetDirtyStorage() Storage {
return s.dirtyStorage
}

func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) {
if value, cached := s.originStorage[key]; cached {
return value, true
Expand Down
6 changes: 6 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject {
return nil
}

// getStateObjects returns the stateObjects.
// BAS. It's needed to generate the genesis.
func (s *StateDB) GetStateObjects() map[common.Address]*stateObject {
return s.stateObjects
}

// getDeletedStateObject is similar to getStateObject, but instead of returning
// nil for a deleted state object, it returns the actual object with the deleted
// flag set. This is needed by the state journal to revert to the correct s-
Expand Down
4 changes: 3 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/systemcontract"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -487,7 +488,8 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
ret, err := evm.interpreter.Run(contract, nil, false)

// Check whether the max code size has been exceeded, assign err if the case.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
// BAS. System contracts are allowed to deploy contracts with unlimited size.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize && !systemcontract.IsSystemContract(caller.Address()) {
err = ErrMaxCodeSizeExceeded
}

Expand Down

0 comments on commit 1ef706c

Please sign in to comment.