aboutsummaryrefslogtreecommitdiffstats
path: root/core/state_transition.go
diff options
context:
space:
mode:
authorbojie <bojie@dexon.org>2019-01-31 18:23:46 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit13651db29d3534620bf156be1539857cf558d352 (patch)
tree433495c877c633040b0aff078b4b724085376d3b /core/state_transition.go
parent7058db1105704ba338220d5070f1fcb0fcfbfbe8 (diff)
downloadgo-tangerine-13651db29d3534620bf156be1539857cf558d352.tar
go-tangerine-13651db29d3534620bf156be1539857cf558d352.tar.gz
go-tangerine-13651db29d3534620bf156be1539857cf558d352.tar.bz2
go-tangerine-13651db29d3534620bf156be1539857cf558d352.tar.lz
go-tangerine-13651db29d3534620bf156be1539857cf558d352.tar.xz
go-tangerine-13651db29d3534620bf156be1539857cf558d352.tar.zst
go-tangerine-13651db29d3534620bf156be1539857cf558d352.zip
transaction: use all transaction gas to reduce attack intention (#180)
The ci test in /tests will use origin evm logic.
Diffstat (limited to 'core/state_transition.go')
-rw-r--r--core/state_transition.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/core/state_transition.go b/core/state_transition.go
index 3b5ea6a2f..ce05e54a2 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -18,6 +18,7 @@ package core
import (
"errors"
+ "flag"
"math"
"math/big"
@@ -27,6 +28,8 @@ import (
"github.com/dexon-foundation/dexon/params"
)
+var legacyEvm = flag.Bool("legacy-evm", false, "make evm run origin logic")
+
var (
errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
)
@@ -221,12 +224,33 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
return nil, 0, false, vmerr
}
}
- st.refundGas()
+
+ if *legacyEvm {
+ st.refundGas()
+ } else {
+ st.dexonRefundGas()
+ }
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice))
return ret, st.gasUsed(), vmerr != nil, err
}
+func (st *StateTransition) dexonRefundGas() {
+ // Apply refund counter, capped to half of the used gas.
+ refund := st.gasUsed() / 2
+ if refund > st.state.GetRefund() {
+ refund = st.state.GetRefund()
+ }
+
+ // Return ETH for remaining gas, exchanged at the original rate.
+ remaining := new(big.Int).Mul(new(big.Int).SetUint64(refund), st.gasPrice)
+ st.state.AddBalance(st.msg.From(), remaining)
+
+ // Also return remaining gas to the block gas counter so it is
+ // available for the next transaction.
+ st.gp.AddGas(refund)
+}
+
func (st *StateTransition) refundGas() {
// Apply refund counter, capped to half of the used gas.
refund := st.gasUsed() / 2