From 857f523aee264047695311855d0130f3984000e1 Mon Sep 17 00:00:00 2001 From: Qi Zhou Date: Thu, 14 Apr 2022 01:13:05 -0700 Subject: [PATCH] add W3IP-5 fractional lock-for-storage --- core/vm/evm.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 8af230160af5..352b42df5a86 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -407,14 +407,28 @@ func (evm *EVM) checkContractStaking(contract *Contract, codeSize uint64) error codeSize = uint64(evm.StateDB.GetCodeSize(contract.Address())) } // Check if the remaining balance of the contract can cover the staking requirement - if !evm.StateDB.HasSuicided(contract.Address()) && codeSize > params.MaxCodeSizeSoft { - staking := big.NewInt(int64((codeSize - 1) / params.ExtcodeCopyChunkSize)) + if evm.StateDB.HasSuicided(contract.Address()) { + return nil + } + + if codeSize <= params.MaxCodeSizeSoft { + return nil + } + + var staking *big.Int + if evm.chainRules.IsPisa { + staking = big.NewInt(int64(codeSize - params.MaxCodeSizeSoft)) staking.Mul(staking, big.NewInt(int64(params.CodeStakingPerChunk))) + staking.Div(staking, big.NewInt(int64(params.ExtcodeCopyChunkSize))) + } else { + staking = big.NewInt(int64((codeSize - 1) / params.ExtcodeCopyChunkSize)) + staking.Mul(staking, big.NewInt(int64(params.CodeStakingPerChunk))) + } - if !evm.Context.CanTransfer(evm.StateDB, contract.Address(), staking) { - return ErrCodeInsufficientStake - } + if !evm.Context.CanTransfer(evm.StateDB, contract.Address(), staking) { + return ErrCodeInsufficientStake } + return nil }