Skip to content

Commit

Permalink
[evm] implement EIP-3529
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Mar 25, 2022
1 parent faf3c97 commit 98a477b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
11 changes: 9 additions & 2 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ func getChainConfig(g genesis.Blockchain, height uint64) *params.ChainConfig {
if g.IsIceland(height) {
chainConfig.ChainID = new(big.Int).SetUint64(uint64(config.EVMNetworkID()))
}
// enable Berlin
// enable Berlin and London
chainConfig.BerlinBlock = new(big.Int).SetUint64(g.ToBeEnabledBlockHeight)
chainConfig.LondonBlock = new(big.Int).SetUint64(g.ToBeEnabledBlockHeight)
return &chainConfig
}

Expand Down Expand Up @@ -365,8 +366,10 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte
var (
contractRawAddress = action.EmptyAddress
executor = vm.AccountRef(evmParams.txCtx.Origin)
london = evm.ChainConfig().IsLondon(evm.Context.BlockNumber)
ret []byte
evmErr error
refund uint64
)
if evmParams.contract == nil {
// create contract
Expand Down Expand Up @@ -395,7 +398,11 @@ func executeInEVM(ctx context.Context, evmParams *Params, stateDB *StateDBAdapte
if stateDB.Error() != nil {
log.L().Debug("statedb error", zap.Error(stateDB.Error()))
}
refund := (evmParams.gas - remainingGas) / 2
if !london {
refund = (evmParams.gas - remainingGas) / params.RefundQuotient
} else {
refund = (evmParams.gas - remainingGas) / params.RefundQuotientEIP3529
}
if refund > stateDB.GetRefund() {
refund = stateDB.GetRefund()
}
Expand Down
41 changes: 35 additions & 6 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package evm
import (
"context"
"errors"
"math"
"math/big"
"testing"

Expand Down Expand Up @@ -149,14 +150,41 @@ func TestConstantinople(t *testing.T) {
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
12289321,
},
// after Jutland
// Jutland - Kamchatka
{
action.EmptyAddress,
20000000,
13685401,
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
20000000,
13816440,
},
// Kamchatka - LordHowe
{
action.EmptyAddress,
13816441,
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
13979160,
},
// LordHowe - Midway
{
action.EmptyAddress,
13979161,
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
16509240,
},
// after Midway
{
action.EmptyAddress,
16509241,
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
math.MaxUint64,
},
}

Expand Down Expand Up @@ -235,12 +263,13 @@ func TestConstantinople(t *testing.T) {
require.Equal(isIceland, evmChainConfig.IsMuirGlacier(evm.Context.BlockNumber))
require.Equal(isIceland, chainRules.IsIstanbul)

// enable Berlin
// enable Berlin and London
isBerlin := g.IsToBeEnabled(e.height)
require.Equal(isBerlin, evmChainConfig.IsBerlin(evm.Context.BlockNumber))
require.Equal(isBerlin, chainRules.IsBerlin)
require.False(evmChainConfig.IsLondon(evm.Context.BlockNumber))
require.False(chainRules.IsLondon)
isLondon := g.IsToBeEnabled(e.height)
require.Equal(isLondon, evmChainConfig.IsLondon(evm.Context.BlockNumber))
require.Equal(isLondon, chainRules.IsLondon)
require.False(evmChainConfig.IsCatalyst(evm.Context.BlockNumber))
require.False(chainRules.IsCatalyst)
}
Expand Down

0 comments on commit 98a477b

Please sign in to comment.