git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 8ff4e4d6eb9c888cbb0c757e872b6da49d98c1e8

Kernel: assume that every number is an instance of U256

Alex Beregszaszi committed on 8/23/2016, 12:27:46 AM
Parent: c6e879cecacacc8ce87b4741f02493827fd992c8

Files changed

index.jschanged
index.jsView
@@ -21,8 +21,9 @@
2121
2222 const DebugInterface = require('./debugInterface.js')
2323
2424 const Address = require('./address.js')
25+const U256 = require('./u256.js')
2526 const Utils = require('./utils.js')
2627
2728 module.exports = class Kernel {
2829 // runs some code in the VM
@@ -101,10 +102,10 @@
101102 //this.environment.state.set(address, { stateRoot: stateRoot })
102103
103104 return {
104105 executionOutcome: 1, // success
105- gasLeft: environment.gasLimit, // this starts as the limit and results as the gas left
106- gasRefund: environment.gasRefund,
106+ gasLeft: new U256(environment.gasLimit), // this starts as the limit and results as the gas left
107+ gasRefund: new U256(environment.gasRefund),
107108 returnValue: environment.returnValue,
108109 selfDestructAddress: environment.selfDestructAddress,
109110 logs: environment.logs
110111 }
@@ -135,19 +136,19 @@
135136 throw new Error('Sender account not found')
136137 }
137138
138139 // deduct gasLimit * gasPrice from sender
139- if (fromAccount.balance < (tx.gasLimit * tx.gasPrice)) {
140+ if (fromAccount.balance.lt(tx.gasLimit.mul(tx.gasPrice))) {
140141 throw new Error('Insufficient account balance')
141142 }
142143
143- fromAccount.balance -= ts.gasLimit * tx.gasPrice
144+ fromAccount.balance = fromAccount.balance.sub(ts.gasLimit.mul(tx.gasPrice))
144145
145146 let ret = this.callHandler(tx.to, tx.gasLimit, tx.gasPrice, tx.value, tx.data)
146147
147148 // refund gas
148149 if (ret.executionOutcome === 1) {
149- fromAccount.balance += (ret.gasLeft + ret.gasRefund) * tx.gasPrice
150+ fromAccount.balance = fromAccount.balance.add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund)))
150151 }
151152
152153 // save new state?
153154

Built with git-ssb-web