Skip to content

Commit

Permalink
Temporary Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed May 6, 2024
1 parent b2fd9b8 commit 1ba1bd1
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions x/evm/keeper/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ func (k *Keeper) SyncEnabledPrecompiles(ctx sdk.Context, enabledPrecompiles []co
return nil
}

func HexToAddresses(hexAddrs []string) []common.Address {
addrs := make([]common.Address, len(hexAddrs))
for i, hexAddr := range hexAddrs {
addrs[i] = common.HexToAddress(hexAddr)
}

return addrs
}

func AddressesToHex(addrs []common.Address) []string {
hexAddrs := make([]string, len(addrs))
for i, addr := range addrs {
hexAddrs[i] = addr.Hex()
}

return hexAddrs
}

func SyncEnabledPrecompiles(stateDB StateDB, old []common.Address, new []common.Address) error {
cfg := DetermineInitializationConfig(old, new)
return ApplyInitializationConfig(stateDB, cfg)
Expand Down Expand Up @@ -97,6 +79,10 @@ func ApplyInitializationConfig(stateDB StateDB, cfg *InitializationConfig) error
return nil
}

// SetDifference returns difference between two sets, example can be:
// a : {1, 2, 3}
// b : {1, 3}
// diff: {2}
func SetDifference(a []common.Address, b []common.Address) []common.Address {
bMap := make(map[common.Address]struct{}, len(b))
for _, elem := range b {
Expand All @@ -113,6 +99,7 @@ func SetDifference(a []common.Address, b []common.Address) []common.Address {
return diff
}

// ValidatePrecompilesInitialized validates that precompiles at specified addresses are initialized.
func ValidatePrecompilesInitialized(stateDB StateDB, addrs []common.Address) error {
for _, addr := range addrs {
nonce := stateDB.GetNonce(addr)
Expand All @@ -127,6 +114,7 @@ func ValidatePrecompilesInitialized(stateDB StateDB, addrs []common.Address) err
return nil
}

// ValidatePrecompilesUninitialized validates that precompiles at specified addresses are uninitialized.
func ValidatePrecompilesUninitialized(stateDB StateDB, addrs []common.Address) error {
for _, addr := range addrs {
nonce := stateDB.GetNonce(addr)
Expand All @@ -141,6 +129,9 @@ func ValidatePrecompilesUninitialized(stateDB StateDB, addrs []common.Address) e
return nil
}

// InitializePrecompiles initializes list of precompiles at specified addresses.
// Initialization of precompile sets non-zero nonce and non-empty code at specified address to resemble behaviour of

Check failure on line 133 in x/evm/keeper/precompile.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

`behaviour` is a misspelling of `behavior` (misspell)
// regular smart contract.
func InitializePrecompiles(stateDB StateDB, addrs []common.Address) {
for _, addr := range addrs {
// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
Expand All @@ -153,9 +144,29 @@ func InitializePrecompiles(stateDB StateDB, addrs []common.Address) {
}
}

// UninitializePrecompiles uninitializes list of precompiles at specified addresses.
// Uninitialization of precompile sets zero nonce and empty code at specified address.
func UninitializePrecompiles(stateDB StateDB, addrs []common.Address) {
for _, addr := range addrs {
stateDB.SetNonce(addr, 0)
stateDB.SetCode(addr, nil)
}
}

func HexToAddresses(hexAddrs []string) []common.Address {
addrs := make([]common.Address, len(hexAddrs))
for i, hexAddr := range hexAddrs {
addrs[i] = common.HexToAddress(hexAddr)
}

return addrs
}

func AddressesToHex(addrs []common.Address) []string {
hexAddrs := make([]string, len(addrs))
for i, addr := range addrs {
hexAddrs[i] = addr.Hex()
}

return hexAddrs
}

0 comments on commit 1ba1bd1

Please sign in to comment.