From ac0f688edd90bc2976d0a10607230a58690e0f90 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Sat, 24 Nov 2018 15:35:19 +0100 Subject: [PATCH] core vm: Revert calls when balance > 128bits --- core/vm/ewasm.go | 2 -- core/vm/ewasm_eei.go | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/vm/ewasm.go b/core/vm/ewasm.go index b574f839f9..4f09faa0b9 100644 --- a/core/vm/ewasm.go +++ b/core/vm/ewasm.go @@ -109,7 +109,6 @@ func (in *InterpreterEWASM) Run(contract *Contract, input []byte, ro bool) ([]by in.contract = contract in.contract.Input = input - initialGas := contract.Gas module, err := wasm.ReadModule(bytes.NewReader(contract.Code), WrappedModuleResolver(in)) if err != nil { @@ -131,7 +130,6 @@ func (in *InterpreterEWASM) Run(contract *Contract, input []byte, ro bool) ([]by return nil, err } - // Check input and output types sig := module.FunctionIndexSpace[mainIndex].Sig if len(sig.ParamTypes) == 0 && len(sig.ReturnTypes) == 0 { diff --git a/core/vm/ewasm_eei.go b/core/vm/ewasm_eei.go index 710e755793..4dd19f3b39 100644 --- a/core/vm/ewasm_eei.go +++ b/core/vm/ewasm_eei.go @@ -439,6 +439,13 @@ func call(p *exec.Process, in *InterpreterEWASM, gas int64, addressOffset int32, return ErrEEICallFailure } + // Fail if the account's balance is greater than 128bits as discussed + // in https://github.com/ewasm/hera/issues/456 + if in.StateDB.GetBalance(contract.Address()).Cmp(check128bits) > 0 { + in.gasAccounting(contract.Gas) + return ErrEEICallRevert + } + if in.staticMode == true && value.Cmp(big.NewInt(0)) != 0 { in.gasAccounting(in.contract.Gas) return ErrEEICallFailure