Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mralj committed Oct 4, 2024
1 parent 1974d92 commit 99ccaf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
28 changes: 20 additions & 8 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,31 @@ func init() {
}

func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
var activePrecompiles PrecompiledContracts
switch {
case rules.IsVerkle:
return PrecompiledContractsVerkle
activePrecompiles = PrecompiledContractsVerkle
case rules.IsPrague:
return PrecompiledContractsPrague
activePrecompiles = PrecompiledContractsPrague
case rules.IsCancun:
return PrecompiledContractsCancun
activePrecompiles = PrecompiledContractsCancun
case rules.IsBerlin:
return PrecompiledContractsBerlin
activePrecompiles = PrecompiledContractsBerlin
case rules.IsIstanbul:
return PrecompiledContractsIstanbul
activePrecompiles = PrecompiledContractsIstanbul
case rules.IsByzantium:
return PrecompiledContractsByzantium
activePrecompiles = PrecompiledContractsByzantium
default:
return PrecompiledContractsHomestead
activePrecompiles = PrecompiledContractsHomestead
}

// [rollup-geth]
activeRollupPrecompiles := activeRollupPrecompiledContracts(rules)
for k, v := range activeRollupPrecompiles {
activePrecompiles[k] = v
}

return activePrecompiles
}

// ActivePrecompiledContracts returns a copy of precompiled contracts enabled with the current configuration.
Expand Down Expand Up @@ -281,6 +290,7 @@ type sha256hash struct{}
func (c *sha256hash) RequiredGas(input []byte) uint64 {
return uint64(len(input)+31)/32*params.Sha256PerWordGas + params.Sha256BaseGas
}

func (c *sha256hash) Run(input []byte) ([]byte, error) {
h := sha256.Sum256(input)
return h[:], nil
Expand All @@ -296,6 +306,7 @@ type ripemd160hash struct{}
func (c *ripemd160hash) RequiredGas(input []byte) uint64 {
return uint64(len(input)+31)/32*params.Ripemd160PerWordGas + params.Ripemd160BaseGas
}

func (c *ripemd160hash) Run(input []byte) ([]byte, error) {
ripemd := ripemd160.New()
ripemd.Write(input)
Expand All @@ -312,6 +323,7 @@ type dataCopy struct{}
func (c *dataCopy) RequiredGas(input []byte) uint64 {
return uint64(len(input)+31)/32*params.IdentityPerWordGas + params.IdentityBaseGas
}

func (c *dataCopy) Run(in []byte) ([]byte, error) {
return common.CopyBytes(in), nil
}
Expand Down Expand Up @@ -461,7 +473,7 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
// Modulo 0 is undefined, return zero
return common.LeftPadBytes([]byte{}, int(modLen)), nil
case base.BitLen() == 1: // a bit length of 1 means it's 1 (or -1).
//If base == 1, then we can just return base % mod (if mod >= 1, which it is)
// If base == 1, then we can just return base % mod (if mod >= 1, which it is)
v = base.Mod(base, mod).Bytes()
default:
v = base.Exp(base, exp, mod).Bytes()
Expand Down
15 changes: 0 additions & 15 deletions core/vm/contracts_rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ import (
"github.com/ethereum/go-ethereum/params"
)

type RollupPrecompiledContractsOverrides struct {
l1SLoadGetLatestL1Block func() *big.Int
}

func GenerateRollupPrecompiledContractsOverrides(evm *EVM) RollupPrecompiledContractsOverrides {
return RollupPrecompiledContractsOverrides{
l1SLoadGetLatestL1Block: getLatestL1BlockNumber(evm),
}
}

var rollupL1SloadAddress = common.BytesToAddress([]byte{0x10, 0x01})

var PrecompiledContractsRollupR0 = PrecompiledContracts{
Expand All @@ -37,11 +27,6 @@ func activeRollupPrecompiledContracts(rules params.Rules) PrecompiledContracts {
}

func (evm *EVM) activateRollupPrecompiledContracts() {
activeRollupPrecompiles := activeRollupPrecompiledContracts(evm.chainRules)
for k, v := range activeRollupPrecompiles {
evm.precompiles[k] = v
}

// NOTE: if L1SLoad was not activated via chain rules this is no-op
evm.precompiles.activateL1SLoad(evm.Config.L1RpcClient, evm.rollupPrecompileOverrides.l1SLoadGetLatestL1Block)
}
Expand Down

0 comments on commit 99ccaf7

Please sign in to comment.