Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/use gnark-crypto for eip-196 precompiles #7262

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
- `--Xsnapsync-bft-enabled` option enables experimental support for snap sync with IBFT/QBFT permissioned Bonsai-DB chains [#7140](https://github.com/hyperledger/besu/pull/7140)
- Add support to load external profiles using `--profile` [#7265](https://github.com/hyperledger/besu/issues/7265)
- `privacy-nonce-always-increments` option enables private transactions to always increment the nonce, even if the transaction is invalid [#6593](https://github.com/hyperledger/besu/pull/6593)
- Add `block-test` subcommand to the evmtool which runs blockchain reference tests [#7310](https://github.com/hyperledger/besu/pull/7310)
- Added `block-test` subcommand to the evmtool which runs blockchain reference tests [#7293](https://github.com/hyperledger/besu/pull/7293)
- removed PKI backed QBFT [#7310](https://github.com/hyperledger/besu/pull/7310)
- Implement gnark-crypto for eip-2537 [#7316](https://github.com/hyperledger/besu/pull/7316)
- Improve blob size transaction selector [#7312](https://github.com/hyperledger/besu/pull/7312)
- Added EIP-7702 [#7237](https://github.com/hyperledger/besu/pull/7237)
- implement gnark-crypto for eip-196 [#7262](https://github.com/hyperledger/besu/pull/7262)

### Bug fixes
- Fix `eth_call` deserialization to correctly ignore unknown fields in the transaction object. [#7323](https://github.com/hyperledger/besu/pull/7323)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.nativelib.bls12_381.LibEthPairings;
import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP196;

import java.util.Optional;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -49,7 +49,7 @@ public abstract class AbstractAltBnPrecompiledContract extends AbstractPrecompil
*/
public static boolean maybeEnableNative() {
try {
useNative = LibEthPairings.ENABLED;
useNative = LibGnarkEIP196.ENABLED;
} catch (UnsatisfiedLinkError | NoClassDefFoundError ule) {
LOG.info("altbn128 native precompile not available: {}", ule.getMessage());
useNative = false;
Expand All @@ -72,7 +72,7 @@ public static boolean isNative() {
}

private final byte operationId;
private final int inputLen;
private final int inputLimit;

/**
* Instantiates a new Abstract alt bn precompiled contract.
Expand All @@ -89,9 +89,9 @@ public static boolean isNative() {
final int inputLen) {
super(name, gasCalculator);
this.operationId = operationId;
this.inputLen = inputLen + 1;
this.inputLimit = inputLen + 1;

if (!LibEthPairings.ENABLED) {
if (!LibGnarkEIP196.ENABLED) {
LOG.info("Native alt bn128 not available");
}
}
Expand All @@ -106,23 +106,24 @@ public static boolean isNative() {
@Nonnull
public PrecompileContractResult computeNative(
final @Nonnull Bytes input, final MessageFrame messageFrame) {
final byte[] result = new byte[LibEthPairings.EIP196_PREALLOCATE_FOR_RESULT_BYTES];
final byte[] error = new byte[LibEthPairings.EIP2537_PREALLOCATE_FOR_ERROR_BYTES];
final byte[] result = new byte[LibGnarkEIP196.EIP196_PREALLOCATE_FOR_RESULT_BYTES];
final byte[] error = new byte[LibGnarkEIP196.EIP196_PREALLOCATE_FOR_ERROR_BYTES];

final IntByReference o_len =
new IntByReference(LibEthPairings.EIP196_PREALLOCATE_FOR_RESULT_BYTES);
new IntByReference(LibGnarkEIP196.EIP196_PREALLOCATE_FOR_RESULT_BYTES);
final IntByReference err_len =
new IntByReference(LibEthPairings.EIP2537_PREALLOCATE_FOR_ERROR_BYTES);
final int inputSize = Math.min(inputLen, input.size());
new IntByReference(LibGnarkEIP196.EIP196_PREALLOCATE_FOR_ERROR_BYTES);
final int inputSize = Math.min(inputLimit, input.size());
final int errorNo =
LibEthPairings.eip196_perform_operation(
LibGnarkEIP196.eip196_perform_operation(
operationId,
input.slice(0, inputSize).toArrayUnsafe(),
inputSize,
result,
o_len,
error,
err_len);

if (errorNo == 0) {
return PrecompileContractResult.success(Bytes.wrap(result, 0, o_len.getValue()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.nativelib.bls12_381.LibEthPairings;
import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP196;

import java.math.BigInteger;
import java.util.Arrays;
Expand All @@ -40,7 +40,7 @@ private AltBN128AddPrecompiledContract(final GasCalculator gasCalculator, final
super(
"AltBN128Add",
gasCalculator,
LibEthPairings.EIP196_ADD_OPERATION_RAW_VALUE,
LibGnarkEIP196.EIP196_ADD_OPERATION_RAW_VALUE,
PARAMETER_LENGTH);
this.gasCost = gasCost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.nativelib.bls12_381.LibEthPairings;
import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP196;

import java.math.BigInteger;
import java.util.Arrays;
Expand All @@ -44,7 +44,7 @@ private AltBN128MulPrecompiledContract(final GasCalculator gasCalculator, final
super(
"AltBN128Mul",
gasCalculator,
LibEthPairings.EIP196_MUL_OPERATION_RAW_VALUE,
LibGnarkEIP196.EIP196_MUL_OPERATION_RAW_VALUE,
PARAMETER_LENGTH);
this.gasCost = gasCost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.nativelib.bls12_381.LibEthPairings;
import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP196;

import java.math.BigInteger;
import java.util.ArrayList;
Expand Down Expand Up @@ -56,7 +56,7 @@ private AltBN128PairingPrecompiledContract(
super(
"AltBN128Pairing",
gasCalculator,
LibEthPairings.EIP196_PAIR_OPERATION_RAW_VALUE,
LibGnarkEIP196.EIP196_PAIR_OPERATION_RAW_VALUE,
Integer.MAX_VALUE / PARAMETER_LENGTH * PARAMETER_LENGTH);
this.pairingGasCost = pairingGasCost;
this.baseGasCost = baseGasCost;
Expand Down
70 changes: 35 additions & 35 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4632,12 +4632,12 @@
<sha256 value="6d535f94efb663bdb682c9f27a50335394688009642ba7a9677504bc1be4129b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="arithmetic" version="0.9.2">
<artifact name="arithmetic-0.9.2.jar">
<sha256 value="21b0385192903068ca38b0dadf5815717e8c7cef9ce94509461bd7c6121801e5" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="arithmetic" version="0.9.3">
<artifact name="arithmetic-0.9.3.jar">
<sha256 value="4f78999b188e1f6636f3dda95323ea3bf969bbe619011f4b0369d363946cb6a6" origin="Generated by Gradle"/>
</artifact>
<artifact name="arithmetic-0.9.2.module">
<sha256 value="fe8254c1640de98f3ff6f1193157bf69cc312a4e145ad9c93ba34d804ea49a1d" origin="Generated by Gradle"/>
<artifact name="arithmetic-0.9.3.module">
<sha256 value="f78d3739c0086808a11ea0a475e3aa85d69a90f1e1bc6190da766887b43de9cd" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="besu-errorprone-checks" version="1.0.0">
Expand All @@ -4648,52 +4648,52 @@
<sha256 value="c273525c9f23a0bd5b9cf6830b4bebd9d81e355b7f2ed3a22f23f76c2a2313d5" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="blake2bf" version="0.9.2">
<artifact name="blake2bf-0.9.2.jar">
<sha256 value="45449403f4b3b3a0f889b48bd5e28d096fc5a39fbcd9aea274e2c04595a20cc3" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="blake2bf" version="0.9.3">
<artifact name="blake2bf-0.9.3.jar">
<sha256 value="6f7b26ee6d8f6dbc79e76a1c013d4bf22e6fd43aa25b1f6387692f6a1a300b98" origin="Generated by Gradle"/>
</artifact>
<artifact name="blake2bf-0.9.2.module">
<sha256 value="9866d271c4cf13d5c1ead2c4fade33a3f46f39934a28581bd7d374d6dfc61666" origin="Generated by Gradle"/>
<artifact name="blake2bf-0.9.3.module">
<sha256 value="7db02d5304b1a1063f6ae8d8b8ac1bb93f2f9a56ee91e7a08f1775013ef89f6b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="bls12-381" version="0.9.2">
<artifact name="bls12-381-0.9.2.jar">
<sha256 value="65bca7983f9693f03501c3291be7837c21598f4ff381c08860a656bacf594774" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="bls12-381" version="0.9.3">
<artifact name="bls12-381-0.9.3.jar">
<sha256 value="ea4803c5bb8e224148ff2d2b702229e52d55760e565b79e1dc67427df552a24c" origin="Generated by Gradle"/>
</artifact>
<artifact name="bls12-381-0.9.2.module">
<sha256 value="a3dd33461d3235b63a2ae3bb015dd3c017695ca10a06adfdd2560a904df4226d" origin="Generated by Gradle"/>
<artifact name="bls12-381-0.9.3.module">
<sha256 value="3ffaf47860b7ec2d0a01a5d22dbc90e3a5101c5089b477b1e3695648351b8f6d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="gnark" version="0.9.2">
<artifact name="gnark-0.9.2.jar">
<sha256 value="37141ecfc7a196844ed85211d9bdc3da4c735b880b01f58191b55a7432596382" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="gnark" version="0.9.3">
<artifact name="gnark-0.9.3.jar">
<sha256 value="d98ac0e9f46a9db0aa59c6e3c31f7ad9888af9f287db9f331279e7426a6ccf34" origin="Generated by Gradle"/>
</artifact>
<artifact name="gnark-0.9.2.module">
<sha256 value="09220bdc8313d5b3f8499158fae39c24c9d2493256ab48925b2cc0ab673952f3" origin="Generated by Gradle"/>
<artifact name="gnark-0.9.3.module">
<sha256 value="88728b791402476c675929e18b89e925167ef7601c04abbc6661eae97b6b84a0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="ipa-multipoint" version="0.9.2">
<artifact name="ipa-multipoint-0.9.2.jar">
<sha256 value="de5d1b22acc4ee6c2148b04c7e560f79725653f5b442f07efcb542041a92f02e" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="ipa-multipoint" version="0.9.3">
<artifact name="ipa-multipoint-0.9.3.jar">
<sha256 value="4dc870c28de6b67a5fad6a9e3ae7e4e432107933dac9b267fcb21b3eb41f5e11" origin="Generated by Gradle"/>
</artifact>
<artifact name="ipa-multipoint-0.9.2.module">
<sha256 value="cb530713dfb4bbc4afddd2fb9be28a8974f19824b761a65fd464f1b448715c07" origin="Generated by Gradle"/>
<artifact name="ipa-multipoint-0.9.3.module">
<sha256 value="fd81db1e3c9d4399ad1eeea5e0963c6818df1c959f3c76ed9c4ef2c94e40b05a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="secp256k1" version="0.9.2">
<artifact name="secp256k1-0.9.2.jar">
<sha256 value="61d0eba0c323b6ea5f714bf5c4b168de7b4d6c55dda3b20ed7e58445bda41342" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="secp256k1" version="0.9.3">
<artifact name="secp256k1-0.9.3.jar">
<sha256 value="335717ee043ca2970268f8d150f082f71d75f81214125136dd2c0ce37e59a0a2" origin="Generated by Gradle"/>
</artifact>
<artifact name="secp256k1-0.9.2.module">
<sha256 value="88f7f17c696e0c7e011e72e1be13e08ea67620edfda8f66064374a9c1179339d" origin="Generated by Gradle"/>
<artifact name="secp256k1-0.9.3.module">
<sha256 value="76750b0030cfc9d3cb2fd942ae034ea4befaf59f37e1293f36354db685a64bd2" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.hyperledger.besu" name="secp256r1" version="0.9.2">
<artifact name="secp256r1-0.9.2.jar">
<sha256 value="18fc52c18014f14b40bc9298767f1b8b0fffe4340b7f85993d02594c0e85ed8d" origin="Generated by Gradle"/>
<component group="org.hyperledger.besu" name="secp256r1" version="0.9.3">
<artifact name="secp256r1-0.9.3.jar">
<sha256 value="8e899532b70e67dd2f314d28d291e32a0a4982ed5a4f4935168f4e86da4d3e79" origin="Generated by Gradle"/>
</artifact>
<artifact name="secp256r1-0.9.2.module">
<sha256 value="95137e1b3d61c298f15fb7b4c0e92d2c4c433e749306af10a7470855fe02c30d" origin="Generated by Gradle"/>
<artifact name="secp256r1-0.9.3.module">
<sha256 value="5f7367100ab289f9daf5ee050857db83b9ec6984aec19e3379181c2ff594cd81" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.immutables" name="immutables" version="2.10.0">
Expand Down
2 changes: 1 addition & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ dependencyManagement {
dependency 'org.openjdk.jol:jol-core:0.17'
dependency 'tech.pegasys:jc-kzg-4844:1.0.0'

dependencySet(group: 'org.hyperledger.besu', version: '0.9.2') {
dependencySet(group: 'org.hyperledger.besu', version: '0.9.3') {
entry 'arithmetic'
entry 'ipa-multipoint'
entry 'bls12-381'
Expand Down
Loading