Skip to content

Commit 86feea6

Browse files
committed
precompiles: Add bls precompiles IDs
1 parent 6974fd7 commit 86feea6

File tree

4 files changed

+167
-19
lines changed

4 files changed

+167
-19
lines changed

test/state/precompiles.cpp

+114-13
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,60 @@ PrecompileAnalysis point_evaluation_analyze(bytes_view, evmc_revision) noexcept
153153
return {POINT_EVALUATION_PRECOMPILE_GAS, 64};
154154
}
155155

156+
PrecompileAnalysis bls12_g1add_analyze(bytes_view, evmc_revision) noexcept
157+
{
158+
// TODO: Implement
159+
return {GasCostMax, 0};
160+
}
161+
162+
PrecompileAnalysis bls12_g1mul_analyze(bytes_view, evmc_revision) noexcept
163+
{
164+
// TODO: Implement
165+
return {GasCostMax, 0};
166+
}
167+
168+
PrecompileAnalysis bls12_g1msm_analyze(bytes_view input, evmc_revision) noexcept
169+
{
170+
// TODO: Implement
171+
return {GasCostMax, 0};
172+
}
173+
174+
PrecompileAnalysis bls12_g2add_analyze(bytes_view, evmc_revision) noexcept
175+
{
176+
// TODO: Implement
177+
return {GasCostMax, 0};
178+
}
179+
180+
PrecompileAnalysis bls12_g2mul_analyze(bytes_view, evmc_revision) noexcept
181+
{
182+
// TODO: Implement
183+
return {GasCostMax, 0};
184+
}
185+
186+
PrecompileAnalysis bls12_g2msm_analyze(bytes_view input, evmc_revision) noexcept
187+
{
188+
// TODO: Implement
189+
return {GasCostMax, 0};
190+
}
191+
192+
PrecompileAnalysis bls12_pairing_check_analyze(bytes_view input, evmc_revision) noexcept
193+
{
194+
// TODO: Implement
195+
return {GasCostMax, 0};
196+
}
197+
198+
PrecompileAnalysis bls12_map_fp_to_g1_analyze(bytes_view, evmc_revision) noexcept
199+
{
200+
// TODO: Implement
201+
return {GasCostMax, 0};
202+
}
203+
204+
PrecompileAnalysis bls12_map_fp2_to_g2_analyze(bytes_view, evmc_revision) noexcept
205+
{
206+
// TODO: Implement
207+
return {GasCostMax, 0};
208+
}
209+
156210
ExecutionResult ecrecover_execute(const uint8_t* input, size_t input_size, uint8_t* output,
157211
[[maybe_unused]] size_t output_size) noexcept
158212
{
@@ -292,6 +346,51 @@ ExecutionResult blake2bf_execute(const uint8_t* input, [[maybe_unused]] size_t i
292346
return {EVMC_SUCCESS, sizeof(h)};
293347
}
294348

349+
ExecutionResult bls12_g1add_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
350+
{
351+
return {EVMC_PRECOMPILE_FAILURE, 0};
352+
}
353+
354+
ExecutionResult bls12_g1mul_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
355+
{
356+
return {EVMC_PRECOMPILE_FAILURE, 0};
357+
}
358+
359+
ExecutionResult bls12_g1msm_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
360+
{
361+
return {EVMC_PRECOMPILE_FAILURE, 0};
362+
}
363+
364+
ExecutionResult bls12_g2add_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
365+
{
366+
return {EVMC_PRECOMPILE_FAILURE, 0};
367+
}
368+
369+
ExecutionResult bls12_g2mul_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
370+
{
371+
return {EVMC_PRECOMPILE_FAILURE, 0};
372+
}
373+
374+
ExecutionResult bls12_g2msm_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
375+
{
376+
return {EVMC_PRECOMPILE_FAILURE, 0};
377+
}
378+
379+
ExecutionResult bls12_pairing_check_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
380+
{
381+
return {EVMC_PRECOMPILE_FAILURE, 0};
382+
}
383+
384+
ExecutionResult bls12_map_fp_to_g1_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
385+
{
386+
return {EVMC_PRECOMPILE_FAILURE, 0};
387+
}
388+
389+
ExecutionResult bls12_map_fp2_to_g2_execute(const uint8_t*, size_t, uint8_t*, size_t) noexcept
390+
{
391+
return {EVMC_PRECOMPILE_FAILURE, 0};
392+
}
393+
295394
namespace
296395
{
297396
struct PrecompileTraits
@@ -301,19 +400,18 @@ struct PrecompileTraits
301400
};
302401

303402
inline constexpr auto traits = []() noexcept {
304-
std::array<PrecompileTraits, NumPrecompiles> tbl{{
305-
{}, // undefined for 0
306-
{ecrecover_analyze, ecrecover_execute},
307-
{sha256_analyze, sha256_execute},
308-
{ripemd160_analyze, ripemd160_execute},
309-
{identity_analyze, identity_execute},
310-
{expmod_analyze, expmod_stub},
311-
{ecadd_analyze, ecadd_execute},
312-
{ecmul_analyze, ecmul_execute},
313-
{ecpairing_analyze, ecpairing_stub},
314-
{blake2bf_analyze, blake2bf_execute},
315-
{point_evaluation_analyze, point_evaluation_stub},
316-
}};
403+
std::array<PrecompileTraits, NumPrecompiles> tbl{{{}, // undefined for 0
404+
{ecrecover_analyze, ecrecover_execute}, {sha256_analyze, sha256_execute},
405+
{ripemd160_analyze, ripemd160_execute}, {identity_analyze, identity_execute},
406+
{expmod_analyze, expmod_stub}, {ecadd_analyze, ecadd_execute},
407+
{ecmul_analyze, ecmul_execute}, {ecpairing_analyze, ecpairing_stub},
408+
{blake2bf_analyze, blake2bf_execute}, {point_evaluation_analyze, point_evaluation_stub},
409+
{bls12_g1add_analyze, bls12_g1add_execute}, {bls12_g1mul_analyze, bls12_g1mul_execute},
410+
{bls12_g1msm_analyze, bls12_g1msm_execute}, {bls12_g2add_analyze, bls12_g2add_execute},
411+
{bls12_g2mul_analyze, bls12_g2mul_execute}, {bls12_g2msm_analyze, bls12_g2msm_execute},
412+
{bls12_pairing_check_analyze, bls12_pairing_check_execute},
413+
{bls12_map_fp_to_g1_analyze, bls12_map_fp_to_g1_execute},
414+
{bls12_map_fp2_to_g2_analyze, bls12_map_fp2_to_g2_execute}}};
317415
#ifdef EVMONE_PRECOMPILES_SILKPRE
318416
// tbl[static_cast<size_t>(PrecompileId::ecrecover)].execute = silkpre_ecrecover_execute;
319417
// tbl[static_cast<size_t>(PrecompileId::sha256)].execute = silkpre_sha256_execute;
@@ -348,6 +446,9 @@ bool is_precompile(evmc_revision rev, const evmc::address& addr) noexcept
348446
if (rev < EVMC_CANCUN && id >= stdx::to_underlying(PrecompileId::since_cancun))
349447
return false;
350448

449+
if (rev < EVMC_PRAGUE && id >= stdx::to_underlying(PrecompileId::since_prague))
450+
return false;
451+
351452
return true;
352453
}
353454

test/state/precompiles.hpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ enum class PrecompileId : uint8_t
2222
ecpairing = 0x08,
2323
blake2bf = 0x09,
2424
point_evaluation = 0x0a,
25+
bls12_g1add = 0x0b,
26+
bls12_g1mul = 0x0c,
27+
bls12_g1msm = 0x0d,
28+
bls12_g2add = 0x0e,
29+
bls12_g2mul = 0x0f,
30+
bls12_g2msm = 0x10,
31+
bls12_pairing_check = 0x11,
32+
bls12_map_fp_to_g1 = 0x12,
33+
bls12_map_fp2_to_g2 = 0x13,
2534

2635
since_byzantium = expmod, ///< The first precompile introduced in Byzantium.
2736
since_istanbul = blake2bf, ///< The first precompile introduced in Istanbul.
2837
since_cancun = point_evaluation, ///< The first precompile introduced in Cancun.
29-
latest = point_evaluation ///< The latest introduced precompile (highest address).
38+
since_prague = bls12_g1add, ///< The first precompile introduced in Prague.
39+
latest = bls12_map_fp2_to_g2 ///< The latest introduced precompile (highest address).
3040
};
3141

3242
/// The total number of known precompiles ids, including 0.

test/state/precompiles_internal.hpp

+27
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ PrecompileAnalysis ecmul_analyze(evmc::bytes_view input, evmc_revision rev) noex
2929
PrecompileAnalysis ecpairing_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
3030
PrecompileAnalysis blake2bf_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
3131
PrecompileAnalysis point_evaluation_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
32+
PrecompileAnalysis bls12_g1add_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
33+
PrecompileAnalysis bls12_g1mul_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
34+
PrecompileAnalysis bls12_g1msm_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
35+
PrecompileAnalysis bls12_g2add_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
36+
PrecompileAnalysis bls12_g2mul_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
37+
PrecompileAnalysis bls12_g2msm_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
38+
PrecompileAnalysis bls12_pairing_check_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
39+
PrecompileAnalysis bls12_map_fp_to_g1_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
40+
PrecompileAnalysis bls12_map_fp2_to_g2_analyze(evmc::bytes_view input, evmc_revision rev) noexcept;
3241

3342
ExecutionResult ecrecover_execute(
3443
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
@@ -44,4 +53,22 @@ ExecutionResult ecmul_execute(
4453
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
4554
ExecutionResult blake2bf_execute(
4655
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
56+
ExecutionResult bls12_g1add_execute(
57+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
58+
ExecutionResult bls12_g1mul_execute(
59+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
60+
ExecutionResult bls12_g1msm_execute(
61+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
62+
ExecutionResult bls12_g2add_execute(
63+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
64+
ExecutionResult bls12_g2mul_execute(
65+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
66+
ExecutionResult bls12_g2msm_execute(
67+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
68+
ExecutionResult bls12_pairing_check_execute(
69+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
70+
ExecutionResult bls12_map_fp_to_g1_execute(
71+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
72+
ExecutionResult bls12_map_fp2_to_g2_execute(
73+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
4774
} // namespace evmone::state

test/unittests/state_precompiles_test.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,21 @@ TEST(state_precompiles, is_precompile)
3434
// Cancun:
3535
EXPECT_EQ(is_precompile(rev, 0x0a_address), rev >= EVMC_CANCUN);
3636

37+
// Prague:
38+
EXPECT_EQ(is_precompile(rev, 0x0b_address), rev >= EVMC_PRAGUE);
39+
EXPECT_EQ(is_precompile(rev, 0x0c_address), rev >= EVMC_PRAGUE);
40+
EXPECT_EQ(is_precompile(rev, 0x0d_address), rev >= EVMC_PRAGUE);
41+
EXPECT_EQ(is_precompile(rev, 0x0e_address), rev >= EVMC_PRAGUE);
42+
EXPECT_EQ(is_precompile(rev, 0x0f_address), rev >= EVMC_PRAGUE);
43+
EXPECT_EQ(is_precompile(rev, 0x10_address), rev >= EVMC_PRAGUE);
44+
EXPECT_EQ(is_precompile(rev, 0x11_address), rev >= EVMC_PRAGUE);
45+
EXPECT_EQ(is_precompile(rev, 0x12_address), rev >= EVMC_PRAGUE);
46+
EXPECT_EQ(is_precompile(rev, 0x13_address), rev >= EVMC_PRAGUE);
47+
3748
// Future?
38-
EXPECT_FALSE(is_precompile(rev, 0x0b_address));
39-
EXPECT_FALSE(is_precompile(rev, 0x0c_address));
40-
EXPECT_FALSE(is_precompile(rev, 0x0d_address));
41-
EXPECT_FALSE(is_precompile(rev, 0x0e_address));
42-
EXPECT_FALSE(is_precompile(rev, 0x0f_address));
49+
EXPECT_FALSE(is_precompile(rev, 0x14_address));
50+
EXPECT_FALSE(is_precompile(rev, 0x15_address));
51+
EXPECT_FALSE(is_precompile(rev, 0x16_address));
52+
EXPECT_FALSE(is_precompile(rev, 0x17_address));
4353
}
4454
}

0 commit comments

Comments
 (0)