aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2020-09-19 01:28:41 -0400
committerDeterminant <tederminant@gmail.com>2020-09-19 01:28:41 -0400
commit2580891f8be274b43ffa633edb11b8332e21f172 (patch)
tree24ff7da5724f7012979f23e75e0d48d5441def98
parent573ff7bbf2a0b529fd3f8acf4aa825e446c73423 (diff)
...
-rw-r--r--plugin/evm/export_tx.go12
-rw-r--r--plugin/evm/vm.go2
2 files changed, 10 insertions, 4 deletions
diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go
index 231afee..d9e2829 100644
--- a/plugin/evm/export_tx.go
+++ b/plugin/evm/export_tx.go
@@ -228,13 +228,17 @@ func (tx *UnsignedExportTx) EVMStateTransfer(vm *VM, state *state.StateDB) error
log.Info("crosschain C->X", "addr", from.Address, "amount", from.Amount)
amount := new(big.Int).Mul(
new(big.Int).SetUint64(from.Amount), x2cRate)
- if state.GetBalance(from.Address).Cmp(amount) < 0 {
- return errInsufficientFunds
- }
if from.AssetID == vm.ctx.AVAXAssetID {
+ if state.GetBalance(from.Address).Cmp(amount) < 0 {
+ return errInsufficientFunds
+ }
state.SubBalance(from.Address, amount)
} else {
- state.SubBalanceMultiCoin(from.Address, from.AssetID.Key(), amount)
+ assetID := from.AssetID.Key()
+ if state.GetBalanceMultiCoin(from.Address, assetID).Cmp(amount) < 0 {
+ return errInsufficientFunds
+ }
+ state.SubBalanceMultiCoin(from.Address, assetID, amount)
}
if state.GetNonce(from.Address) != from.Nonce {
return errInvalidNonce
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index 1f025ee..2ce72be 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -890,6 +890,8 @@ func (vm *VM) GetSpendableCanonical(keys []*crypto.PrivateKeySECP256K1R, assetID
}
inputs := []EVMInput{}
signers := [][]*crypto.PrivateKeySECP256K1R{}
+ // NOTE: we assume all keys correspond to distinct accounts here (so the
+ // nonce handling in export_tx.go is correct)
for _, key := range keys {
if amount == 0 {
break