Skip to content

Commit

Permalink
EIP-2537 activation and updates (hyperledger#7053)
Browse files Browse the repository at this point in the history
* Add EIP-2537 precompiles to prague
* Update gas schedule
* Update native lib to one with subgroup checks in mul and multiexp
* re-cost gas on most vectors

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored May 7, 2024
1 parent a4b835d commit 46475ce
Show file tree
Hide file tree
Showing 26 changed files with 690 additions and 641 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public BLS12G1AddPrecompiledContract() {

@Override
public long gasRequirement(final Bytes input) {
return 600L;
return 500L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public BLS12G2AddPrecompiledContract() {

@Override
public long gasRequirement(final Bytes input) {
return 4_500L;
return 800L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public BLS12G2MulPrecompiledContract() {

@Override
public long gasRequirement(final Bytes input) {
return 55_000L;
return 45_000L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public BLS12G2MultiExpPrecompiledContract() {
@Override
public long gasRequirement(final Bytes input) {
final int k = input.size() / PARAMETER_LENGTH;
return 55L * k * getDiscount(k);
return 45L * k * getDiscount(k);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public BLS12MapFp2ToG2PrecompiledContract() {

@Override
public long gasRequirement(final Bytes input) {
return 110_000L;
return 75_000L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public BLS12PairingPrecompiledContract() {
@Override
public long gasRequirement(final Bytes input) {
final int k = input.size() / PARAMETER_LENGTH;
return 23_000L * k + 115_000L;
return 43_000L * k + 65_000L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static void populateForCancun(
populateForIstanbul(registry, gasCalculator);

// EIP-4844 - shard blob transactions
// TODO: allow override to be configured?
registry.put(Address.KZG_POINT_EVAL, new KZGPointEvalPrecompiledContract());
}

Expand All @@ -162,7 +161,16 @@ static void populateForPrague(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForCancun(registry, gasCalculator);

// TODO: add Prague precompiles here
// EIP-2537 - BLS12-381 curve operations
registry.put(Address.BLS12_G1ADD, new BLS12G1AddPrecompiledContract());
registry.put(Address.BLS12_G1MUL, new BLS12G1MulPrecompiledContract());
registry.put(Address.BLS12_G1MULTIEXP, new BLS12G1MultiExpPrecompiledContract());
registry.put(Address.BLS12_G2ADD, new BLS12G2AddPrecompiledContract());
registry.put(Address.BLS12_G2MUL, new BLS12G2MulPrecompiledContract());
registry.put(Address.BLS12_G2MULTIEXP, new BLS12G2MultiExpPrecompiledContract());
registry.put(Address.BLS12_PAIRING, new BLS12PairingPrecompiledContract());
registry.put(Address.BLS12_MAP_FP_TO_G1, new BLS12MapFpToG1PrecompiledContract());
registry.put(Address.BLS12_MAP_FP2_TO_G2, new BLS12MapFp2ToG2PrecompiledContract());
}

/**
Expand All @@ -186,16 +194,5 @@ static PrecompileContractRegistry futureEIPs(final GasCalculator gasCalculator)
static void populateForFutureEIPs(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForCancun(registry, gasCalculator);

// EIP-2537 - BLS12-381 curve operations
registry.put(Address.BLS12_G1ADD, new BLS12G1AddPrecompiledContract());
registry.put(Address.BLS12_G1MUL, new BLS12G1MulPrecompiledContract());
registry.put(Address.BLS12_G1MULTIEXP, new BLS12G1MultiExpPrecompiledContract());
registry.put(Address.BLS12_G2ADD, new BLS12G2AddPrecompiledContract());
registry.put(Address.BLS12_G2MUL, new BLS12G2MulPrecompiledContract());
registry.put(Address.BLS12_G2MULTIEXP, new BLS12G2MultiExpPrecompiledContract());
registry.put(Address.BLS12_PAIRING, new BLS12PairingPrecompiledContract());
registry.put(Address.BLS12_MAP_FP_TO_G1, new BLS12MapFpToG1PrecompiledContract());
registry.put(Address.BLS12_MAP_FP2_TO_G2, new BLS12MapFp2ToG2PrecompiledContract());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
Mockito.verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void shouldCalculate(
if (actualComputation == null) {
final ArgumentCaptor<Bytes> revertReason = ArgumentCaptor.forClass(Bytes.class);
verify(messageFrame).setRevertReason(revertReason.capture());
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).isEqualTo(notes);
assertThat(new String(revertReason.getValue().toArrayUnsafe(), UTF_8)).contains(notes);

assertThat(expectedComputation.size()).isZero();
} else {
Expand Down
Loading

0 comments on commit 46475ce

Please sign in to comment.