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

precompiles: Add BLS precompiles IDs #984

Merged
merged 1 commit into from
Sep 6, 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
111 changes: 111 additions & 0 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,60 @@ PrecompileAnalysis point_evaluation_analyze(bytes_view, evmc_revision) noexcept
return {POINT_EVALUATION_PRECOMPILE_GAS, 64};
}

PrecompileAnalysis bls12_g1add_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_g1mul_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_g1msm_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_g2add_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_g2mul_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_g2msm_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_pairing_check_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_map_fp_to_g1_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

PrecompileAnalysis bls12_map_fp2_to_g2_analyze(bytes_view, evmc_revision) noexcept
{
// TODO: Implement
return {GasCostMax, 0};
}

ExecutionResult ecrecover_execute(const uint8_t* input, size_t input_size, uint8_t* output,
[[maybe_unused]] size_t output_size) noexcept
{
Expand Down Expand Up @@ -292,6 +346,51 @@ ExecutionResult blake2bf_execute(const uint8_t* input, [[maybe_unused]] size_t i
return {EVMC_SUCCESS, sizeof(h)};
}

ExecutionResult bls12_g1add_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_g1mul_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_g1msm_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_g2add_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_g2mul_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_g2msm_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_pairing_check_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_map_fp_to_g1_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

ExecutionResult bls12_map_fp2_to_g2_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
{
return {EVMC_PRECOMPILE_FAILURE, 0};
}

namespace
{
struct PrecompileTraits
Expand All @@ -313,6 +412,15 @@ inline constexpr auto traits = []() noexcept {
{ecpairing_analyze, ecpairing_stub},
{blake2bf_analyze, blake2bf_execute},
{point_evaluation_analyze, point_evaluation_stub},
{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},
{bls12_map_fp2_to_g2_analyze, bls12_map_fp2_to_g2_execute},
}};
#ifdef EVMONE_PRECOMPILES_SILKPRE
// tbl[static_cast<size_t>(PrecompileId::ecrecover)].execute = silkpre_ecrecover_execute;
Expand Down Expand Up @@ -348,6 +456,9 @@ bool is_precompile(evmc_revision rev, const evmc::address& addr) noexcept
if (rev < EVMC_CANCUN && id >= stdx::to_underlying(PrecompileId::since_cancun))
return false;

if (rev < EVMC_PRAGUE && id >= stdx::to_underlying(PrecompileId::since_prague))
return false;

return true;
}

Expand Down
12 changes: 11 additions & 1 deletion test/state/precompiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ enum class PrecompileId : uint8_t
ecpairing = 0x08,
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,

since_byzantium = expmod, ///< The first precompile introduced in Byzantium.
since_istanbul = blake2bf, ///< The first precompile introduced in Istanbul.
since_cancun = point_evaluation, ///< The first precompile introduced in Cancun.
latest = point_evaluation ///< The latest introduced precompile (highest address).
since_prague = bls12_g1add, ///< The first precompile introduced in Prague.
latest = bls12_map_fp2_to_g2 ///< The latest introduced precompile (highest address).
};

/// The total number of known precompiles ids, including 0.
Expand Down
27 changes: 27 additions & 0 deletions test/state/precompiles_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ PrecompileAnalysis ecmul_analyze(evmc::bytes_view input, evmc_revision rev) noex
PrecompileAnalysis ecpairing_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis blake2bf_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis point_evaluation_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g1add_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g1mul_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g1msm_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g2add_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g2mul_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_g2msm_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_pairing_check_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_map_fp_to_g1_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
PrecompileAnalysis bls12_map_fp2_to_g2_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;

ExecutionResult ecrecover_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
Expand All @@ -44,4 +53,22 @@ ExecutionResult ecmul_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult blake2bf_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(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_map_fp_to_g1_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
ExecutionResult bls12_map_fp2_to_g2_execute(
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
} // namespace evmone::state
20 changes: 15 additions & 5 deletions test/unittests/state_precompiles_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ TEST(state_precompiles, is_precompile)
// Cancun:
EXPECT_EQ(is_precompile(rev, 0x0a_address), rev >= EVMC_CANCUN);

// Prague:
EXPECT_EQ(is_precompile(rev, 0x0b_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x0c_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x0d_address), rev >= EVMC_PRAGUE);
EXPECT_EQ(is_precompile(rev, 0x0e_address), rev >= EVMC_PRAGUE);
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, 0x0b_address));
EXPECT_FALSE(is_precompile(rev, 0x0c_address));
EXPECT_FALSE(is_precompile(rev, 0x0d_address));
EXPECT_FALSE(is_precompile(rev, 0x0e_address));
EXPECT_FALSE(is_precompile(rev, 0x0f_address));
EXPECT_FALSE(is_precompile(rev, 0x14_address));
EXPECT_FALSE(is_precompile(rev, 0x15_address));
EXPECT_FALSE(is_precompile(rev, 0x16_address));
EXPECT_FALSE(is_precompile(rev, 0x17_address));
}
}