Fix Index out of Bounds on Yolo with BLS12_G1MULTIEXP and BLS12_G2MULTIEXP (#1125)

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/1128/head
Karim T 4 years ago committed by GitHub
parent 109d548e85
commit 0a01ddb785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/AbstractBLS12PrecompiledContract.java
  2. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/BLS12G1MultiExpPrecompiledContract.java
  3. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/BLS12G2MultiExpPrecompiledContract.java
  4. 1
      ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/mainnet/precompiles/g1_multiexp.csv
  5. 2
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java

@ -43,6 +43,8 @@ public abstract class AbstractBLS12PrecompiledContract implements PrecompiledCon
174
};
static final int MAX_DISCOUNT = 174;
private final String name;
private final byte operationId;
@ -79,4 +81,17 @@ public abstract class AbstractBLS12PrecompiledContract implements PrecompiledCon
return null;
}
}
protected int getDiscount(final int k) {
// `k * multiplication_cost * discount / multiplier` where `multiplier = 1000`
// multiplication_cost and multiplier are folded into one constant as a long and placed first to
// prevent int32 overflow
// there was a table prepared for discount in case of k <= 128 points in the multiexponentiation
// with a discount cup max_discount for k > 128.
if (k >= DISCOUNT_TABLE.length) {
return MAX_DISCOUNT;
}
return DISCOUNT_TABLE[k];
}
}

@ -29,9 +29,6 @@ public class BLS12G1MultiExpPrecompiledContract extends AbstractBLS12Precompiled
@Override
public Gas gasRequirement(final Bytes input) {
final int k = input.size() / 160;
// `k * multiplication_cost * discount / multiplier` where `multiplier = 1000`
// multiplication_cost and multiplier are folded into one constant as a long and placed first to
// prevent int32 overflow
return Gas.of(12L * k * DISCOUNT_TABLE[k]);
return Gas.of(12L * k * getDiscount(k));
}
}

@ -29,9 +29,6 @@ public class BLS12G2MultiExpPrecompiledContract extends AbstractBLS12Precompiled
@Override
public Gas gasRequirement(final Bytes input) {
final int k = input.size() / 288;
// `k * multiplication_cost * discount / multiplier` where `multiplier = 1000`
// multiplication_cost and multiplier are folded into one constant as a long and placed first to
// prevent int32 overflow
return Gas.of(55L * k * DISCOUNT_TABLE[k]);
return Gas.of(55L * k * getDiscount(k));
}
}

@ -155,7 +155,7 @@ public class DiscoveryConfiguration {
public static List<EnodeURL> YOLO_V1_BOOTSTRAP_NODES =
Collections.unmodifiableList(
Stream.of(
"enode://9e1096aa59862a6f164994cb5cb16f5124d6c992cdbf4535ff7dea43ea1512afe5448dca9df1b7ab0726129603f1a3336b631e4d7a1a44c94daddd03241587f9@35.178.210.161:30303")
"enode://9e1096aa59862a6f164994cb5cb16f5124d6c992cdbf4535ff7dea43ea1512afe5448dca9df1b7ab0726129603f1a3336b631e4d7a1a44c94daddd03241587f9@52.56.120.77:30303")
.map(EnodeURL::fromString)
.collect(toList()));

Loading…
Cancel
Save