Skip to content

Commit

Permalink
Fix gas calculations for Byzantium precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Oct 16, 2017
1 parent 500e1ad commit d8cbf6f
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static class ModExp extends PrecompiledContract {
@Override
public long getGasForData(byte[] data) {

if (data == null) return 0;
if (data == null) data = EMPTY_BYTE_ARRAY;

int baseLen = parseLen(data, 0);
int expLen = parseLen(data, 1);
Expand Down Expand Up @@ -329,17 +329,14 @@ public static class BN128Addition extends PrecompiledContract {

@Override
public long getGasForData(byte[] data) {

if (data == null) return 0;

return 500;
}

@Override
public Pair<Boolean, byte[]> execute(byte[] data) {

if (data == null)
return Pair.of(false, EMPTY_BYTE_ARRAY);
data = EMPTY_BYTE_ARRAY;

byte[] x1 = parseWord(data, 0);
byte[] y1 = parseWord(data, 1);
Expand Down Expand Up @@ -379,17 +376,14 @@ public static class BN128Multiplication extends PrecompiledContract {

@Override
public long getGasForData(byte[] data) {

if (data == null) return 0;

return 40000;
}

@Override
public Pair<Boolean, byte[]> execute(byte[] data) {

if (data == null)
return Pair.of(false, EMPTY_BYTE_ARRAY);
data = EMPTY_BYTE_ARRAY;

byte[] x = parseWord(data, 0);
byte[] y = parseWord(data, 1);
Expand Down Expand Up @@ -432,7 +426,7 @@ public static class BN128Pairing extends PrecompiledContract {
@Override
public long getGasForData(byte[] data) {

if (data == null) return 0;
if (data == null) return 100000;

return 80000 * (data.length / PAIR_SIZE) + 100000;
}
Expand All @@ -441,7 +435,7 @@ public long getGasForData(byte[] data) {
public Pair<Boolean, byte[]> execute(byte[] data) {

if (data == null)
return Pair.of(false, EMPTY_BYTE_ARRAY);
data = EMPTY_BYTE_ARRAY;

// fail if input len is not a multiple of PAIR_SIZE
if (data.length % PAIR_SIZE > 0)
Expand Down

0 comments on commit d8cbf6f

Please sign in to comment.