Skip to content

Commit

Permalink
precompiles: Remove redundant BLS MUL precompiles
Browse files Browse the repository at this point in the history
Remove redundant G1/G2 MUL precompiles easily replaceable with MSMs.
Spec update: ethereum/EIPs#8945.
  • Loading branch information
chfast committed Dec 20, 2024
1 parent 4c6470b commit 6e214c6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 44 deletions.
30 changes: 0 additions & 30 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,6 @@ ExecutionResult bls12_g1add_execute(const uint8_t* input, size_t input_size, uin
return {EVMC_SUCCESS, 128};
}

ExecutionResult bls12_g1mul_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
if (input_size != 160)
return {EVMC_PRECOMPILE_FAILURE, 0};

assert(output_size == 128);

if (!crypto::bls::g1_mul(output, &output[64], input, &input[64], &input[128]))
return {EVMC_PRECOMPILE_FAILURE, 0};

return {EVMC_SUCCESS, 128};
}

ExecutionResult bls12_g1msm_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
Expand Down Expand Up @@ -485,20 +471,6 @@ ExecutionResult bls12_g2add_execute(const uint8_t* input, size_t input_size, uin
return {EVMC_SUCCESS, 256};
}

ExecutionResult bls12_g2mul_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
if (input_size != 288)
return {EVMC_PRECOMPILE_FAILURE, 0};

assert(output_size == 256);

if (!crypto::bls::g2_mul(output, &output[128], input, &input[128], &input[256]))
return {EVMC_PRECOMPILE_FAILURE, 0};

return {EVMC_SUCCESS, 256};
}

ExecutionResult bls12_g2msm_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
Expand Down Expand Up @@ -577,10 +549,8 @@ inline constexpr auto traits = []() noexcept {
{blake2bf_analyze, blake2bf_execute},
{point_evaluation_analyze, point_evaluation_execute},
{bls12_g1add_analyze, bls12_g1add_execute},
{bls12_g1mul_analyze, bls12_g1mul_execute},
{bls12_g1msm_analyze, bls12_g1msm_execute},
{bls12_g2add_analyze, bls12_g2add_execute},
{bls12_g2mul_analyze, bls12_g2mul_execute},
{bls12_g2msm_analyze, bls12_g2msm_execute},
{bls12_pairing_check_analyze, bls12_pairing_check_execute},
{bls12_map_fp_to_g1_analyze, bls12_map_fp_to_g1_execute},
Expand Down
14 changes: 6 additions & 8 deletions test/state/precompiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ enum class PrecompileId : uint8_t
blake2bf = 0x09,
point_evaluation = 0x0a,
bls12_g1add = 0x0b,
bls12_g1mul = 0x0c,
bls12_g1msm = 0x0d,
bls12_g2add = 0x0e,
bls12_g2mul = 0x0f,
bls12_g2msm = 0x10,
bls12_pairing_check = 0x11,
bls12_map_fp_to_g1 = 0x12,
bls12_map_fp2_to_g2 = 0x13,
bls12_g1msm = 0x0c,
bls12_g2add = 0x0d,
bls12_g2msm = 0x0e,
bls12_pairing_check = 0x0f,
bls12_map_fp_to_g1 = 0x10,
bls12_map_fp2_to_g2 = 0x11,

since_byzantium = expmod, ///< The first precompile introduced in Byzantium.
since_istanbul = blake2bf, ///< The first precompile introduced in Istanbul.
Expand Down
4 changes: 0 additions & 4 deletions test/state/precompiles_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ ExecutionResult point_evaluation_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g1add_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g1mul_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g1msm_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g2add_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g2mul_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_g2msm_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_pairing_check_execute(
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/state_precompiles_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ TEST(state_precompiles, is_precompile)
EXPECT_EQ(is_precompile(rev, 0x0f_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x10_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x11_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x12_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x13_address), rev >= EVMC_PRAGUE);

// Future?
EXPECT_FALSE(is_precompile(rev, 0x12_address));
EXPECT_FALSE(is_precompile(rev, 0x13_address));
EXPECT_FALSE(is_precompile(rev, 0x14_address));
EXPECT_FALSE(is_precompile(rev, 0x15_address));
EXPECT_FALSE(is_precompile(rev, 0x16_address));
Expand Down

0 comments on commit 6e214c6

Please sign in to comment.