Merge pull request #1174 from ethereum/yann300-patch-32

Validate input using BigNumber
pull/1196/head
yann300 4 years ago committed by GitHub
commit f8be36a5ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      apps/remix-ide/src/app/tabs/runTab/settings.js
  2. 12
      libs/remix-lib/src/execution/txRunner.ts

@ -1,3 +1,4 @@
import { BN } from 'ethereumjs-util'
const $ = require('jquery')
const yo = require('yo-yo')
const remixLib = require('@remix-project/remix-lib')
@ -65,14 +66,26 @@ class SettingsUI {
validateValue () {
const valueEl = this.el.querySelector('#value')
valueEl.value = parseInt(valueEl.value)
// assign 0 if given value is
// - empty
// - not valid (for ex 4345-54)
// - contains only '0's (for ex 0000) copy past or edit
if (!valueEl.value) valueEl.value = 0
if (!valueEl.value) {
// assign 0 if given value is
// - empty
valueEl.value = 0
return
}
let v
try {
v = new BN(valueEl.value, 10)
valueEl.value = v.toString(10)
} catch (e) {
// assign 0 if given value is
// - not valid (for ex 4345-54)
// - contains only '0's (for ex 0000) copy past or edit
valueEl.value = 0
}
// if giveen value is negative(possible with copy-pasting) set to 0
if (valueEl.value < 0) valueEl.value = 0
if (v.lt(0)) valueEl.value = 0
}
render () {

@ -118,7 +118,17 @@ export class TxRunner {
this.executionContext.vm().stateManager.getAccount(Address.fromString(from)).then((res) => {
// See https://github.com/ethereumjs/ethereumjs-tx/blob/master/docs/classes/transaction.md#constructor
// for initialization fields and their types
value = value ? parseInt(value) : 0
if (!value) value = 0
if (typeof value === 'string') {
if (value.startsWith('0x')) value = new BN(value.replace('0x', ''), 'hex')
else {
try {
value = new BN(value, 10)
} catch (e) {
return callback('Unable to parse the value ' + e.message)
}
}
}
const tx = Transaction.fromTxData({
nonce: new BN(res.nonce),
gasPrice: '0x1',

Loading…
Cancel
Save