Skip to content

Commit

Permalink
Charging NewAccountGas for creating new account in Quai State Size
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Sep 6, 2024
1 parent 3709fa3 commit c99c37f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
}
return nil, gas, stateGas, nil
}
newAccountCreationGas := params.CallNewAccountGas(evm.Context.QuaiStateSize)
if gas > newAccountCreationGas {
gas = gas - newAccountCreationGas
} else {
return nil, gas, stateGas, ErrInsufficientBalance
}
stateGas += params.CallNewAccountGas(evm.Context.QuaiStateSize)
evm.StateDB.CreateAccount(internalAddr)
}
Expand Down Expand Up @@ -456,6 +462,13 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if evm.depth > int(params.CallCreateDepth) {
return nil, common.Zero, gas, 0, ErrDepth
}
newAccountCreationGas := params.CallNewAccountGas(evm.Context.QuaiStateSize)
if gas > newAccountCreationGas {
gas = gas - newAccountCreationGas
} else {
return nil, common.Zero, gas, 0, ErrInsufficientBalance
}
stateUsed := newAccountCreationGas
if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
return nil, common.Zero, gas, 0, ErrInsufficientBalance
}
Expand All @@ -476,7 +489,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
// Create a new account on the state
snapshot := evm.StateDB.Snapshot()
stateUsed := params.CallNewAccountGas(evm.Context.QuaiStateSize)
evm.StateDB.CreateAccount(internalContractAddr)

evm.StateDB.SetNonce(internalContractAddr, 1)
Expand Down

0 comments on commit c99c37f

Please sign in to comment.