Skip to content

Commit 3c09f3c

Browse files
committed
Replaced hard-coded fees for precompile gas costs with constants from ethereum-common
1 parent a4e547e commit 3c09f3c

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

lib/precompiled/05-modexp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const utils = require('ethereumjs-util')
22
const BN = utils.BN
33
const error = require('../constants.js').ERROR
4+
const fees = require('ethereum-common')
45

5-
const Gquaddivisor = 20
6+
const Gquaddivisor = fees.modexpGquaddivisor.v
67

78
function multComplexity (x) {
89
if (x <= 64) {

lib/precompiled/06-ecadd.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const utils = require('ethereumjs-util')
22
const BN = utils.BN
33
const error = require('../constants.js').ERROR
4+
const fees = require('ethereum-common')
45

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

13-
// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
14-
results.gasUsed = new BN(500)
14+
results.gasUsed = new BN(fees.ecAddGas.v)
1515
try {
1616
let returnData = ecAdd_precompile(inputHexStr)
1717
results.return = Buffer.from(returnData, 'hex')

lib/precompiled/07-ecmul.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const utils = require('ethereumjs-util')
22
const BN = utils.BN
3+
const fees = require('ethereum-common')
34

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

24-
// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
25-
results.gasUsed = new BN(40000)
25+
results.gasUsed = new BN(fees.ecMulGas.v)
2626
return results
2727
}

lib/precompiled/08-ecpairing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const utils = require('ethereumjs-util')
22
const BN = utils.BN
33
const error = require('../constants.js').ERROR
4+
const fees = require('ethereum-common')
45

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

16-
// Temporary, replace with finalized gas cost from EIP spec (via ethereum-common)
17-
const gascost = 100000 + (inputDataSize * 80000)
17+
18+
const gascost = fees.ecPairingGas.v + (inputDataSize * fees.ecPairingWordGas.v)
1819
results.gasUsed = new BN(gascost)
1920

2021
if (opts.gasLimit.ltn(gascost)) {

0 commit comments

Comments
 (0)