Skip to content

Commit 69d165e

Browse files
committed
refactor: assert input checks in bls12 executes
1 parent 08284bd commit 69d165e

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

test/state/precompiles.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,8 @@ ExecutionResult bls12_g1add_execute(const uint8_t* input, size_t input_size, uin
601601
ExecutionResult bls12_g1msm_execute(const uint8_t* input, size_t input_size, uint8_t* output,
602602
[[maybe_unused]] size_t output_size) noexcept
603603
{
604-
if (input_size % BLS12_G1_MUL_INPUT_SIZE != 0)
605-
return {EVMC_PRECOMPILE_FAILURE, 0};
606-
604+
// Checked in `_analyze` function which must be called before.
605+
assert(input_size % BLS12_G1_MUL_INPUT_SIZE == 0);
607606
assert(output_size == BLS12_G1_POINT_SIZE);
608607

609608
if (input_size == BLS12_G1_MUL_INPUT_SIZE)
@@ -638,9 +637,8 @@ ExecutionResult bls12_g2add_execute(const uint8_t* input, size_t input_size, uin
638637
ExecutionResult bls12_g2msm_execute(const uint8_t* input, size_t input_size, uint8_t* output,
639638
[[maybe_unused]] size_t output_size) noexcept
640639
{
641-
if (input_size % BLS12_G2_MUL_INPUT_SIZE != 0)
642-
return {EVMC_PRECOMPILE_FAILURE, 0};
643-
640+
// Checked in `_analyze` function which must be called before.
641+
assert(input_size % BLS12_G2_MUL_INPUT_SIZE == 0);
644642
assert(output_size == BLS12_G2_POINT_SIZE);
645643

646644
if (input_size == BLS12_G2_MUL_INPUT_SIZE)
@@ -661,9 +659,8 @@ ExecutionResult bls12_g2msm_execute(const uint8_t* input, size_t input_size, uin
661659
ExecutionResult bls12_pairing_check_execute(const uint8_t* input, size_t input_size,
662660
uint8_t* output, [[maybe_unused]] size_t output_size) noexcept
663661
{
664-
if (input_size % (BLS12_G1_POINT_SIZE + BLS12_G2_POINT_SIZE) != 0)
665-
return {EVMC_PRECOMPILE_FAILURE, 0};
666-
662+
// Checked in `_analyze` function which must be called before.
663+
assert(input_size % (BLS12_G1_POINT_SIZE + BLS12_G2_POINT_SIZE) == 0);
667664
assert(output_size == 32);
668665

669666
if (!crypto::bls::pairing_check(output, input, input_size))

0 commit comments

Comments
 (0)