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

BLS multiplication precompiles interoperability #1042

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
20 changes: 18 additions & 2 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ ExecutionResult bls12_g1mul_execute(const uint8_t* input, size_t input_size, uin

assert(output_size == 128);

if (!crypto::bls::g1_mul(output, &output[64], input, &input[64], &input[128]))
// Pass the input to MSM for cross-check. They are ABI equivalent.
if (!crypto::bls::g1_msm(output, &output[64], input, input_size))
return {EVMC_PRECOMPILE_FAILURE, 0};

return {EVMC_SUCCESS, 128};
Expand All @@ -442,6 +443,13 @@ ExecutionResult bls12_g1msm_execute(const uint8_t* input, size_t input_size, uin

assert(output_size == 128);

// For single input pass it to the simpler single-point multiplication.
if (input_size == 160)
{
if (!crypto::bls::g1_mul(output, &output[64], input, &input[64], &input[128]))
return {EVMC_PRECOMPILE_FAILURE, 0};
}

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

Expand Down Expand Up @@ -470,7 +478,8 @@ ExecutionResult bls12_g2mul_execute(const uint8_t* input, size_t input_size, uin

assert(output_size == 256);

if (!crypto::bls::g2_mul(output, &output[128], input, &input[128], &input[256]))
// Pass the input to MSM for cross-check. They are ABI equivalent.
if (!crypto::bls::g2_msm(output, &output[128], input, input_size))
return {EVMC_PRECOMPILE_FAILURE, 0};

return {EVMC_SUCCESS, 256};
Expand All @@ -484,6 +493,13 @@ ExecutionResult bls12_g2msm_execute(const uint8_t* input, size_t input_size, uin

assert(output_size == 256);

// For single input pass it to the simpler single-point multiplication.
if (input_size == 288)
{
if (!crypto::bls::g2_mul(output, &output[128], input, &input[128], &input[256]))
return {EVMC_PRECOMPILE_FAILURE, 0};
}

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

Expand Down