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

Updates to BLS precompiles (EIP-2537) #1089

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 0 additions & 30 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@
if (input.empty() || input.size() % 160 != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define single input size and use ut here and below? Same for G2

return {GasCostMax, 0};

const auto k = input.size() / 160;
assert(k > 0);

Check warning on line 202 in test/state/precompiles.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/precompiles.cpp#L201-L202

Added lines #L201 - L202 were not covered by tests

return {POINT_COSTS[std::min(k, std::size(POINT_COSTS)) - 1] * static_cast<int64_t>(k), 128};

Check warning on line 204 in test/state/precompiles.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/precompiles.cpp#L204

Added line #L204 was not covered by tests
}

PrecompileAnalysis bls12_g2add_analyze(bytes_view, evmc_revision) noexcept
Expand Down Expand Up @@ -233,10 +233,10 @@
if (input.empty() || input.size() % 288 != 0)
return {GasCostMax, 0};

const auto k = input.size() / 288;
assert(k > 0);

Check warning on line 237 in test/state/precompiles.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/precompiles.cpp#L236-L237

Added lines #L236 - L237 were not covered by tests

return {POINT_COSTS[std::min(k, std::size(POINT_COSTS)) - 1] * static_cast<int64_t>(k), 256};

Check warning on line 239 in test/state/precompiles.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/precompiles.cpp#L239

Added line #L239 was not covered by tests
}

PrecompileAnalysis bls12_pairing_check_analyze(bytes_view input, evmc_revision) noexcept
Expand Down Expand Up @@ -443,20 +443,6 @@
return {EVMC_SUCCESS, 128};
}

ExecutionResult bls12_g1mul_execute(const uint8_t* input, size_t input_size, uint8_t* output,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove also their analysis counterparts for g1 and g2. Here and from the header.

[[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 @@
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 @@
{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