Skip to content

Commit

Permalink
Replaced hard-coded fees for precompile gas costs with constants from…
Browse files Browse the repository at this point in the history
… ethereum-common
  • Loading branch information
holgerd77 committed Sep 15, 2017
1 parent a4e547e commit 3c09f3c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/precompiled/05-modexp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const utils = require('ethereumjs-util')
const BN = utils.BN
const error = require('../constants.js').ERROR
const fees = require('ethereum-common')

const Gquaddivisor = 20
const Gquaddivisor = fees.modexpGquaddivisor.v

function multComplexity (x) {
if (x <= 64) {
Expand Down
4 changes: 2 additions & 2 deletions lib/precompiled/06-ecadd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const utils = require('ethereumjs-util')
const BN = utils.BN
const error = require('../constants.js').ERROR
const fees = require('ethereum-common')

const bn128_module = require('rustbn.js')
const ecAdd_precompile = bn128_module.cwrap('ec_add', 'string', ['string'])
Expand All @@ -10,8 +11,7 @@ module.exports = function (opts) {
let data = opts.data
let inputHexStr = data.toString('hex')

// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
results.gasUsed = new BN(500)
results.gasUsed = new BN(fees.ecAddGas.v)
try {
let returnData = ecAdd_precompile(inputHexStr)
results.return = Buffer.from(returnData, 'hex')
Expand Down
4 changes: 2 additions & 2 deletions lib/precompiled/07-ecmul.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const utils = require('ethereumjs-util')
const BN = utils.BN
const fees = require('ethereum-common')

const bn128_module = require('rustbn.js')
const ecMul_precompile = bn128_module.cwrap('ec_mul', 'string', ['string'])
Expand All @@ -21,7 +22,6 @@ module.exports = function (opts) {
results.exception = 0
}

// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
results.gasUsed = new BN(40000)
results.gasUsed = new BN(fees.ecMulGas.v)
return results
}
5 changes: 3 additions & 2 deletions lib/precompiled/08-ecpairing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const utils = require('ethereumjs-util')
const BN = utils.BN
const error = require('../constants.js').ERROR
const fees = require('ethereum-common')

const bn128_module = require('rustbn.js')
const ecPairing_precompile = bn128_module.cwrap('ec_pairing', 'string', ['string'])
Expand All @@ -13,8 +14,8 @@ module.exports = function (opts) {
let inputData = Buffer.from(inputHexStr, 'hex')
let inputDataSize = Math.floor(inputData.length / 192)

// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
const gascost = 100000 + (inputDataSize * 80000)

const gascost = fees.ecPairingGas.v + (inputDataSize * fees.ecPairingWordGas.v)
results.gasUsed = new BN(gascost)

if (opts.gasLimit.ltn(gascost)) {
Expand Down

0 comments on commit 3c09f3c

Please sign in to comment.