mirror of
https://github.com/filecoin-project/lotus.git
synced 2026-03-13 08:32:30 +08:00
test(evm): add FEVM BLS12_381 precompile tests and contracts (#13343)
* itests: add FEVM BLS12-381 precompile tests and contracts Add Solidity test contracts and compiled artifacts for BLS12-381 operations: - G1AddTest, G1MsmTest - G2AddTest, G2MsmTest - MapFpToG1Test, MapFp2ToG2Test - PairingTest Include corresponding .hex artifacts and a compile script (itests/contracts/bls12/compile.sh). Update itests/fevm_test.go to run and validate these precompile tests. * Update itests/fevm_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Missing shebang line at the beginning of the script. Add #!/bin/bash as the first line to explicitly specify the shell interpreter. * run all bls12 tests helper contract --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
1
itests/contracts/bls12/AllBLS12Tests.hex
Normal file
1
itests/contracts/bls12/AllBLS12Tests.hex
Normal file
File diff suppressed because one or more lines are too long
41
itests/contracts/bls12/AllBLS12Tests.sol
Normal file
41
itests/contracts/bls12/AllBLS12Tests.sol
Normal file
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "./G1AddTest.sol";
|
||||
import "./G1MsmTest.sol";
|
||||
import "./G2AddTest.sol";
|
||||
import "./G2MsmTest.sol";
|
||||
import "./MapFpToG1Test.sol";
|
||||
import "./MapFp2ToG2Test.sol";
|
||||
import "./PairingTest.sol";
|
||||
|
||||
contract AllBLS12Tests {
|
||||
G1AddTest private g1Add;
|
||||
G1MsmTest private g1Msm;
|
||||
G2AddTest private g2Add;
|
||||
G2MsmTest private g2Msm;
|
||||
MapFpToG1Test private mapFpToG1;
|
||||
MapFp2ToG2Test private mapFp2ToG2;
|
||||
PairingTest private pairing;
|
||||
|
||||
constructor() {
|
||||
g1Add = new G1AddTest();
|
||||
g1Msm = new G1MsmTest();
|
||||
g2Add = new G2AddTest();
|
||||
g2Msm = new G2MsmTest();
|
||||
mapFpToG1 = new MapFpToG1Test();
|
||||
mapFp2ToG2 = new MapFp2ToG2Test();
|
||||
pairing = new PairingTest();
|
||||
}
|
||||
|
||||
function runTests() public view {
|
||||
g1Add.runTests();
|
||||
g1Msm.runTests();
|
||||
g2Add.runTests();
|
||||
g2Msm.runTests();
|
||||
mapFpToG1.runTests();
|
||||
mapFp2ToG2.runTests();
|
||||
pairing.runTests();
|
||||
}
|
||||
}
|
||||
|
||||
1
itests/contracts/bls12/G1AddTest.hex
Normal file
1
itests/contracts/bls12/G1AddTest.hex
Normal file
File diff suppressed because one or more lines are too long
69
itests/contracts/bls12/G1AddTest.sol
Normal file
69
itests/contracts/bls12/G1AddTest.sol
Normal file
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract G1AddTest {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x000000000000000000000000000000000000000b; // BLS12_G1ADD
|
||||
uint256 constant OUT_LEN = 128;
|
||||
|
||||
// Vector: g1 + p1
|
||||
bytes constant INPUT_ADD_G1_P1 = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21";
|
||||
bytes constant EXPECT_ADD_G1_P1 = hex"000000000000000000000000000000000a40300ce2dec9888b60690e9a41d3004fda4886854573974fab73b046d3147ba5b7a5bde85279ffede1b45b3918d82d0000000000000000000000000000000006d3d887e9f53b9ec4eb6cedf5607226754b07c01ace7834f57f3e7315faefb739e59018e22c492006190fba4a870025";
|
||||
// Vector: g1 + g1 = 2*g1
|
||||
bytes constant INPUT_G1_PLUS_G1 = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1";
|
||||
bytes constant EXPECT_G1_PLUS_G1 = hex"000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28";
|
||||
// Vector: p1 + p1 = 2*p1
|
||||
bytes constant INPUT_P1_PLUS_P1 = hex"00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21";
|
||||
bytes constant EXPECT_P1_PLUS_P1 = hex"0000000000000000000000000000000015222cddbabdd764c4bee0b3720322a65ff4712c86fc4b1588d0c209210a0884fa9468e855d261c483091b2bf7de6a630000000000000000000000000000000009f9edb99bc3b75d7489735c98b16ab78b9386c5f7a1f76c7e96ac6eb5bbde30dbca31a74ec6e0f0b12229eecea33c39";
|
||||
// Encoded canonical points (128 bytes each) for identity tests
|
||||
bytes constant G1_ENC = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1";
|
||||
bytes constant P1_ENC = hex"00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21";
|
||||
// Subtraction (add inverse) vectors -> infinity
|
||||
bytes constant INPUT_G1_MINUS_G1 = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000114d1d6855d545a8aa7d76c8cf2e21f267816aef1db507c96655b9d5caac42364e6f38ba0ecb751bad54dcd6b939c2ca";
|
||||
bytes constant INPUT_P1_MINUS_P1 = hex"00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca9426000000000000000000000000000000000195e911162921ba5ed055b496420f197693d36569ec34c63d7c0529a097d49e543070afba4b707e878e53c2b779208a";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive: addition
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT_ADD_G1_P1, OUT_LEN);
|
||||
expectEq(out1, EXPECT_ADD_G1_P1, "g1add add mismatch");
|
||||
|
||||
// Additional positives
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT_G1_PLUS_G1, OUT_LEN);
|
||||
expectEq(out2, EXPECT_G1_PLUS_G1, "g1add doubling g1 mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT_P1_PLUS_P1, OUT_LEN);
|
||||
expectEq(out3, EXPECT_P1_PLUS_P1, "g1add doubling p1 mismatch");
|
||||
|
||||
// Identity: g1 + 0 = g1; p1 + 0 = p1
|
||||
bytes memory out4 = callOk(PRECOMPILE, bytes.concat(G1_ENC, new bytes(OUT_LEN)), OUT_LEN);
|
||||
expectEq(out4, G1_ENC, "g1add identity g1+0 mismatch");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, bytes.concat(P1_ENC, new bytes(OUT_LEN)), OUT_LEN);
|
||||
expectEq(out5, P1_ENC, "g1add identity p1+0 mismatch");
|
||||
|
||||
// Subtraction to infinity
|
||||
bytes memory out6 = callOk(PRECOMPILE, INPUT_G1_MINUS_G1, OUT_LEN);
|
||||
expectEq(out6, new bytes(OUT_LEN), "g1add g1-g1 != 0");
|
||||
|
||||
bytes memory out7 = callOk(PRECOMPILE, INPUT_P1_MINUS_P1, OUT_LEN);
|
||||
expectEq(out7, new bytes(OUT_LEN), "g1add p1-p1 != 0");
|
||||
|
||||
// Negative: incorrect input size should revert
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/G1MsmTest.hex
Normal file
1
itests/contracts/bls12/G1MsmTest.hex
Normal file
File diff suppressed because one or more lines are too long
72
itests/contracts/bls12/G1MsmTest.sol
Normal file
72
itests/contracts/bls12/G1MsmTest.sol
Normal file
@@ -0,0 +1,72 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract G1MsmTest {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x000000000000000000000000000000000000000C; // BLS12_G1MSM
|
||||
uint256 constant OUT_LEN = 128;
|
||||
|
||||
// Vector: (g1, 2) -> 2*g1
|
||||
bytes constant INPUT_G1_2X = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000002";
|
||||
bytes constant EXPECT_G1_2X = hex"000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28";
|
||||
// Vector: 1*g1 = g1
|
||||
bytes constant INPUT_G1_1X = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000001";
|
||||
bytes constant EXPECT_G1_1X = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1";
|
||||
// Vector: 0*g1 = inf
|
||||
bytes constant INPUT_G1_0X = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000000";
|
||||
bytes constant EXPECT_INF_G1 = hex"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
// Vector: x*inf = inf (any non-zero scalar)
|
||||
bytes constant INPUT_X_INF = hex"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
|
||||
// Vector: random p1 with unnormalized scalar
|
||||
bytes constant INPUT_P1_UNNORM = hex"00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a219a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4";
|
||||
bytes constant EXPECT_P1_UNNORM = hex"0000000000000000000000000000000006ee9c9331228753bcb148d0ca8623447701bb0aa6eafb0340aa7f81543923474e00f2a225de65c62dd1d8303270220c0000000000000000000000000000000018dd7be47eb4e80985d7a0d2cc96c8b004250b36a5c3ec0217705d453d3ecc6d0d3d1588722da51b40728baba1e93804";
|
||||
// Multi-pair MSM (from Rust tests) -> expected point
|
||||
bytes constant INPUT_MULTI = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e300000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2147b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff66513800000000000000000000000000000000184bb665c37ff561a89ec2122dd343f20e0f4cbcaec84e3c3052ea81d1834e192c426074b02ed3dca4e7676ce4ce48ba0000000000000000000000000000000004407b8d35af4dacc809927071fc0405218f1401a6d15af775810e4e460064bcc9468beeba82fdc751be70476c888bf3328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d21600000000000000000000000000000000009769f3ab59bfd551d53a5f846b9984c59b97d6842b20a2c565baa167945e3d026a3755b6345df8ec7e6acb6868ae6d000000000000000000000000000000001532c00cf61aa3d0ce3e5aa20c3b531a2abd2c770a790a2613818303c6b830ffc0ecf6c357af3317b9575c567f11cd2c263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e2000000000000000000000000000000001974dbb8e6b5d20b84df7e625e2fbfecb2cdb5f77d5eae5fb2955e5ce7313cae8364bc2fff520a6c25619739c6bdcb6a0000000000000000000000000000000015f9897e11c6441eaa676de141c8d83c37aab8667173cbe1dfd6de74d11861b961dccebcd9d289ac633455dfcc7013a347b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff665131000000000000000000000000000000000a7a047c4a8397b3446450642c2ac64d7239b61872c9ae7a59707a8f4f950f101e766afe58223b3bff3a19a7f754027c000000000000000000000000000000001383aebba1e4327ccff7cf9912bda0dbc77de048b71ef8c8a81111d71dc33c5e3aa6edee9cf6f5fe525d50cc50b77cc9328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d211000000000000000000000000000000000e7a16a975904f131682edbb03d9560d3e48214c9986bd50417a77108d13dc957500edf96462a3d01e62dc6cd468ef11000000000000000000000000000000000ae89e677711d05c30a48d6d75e76ca9fb70fe06c6dd6ff988683d89ccde29ac7d46c53bb97a59b1901abf1db66052db55b53c4669f19f0fc7431929bc0363d7d8fb432435fcde2635fdba334424e9f5";
|
||||
bytes constant EXPECT_MULTI = hex"00000000000000000000000000000000053fbdb09b6b5faa08bfe7b7069454247ad4d8bd57e90e2d2ebaa04003dcf110aa83072c07f480ab2107cca2ccff6091000000000000000000000000000000001654537b7c96fe64d13906066679c3d45808cb666452b55d1b909c230cc4b423c3f932c58754b9b762dc49fcc825522c";
|
||||
// 2g1 + inf -> 2*g1
|
||||
bytes constant INPUT_2G1_PLUS_INF = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002";
|
||||
bytes constant EXPECT_2G1_PLUS_INF = hex"000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive: MSM with single pair equals scalar mul
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT_G1_2X, OUT_LEN);
|
||||
expectEq(out1, EXPECT_G1_2X, "g1msm 2x mismatch");
|
||||
|
||||
// Additional positives
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT_G1_1X, OUT_LEN);
|
||||
expectEq(out2, EXPECT_G1_1X, "g1msm 1x mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT_G1_0X, OUT_LEN);
|
||||
expectEq(out3, EXPECT_INF_G1, "g1msm 0x != inf");
|
||||
|
||||
bytes memory out4 = callOk(PRECOMPILE, INPUT_X_INF, OUT_LEN);
|
||||
expectEq(out4, EXPECT_INF_G1, "g1msm x*inf != inf");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, INPUT_P1_UNNORM, OUT_LEN);
|
||||
expectEq(out5, EXPECT_P1_UNNORM, "g1msm unnormalized scalar mismatch");
|
||||
|
||||
bytes memory out6 = callOk(PRECOMPILE, INPUT_MULTI, OUT_LEN);
|
||||
expectEq(out6, EXPECT_MULTI, "g1msm multiple mismatch");
|
||||
|
||||
bytes memory out7 = callOk(PRECOMPILE, INPUT_2G1_PLUS_INF, OUT_LEN);
|
||||
expectEq(out7, EXPECT_2G1_PLUS_INF, "g1msm 2g1+inf mismatch");
|
||||
|
||||
// Negative: empty input should revert
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/G2AddTest.hex
Normal file
1
itests/contracts/bls12/G2AddTest.hex
Normal file
File diff suppressed because one or more lines are too long
69
itests/contracts/bls12/G2AddTest.sol
Normal file
69
itests/contracts/bls12/G2AddTest.sol
Normal file
@@ -0,0 +1,69 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract G2AddTest {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x000000000000000000000000000000000000000d; // BLS12_G2ADD
|
||||
uint256 constant OUT_LEN = 256;
|
||||
|
||||
// Vector: g2 + p2
|
||||
bytes constant INPUT_ADD_G2_P2 = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451";
|
||||
bytes constant EXPECT_ADD_G2_P2 = hex"000000000000000000000000000000000b54a8a7b08bd6827ed9a797de216b8c9057b3a9ca93e2f88e7f04f19accc42da90d883632b9ca4dc38d013f71ede4db00000000000000000000000000000000077eba4eecf0bd764dce8ed5f45040dd8f3b3427cb35230509482c14651713282946306247866dfe39a8e33016fcbe520000000000000000000000000000000014e60a76a29ef85cbd69f251b9f29147b67cfe3ed2823d3f9776b3a0efd2731941d47436dc6d2b58d9e65f8438bad073000000000000000000000000000000001586c3c910d95754fef7a732df78e279c3d37431c6a2b77e67a00c7c130a8fcd4d19f159cbeb997a178108fffffcbd20";
|
||||
// Vector: g2 + g2 = 2*g2
|
||||
bytes constant INPUT_G2_PLUS_G2 = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
bytes constant EXPECT_G2_PLUS_G2 = hex"000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3";
|
||||
// Vector: p2 + p2 = 2*p2
|
||||
bytes constant INPUT_P2_PLUS_P2 = hex"00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451";
|
||||
bytes constant EXPECT_P2_PLUS_P2 = hex"000000000000000000000000000000000b76fcbb604082a4f2d19858a7befd6053fa181c5119a612dfec83832537f644e02454f2b70d40985ebb08042d1620d40000000000000000000000000000000019a4a02c0ae51365d964c73be7babb719db1c69e0ddbf9a8a335b5bed3b0a4b070d2d5df01d2da4a3f1e56aae2ec106d000000000000000000000000000000000d18322f821ac72d3ca92f92b000483cf5b7d9e5d06873a44071c4e7e81efd904f210208fe0b9b4824f01c65bc7e62080000000000000000000000000000000004e563d53609a2d1e216aaaee5fbc14ef460160db8d1fdc5e1bd4e8b54cd2f39abf6f925969fa405efb9e700b01c7085";
|
||||
// Encoded canonical points (256 bytes each) for identity tests
|
||||
bytes constant G2_ENC = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
bytes constant P2_ENC = hex"00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451";
|
||||
// Subtraction (add inverse) vectors -> infinity
|
||||
bytes constant INPUT_G2_MINUS_G2 = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed";
|
||||
bytes constant INPUT_P2_MINUS_P2 = hex"00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000a6296409115572426717c73668335a949829d739cff2cb4ab043710d28f8e772f6ef41aac4806c9cb273c490384032d000000000000000000000000000000000cde4e850c721fa94e8890d500e3655b442d5c0dc4fff1b694c6f8dd68f6d8dc1bc3251a37d27e7af96f65a96278265a";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive: addition
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT_ADD_G2_P2, OUT_LEN);
|
||||
expectEq(out1, EXPECT_ADD_G2_P2, "g2add add mismatch");
|
||||
|
||||
// Additional positives
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT_G2_PLUS_G2, OUT_LEN);
|
||||
expectEq(out2, EXPECT_G2_PLUS_G2, "g2add doubling g2 mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT_P2_PLUS_P2, OUT_LEN);
|
||||
expectEq(out3, EXPECT_P2_PLUS_P2, "g2add doubling p2 mismatch");
|
||||
|
||||
// Identity: g2 + 0 = g2; p2 + 0 = p2
|
||||
bytes memory out4 = callOk(PRECOMPILE, bytes.concat(G2_ENC, new bytes(OUT_LEN)), OUT_LEN);
|
||||
expectEq(out4, G2_ENC, "g2add identity g2+0 mismatch");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, bytes.concat(P2_ENC, new bytes(OUT_LEN)), OUT_LEN);
|
||||
expectEq(out5, P2_ENC, "g2add identity p2+0 mismatch");
|
||||
|
||||
// Subtraction to infinity
|
||||
bytes memory out6 = callOk(PRECOMPILE, INPUT_G2_MINUS_G2, OUT_LEN);
|
||||
expectEq(out6, new bytes(OUT_LEN), "g2add g2-g2 != 0");
|
||||
|
||||
bytes memory out7 = callOk(PRECOMPILE, INPUT_P2_MINUS_P2, OUT_LEN);
|
||||
expectEq(out7, new bytes(OUT_LEN), "g2add p2-p2 != 0");
|
||||
|
||||
// Negative: incorrect input size should revert
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/G2MsmTest.hex
Normal file
1
itests/contracts/bls12/G2MsmTest.hex
Normal file
File diff suppressed because one or more lines are too long
60
itests/contracts/bls12/G2MsmTest.sol
Normal file
60
itests/contracts/bls12/G2MsmTest.sol
Normal file
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract G2MsmTest {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x000000000000000000000000000000000000000E; // BLS12_G2MSM
|
||||
uint256 constant OUT_LEN = 256;
|
||||
|
||||
// Vector: (g2, 2) -> 2*g2
|
||||
bytes constant INPUT_G2_2X = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000002";
|
||||
bytes constant EXPECT_G2_2X = hex"000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3";
|
||||
// Vector: 1*g2 = g2
|
||||
bytes constant INPUT_G2_1X = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000001";
|
||||
bytes constant EXPECT_G2_1X = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
// Vector: 0*g2 = inf
|
||||
bytes constant INPUT_G2_0X = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000000";
|
||||
bytes constant EXPECT_INF_G2 = hex"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
// Vector: x*inf = inf
|
||||
bytes constant INPUT_X_INF = hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
|
||||
// 2g2 + inf -> 2*g2
|
||||
bytes constant INPUT_2G2_PLUS_INF = hex"00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002";
|
||||
bytes constant EXPECT_2G2_PLUS_INF = hex"000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive: MSM with single pair equals scalar mul
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT_G2_2X, OUT_LEN);
|
||||
expectEq(out1, EXPECT_G2_2X, "g2msm 2x mismatch");
|
||||
|
||||
// Additional positives
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT_G2_1X, OUT_LEN);
|
||||
expectEq(out2, EXPECT_G2_1X, "g2msm 1x mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT_G2_0X, OUT_LEN);
|
||||
expectEq(out3, EXPECT_INF_G2, "g2msm 0x != inf");
|
||||
|
||||
bytes memory out4 = callOk(PRECOMPILE, INPUT_X_INF, OUT_LEN);
|
||||
expectEq(out4, EXPECT_INF_G2, "g2msm x*inf != inf");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, INPUT_2G2_PLUS_INF, OUT_LEN);
|
||||
expectEq(out5, EXPECT_2G2_PLUS_INF, "g2msm 2g2+inf mismatch");
|
||||
|
||||
// Negative: empty input should revert
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/MapFp2ToG2Test.hex
Normal file
1
itests/contracts/bls12/MapFp2ToG2Test.hex
Normal file
File diff suppressed because one or more lines are too long
56
itests/contracts/bls12/MapFp2ToG2Test.sol
Normal file
56
itests/contracts/bls12/MapFp2ToG2Test.sol
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract MapFp2ToG2Test {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x0000000000000000000000000000000000000011; // MAP_FP2_TO_G2
|
||||
uint256 constant OUT_LEN = 256;
|
||||
|
||||
// Vector 1 from Rust tests
|
||||
bytes constant INPUT1 = hex"0000000000000000000000000000000007355d25caf6e7f2f0cb2812ca0e513bd026ed09dda65b177500fa31714e09ea0ded3a078b526bed3307f804d4b93b040000000000000000000000000000000002829ce3c021339ccb5caf3e187f6370e1e2a311dec9b75363117063ab2015603ff52c3d3b98f19c2f65575e99e8b78c";
|
||||
bytes constant EXPECT1 = hex"0000000000000000000000000000000000e7f4568a82b4b7dc1f14c6aaa055edf51502319c723c4dc2688c7fe5944c213f510328082396515734b6612c4e7bb700000000000000000000000000000000126b855e9e69b1f691f816e48ac6977664d24d99f8724868a184186469ddfd4617367e94527d4b74fc86413483afb35b000000000000000000000000000000000caead0fd7b6176c01436833c79d305c78be307da5f6af6c133c47311def6ff1e0babf57a0fb5539fce7ee12407b0a42000000000000000000000000000000001498aadcf7ae2b345243e281ae076df6de84455d766ab6fcdaad71fab60abb2e8b980a440043cd305db09d283c895e3d";
|
||||
bytes constant INPUT2 = hex"00000000000000000000000000000000138879a9559e24cecee8697b8b4ad32cced053138ab913b99872772dc753a2967ed50aabc907937aefb2439ba06cc50c000000000000000000000000000000000a1ae7999ea9bab1dcc9ef8887a6cb6e8f1e22566015428d220b7eec90ffa70ad1f624018a9ad11e78d588bd3617f9f2";
|
||||
bytes constant EXPECT2 = hex"00000000000000000000000000000000108ed59fd9fae381abfd1d6bce2fd2fa220990f0f837fa30e0f27914ed6e1454db0d1ee957b219f61da6ff8be0d6441f000000000000000000000000000000000296238ea82c6d4adb3c838ee3cb2346049c90b96d602d7bb1b469b905c9228be25c627bffee872def773d5b2a2eb57d00000000000000000000000000000000033f90f6057aadacae7963b0a0b379dd46750c1c94a6357c99b65f63b79e321ff50fe3053330911c56b6ceea08fee65600000000000000000000000000000000153606c417e59fb331b7ae6bce4fbf7c5190c33ce9402b5ebe2b70e44fca614f3f1382a3625ed5493843d0b0a652fc3f";
|
||||
bytes constant INPUT3 = hex"0000000000000000000000000000000018c16fe362b7dbdfa102e42bdfd3e2f4e6191d479437a59db4eb716986bf08ee1f42634db66bde97d6c16bbfd342b3b8000000000000000000000000000000000e37812ce1b146d998d5f92bdd5ada2a31bfd63dfe18311aa91637b5f279dd045763166aa1615e46a50d8d8f475f184e";
|
||||
bytes constant EXPECT3 = hex"00000000000000000000000000000000038af300ef34c7759a6caaa4e69363cafeed218a1f207e93b2c70d91a1263d375d6730bd6b6509dcac3ba5b567e85bf3000000000000000000000000000000000da75be60fb6aa0e9e3143e40c42796edf15685cafe0279afd2a67c3dff1c82341f17effd402e4f1af240ea90f4b659b0000000000000000000000000000000019b148cbdf163cf0894f29660d2e7bfb2b68e37d54cc83fd4e6e62c020eaa48709302ef8e746736c0e19342cc1ce3df4000000000000000000000000000000000492f4fed741b073e5a82580f7c663f9b79e036b70ab3e51162359cec4e77c78086fe879b65ca7a47d34374c8315ac5e";
|
||||
bytes constant INPUT4 = hex"0000000000000000000000000000000008d4a0997b9d52fecf99427abb721f0fa779479963315fe21c6445250de7183e3f63bfdf86570da8929489e421d4ee950000000000000000000000000000000016cb4ccad91ec95aab070f22043916cd6a59c4ca94097f7f510043d48515526dc8eaaea27e586f09151ae613688d5a89";
|
||||
bytes constant EXPECT4 = hex"000000000000000000000000000000000c5ae723be00e6c3f0efe184fdc0702b64588fe77dda152ab13099a3bacd3876767fa7bbad6d6fd90b3642e902b208f90000000000000000000000000000000012c8c05c1d5fc7bfa847f4d7d81e294e66b9a78bc9953990c358945e1f042eedafce608b67fdd3ab0cb2e6e263b9b1ad0000000000000000000000000000000004e77ddb3ede41b5ec4396b7421dd916efc68a358a0d7425bddd253547f2fb4830522358491827265dfc5bcc1928a5690000000000000000000000000000000011c624c56dbe154d759d021eec60fab3d8b852395a89de497e48504366feedd4662d023af447d66926a28076813dd646";
|
||||
bytes constant INPUT5 = hex"0000000000000000000000000000000003f80ce4ff0ca2f576d797a3660e3f65b274285c054feccc3215c879e2c0589d376e83ede13f93c32f05da0f68fd6a1000000000000000000000000000000000006488a837c5413746d868d1efb7232724da10eca410b07d8b505b9363bdccf0a1fc0029bad07d65b15ccfe6dd25e20d";
|
||||
bytes constant EXPECT5 = hex"000000000000000000000000000000000ea4e7c33d43e17cc516a72f76437c4bf81d8f4eac69ac355d3bf9b71b8138d55dc10fd458be115afa798b55dac34be1000000000000000000000000000000001565c2f625032d232f13121d3cfb476f45275c303a037faa255f9da62000c2c864ea881e2bcddd111edc4a3c0da3e88d00000000000000000000000000000000043b6f5fe4e52c839148dc66f2b3751e69a0f6ebb3d056d6465d50d4108543ecd956e10fa1640dfd9bc0030cc2558d28000000000000000000000000000000000f8991d2a1ad662e7b6f58ab787947f1fa607fce12dde171bc17903b012091b657e15333e11701edcf5b63ba2a561247";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT1, OUT_LEN);
|
||||
expectEq(out1, EXPECT1, "map_fp2_to_g2 mismatch");
|
||||
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT2, OUT_LEN);
|
||||
expectEq(out2, EXPECT2, "map_fp2_to_g2 #2 mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT3, OUT_LEN);
|
||||
expectEq(out3, EXPECT3, "map_fp2_to_g2 #3 mismatch");
|
||||
|
||||
bytes memory out4 = callOk(PRECOMPILE, INPUT4, OUT_LEN);
|
||||
expectEq(out4, EXPECT4, "map_fp2_to_g2 #4 mismatch");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, INPUT5, OUT_LEN);
|
||||
expectEq(out5, EXPECT5, "map_fp2_to_g2 #5 mismatch");
|
||||
|
||||
// Negative: wrong length
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/MapFpToG1Test.hex
Normal file
1
itests/contracts/bls12/MapFpToG1Test.hex
Normal file
File diff suppressed because one or more lines are too long
56
itests/contracts/bls12/MapFpToG1Test.sol
Normal file
56
itests/contracts/bls12/MapFpToG1Test.sol
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract MapFpToG1Test {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x0000000000000000000000000000000000000010; // MAP_FP_TO_G1
|
||||
uint256 constant OUT_LEN = 128;
|
||||
|
||||
// Vector 1 from Rust tests
|
||||
bytes constant INPUT1 = hex"00000000000000000000000000000000156c8a6a2c184569d69a76be144b5cdc5141d2d2ca4fe341f011e25e3969c55ad9e9b9ce2eb833c81a908e5fa4ac5f03";
|
||||
bytes constant EXPECT1 = hex"00000000000000000000000000000000184bb665c37ff561a89ec2122dd343f20e0f4cbcaec84e3c3052ea81d1834e192c426074b02ed3dca4e7676ce4ce48ba0000000000000000000000000000000004407b8d35af4dacc809927071fc0405218f1401a6d15af775810e4e460064bcc9468beeba82fdc751be70476c888bf3";
|
||||
bytes constant INPUT2 = hex"00000000000000000000000000000000147e1ed29f06e4c5079b9d14fc89d2820d32419b990c1c7bb7dbea2a36a045124b31ffbde7c99329c05c559af1c6cc82";
|
||||
bytes constant EXPECT2 = hex"00000000000000000000000000000000009769f3ab59bfd551d53a5f846b9984c59b97d6842b20a2c565baa167945e3d026a3755b6345df8ec7e6acb6868ae6d000000000000000000000000000000001532c00cf61aa3d0ce3e5aa20c3b531a2abd2c770a790a2613818303c6b830ffc0ecf6c357af3317b9575c567f11cd2c";
|
||||
bytes constant INPUT3 = hex"0000000000000000000000000000000004090815ad598a06897dd89bcda860f25837d54e897298ce31e6947378134d3761dc59a572154963e8c954919ecfa82d";
|
||||
bytes constant EXPECT3 = hex"000000000000000000000000000000001974dbb8e6b5d20b84df7e625e2fbfecb2cdb5f77d5eae5fb2955e5ce7313cae8364bc2fff520a6c25619739c6bdcb6a0000000000000000000000000000000015f9897e11c6441eaa676de141c8d83c37aab8667173cbe1dfd6de74d11861b961dccebcd9d289ac633455dfcc7013a3";
|
||||
bytes constant INPUT4 = hex"0000000000000000000000000000000008dccd088ca55b8bfbc96fb50bb25c592faa867a8bb78d4e94a8cc2c92306190244532e91feba2b7fed977e3c3bb5a1f";
|
||||
bytes constant EXPECT4 = hex"000000000000000000000000000000000a7a047c4a8397b3446450642c2ac64d7239b61872c9ae7a59707a8f4f950f101e766afe58223b3bff3a19a7f754027c000000000000000000000000000000001383aebba1e4327ccff7cf9912bda0dbc77de048b71ef8c8a81111d71dc33c5e3aa6edee9cf6f5fe525d50cc50b77cc9";
|
||||
bytes constant INPUT5 = hex"000000000000000000000000000000000dd824886d2123a96447f6c56e3a3fa992fbfefdba17b6673f9f630ff19e4d326529db37e1c1be43f905bf9202e0278d";
|
||||
bytes constant EXPECT5 = hex"000000000000000000000000000000000e7a16a975904f131682edbb03d9560d3e48214c9986bd50417a77108d13dc957500edf96462a3d01e62dc6cd468ef11000000000000000000000000000000000ae89e677711d05c30a48d6d75e76ca9fb70fe06c6dd6ff988683d89ccde29ac7d46c53bb97a59b1901abf1db66052db";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT1, OUT_LEN);
|
||||
expectEq(out1, EXPECT1, "map_fp_to_g1 mismatch");
|
||||
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT2, OUT_LEN);
|
||||
expectEq(out2, EXPECT2, "map_fp_to_g1 #2 mismatch");
|
||||
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT3, OUT_LEN);
|
||||
expectEq(out3, EXPECT3, "map_fp_to_g1 #3 mismatch");
|
||||
|
||||
bytes memory out4 = callOk(PRECOMPILE, INPUT4, OUT_LEN);
|
||||
expectEq(out4, EXPECT4, "map_fp_to_g1 #4 mismatch");
|
||||
|
||||
bytes memory out5 = callOk(PRECOMPILE, INPUT5, OUT_LEN);
|
||||
expectEq(out5, EXPECT5, "map_fp_to_g1 #5 mismatch");
|
||||
|
||||
// Negative: wrong length
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
1
itests/contracts/bls12/PairingTest.hex
Normal file
1
itests/contracts/bls12/PairingTest.hex
Normal file
File diff suppressed because one or more lines are too long
53
itests/contracts/bls12/PairingTest.sol
Normal file
53
itests/contracts/bls12/PairingTest.sol
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
contract PairingTest {
|
||||
function callOk(address pc, bytes memory input, uint256 expectedLen) internal view returns (bytes memory) {
|
||||
(bool ok, bytes memory out) = pc.staticcall(input);
|
||||
require(ok, "precompile reverted");
|
||||
require(out.length == expectedLen, "unexpected return length");
|
||||
return out;
|
||||
}
|
||||
|
||||
function expectRevert(address pc, bytes memory input) internal view {
|
||||
(bool ok, ) = pc.staticcall(input);
|
||||
require(!ok, "expected revert");
|
||||
}
|
||||
|
||||
function expectEq(bytes memory a, bytes memory b, string memory what) internal pure {
|
||||
require(keccak256(a) == keccak256(b), what);
|
||||
}
|
||||
|
||||
address constant PRECOMPILE = 0x000000000000000000000000000000000000000F; // BLS12_PAIRING_CHECK
|
||||
uint256 constant OUT_LEN = 32;
|
||||
|
||||
// Vector: e(0, G2) -> 1 (last byte = 0x01)
|
||||
bytes constant INPUT_E_0_G2 = hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
bytes constant EXPECT_TRUE = hex"0000000000000000000000000000000000000000000000000000000000000001";
|
||||
bytes constant EXPECT_FALSE = hex"0000000000000000000000000000000000000000000000000000000000000000";
|
||||
// Vector: e(G1, 0) -> 1
|
||||
bytes constant INPUT_E_G1_0 = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
// Vector: non-degeneracy -> expect 0
|
||||
bytes constant INPUT_NON_DEGENERATE = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
// Vector: e(G1,G2)*e(0,0)*e(G1,G2) -> 0
|
||||
bytes constant INPUT_PRODUCT_FALSE = hex"0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be";
|
||||
|
||||
function runTests() public view {
|
||||
// Positive: pairing should return true (1)
|
||||
bytes memory out1 = callOk(PRECOMPILE, INPUT_E_0_G2, OUT_LEN);
|
||||
expectEq(out1, EXPECT_TRUE, "pairing e(0,G2) != 1");
|
||||
|
||||
bytes memory out2 = callOk(PRECOMPILE, INPUT_E_G1_0, OUT_LEN);
|
||||
expectEq(out2, EXPECT_TRUE, "pairing e(G1,0) != 1");
|
||||
|
||||
// False (0) cases
|
||||
bytes memory out3 = callOk(PRECOMPILE, INPUT_NON_DEGENERATE, OUT_LEN);
|
||||
expectEq(out3, EXPECT_FALSE, "pairing non-degeneracy expected 0");
|
||||
|
||||
bytes memory out4 = callOk(PRECOMPILE, INPUT_PRODUCT_FALSE, OUT_LEN);
|
||||
expectEq(out4, EXPECT_FALSE, "pairing product false expected 0");
|
||||
|
||||
// Negative: empty input should revert (length must be multiple of 384 and non-zero)
|
||||
expectRevert(PRECOMPILE, hex"");
|
||||
}
|
||||
}
|
||||
10
itests/contracts/bls12/compile.sh
Executable file
10
itests/contracts/bls12/compile.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
#use the solc compiler https://docs.soliditylang.org/en/v0.8.17/installing-solidity.html
|
||||
# to compile all of the .sol files to their corresponding evm binary files stored as .hex
|
||||
# solc outputs to stdout a format that we just want to grab the last line of and then remove the trailing newline on that line
|
||||
|
||||
find . -maxdepth 1 -name \*.sol -print0 |
|
||||
xargs -0 -I{} bash -euc -o pipefail 'solc --bin {} |tail -n1 | tr -d "\n" > $(echo {} | sed -e s/.sol$/.hex/)'
|
||||
@@ -1853,3 +1853,28 @@ func TestTstore(t *testing.T) {
|
||||
_, _, err = client.EVM().InvokeContractByFuncName(ctx, fromAddr, contractAddr, "testNestedContracts(address)", inputDataContract)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestFEVMTestBLS(t *testing.T) {
|
||||
ctx, cancel, client := kit.SetupFEVMTest(t)
|
||||
defer cancel()
|
||||
|
||||
tests := []string{
|
||||
"G1AddTest",
|
||||
"G1MsmTest",
|
||||
"G2AddTest",
|
||||
"G2MsmTest",
|
||||
"MapFpToG1Test",
|
||||
"MapFp2ToG2Test",
|
||||
"PairingTest",
|
||||
}
|
||||
|
||||
for _, name := range tests {
|
||||
name := name
|
||||
t.Run(name, func(t *testing.T) {
|
||||
filename := fmt.Sprintf("contracts/bls12/%s.hex", name)
|
||||
fromAddr, contractAddr := client.EVM().DeployContractFromFilename(ctx, filename)
|
||||
_, _, err := client.EVM().InvokeContractByFuncName(ctx, fromAddr, contractAddr, "runTests()", []byte{})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user