diff --git a/lib/evmone_precompiles/bls.cpp b/lib/evmone_precompiles/bls.cpp index 6afa04e670..5c6efc6e79 100644 --- a/lib/evmone_precompiles/bls.cpp +++ b/lib/evmone_precompiles/bls.cpp @@ -6,6 +6,7 @@ namespace evmone::crypto::bls { +using namespace intx; namespace { /// Offset of the beginning of field element. First 16 bytes must be zero according to spec @@ -203,6 +204,7 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept scalars_ptrs.reserve(npoints); auto ptr = _xycs; + [[maybe_unused]] const auto x_org_npoints = npoints; for (size_t i = 0; i < npoints; ++i) { const auto p_affine = validate_p1(ptr, &ptr[64]); @@ -214,11 +216,18 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept // Point at infinity must be filtered out for BLST library. if (blst_p1_affine_is_inf(&*p_affine)) + { + [[maybe_unused]] const auto xs = be::unsafe::load(ptr + 128); + // assert(xs == 0); + // assert(xs != 0); + assert(xs != 1); continue; + } const auto& p = p1_affines.emplace_back(*p_affine); p1_affine_ptrs.emplace_back(&p); + // assert((ptr[128] & 0x80) != 0); blst_scalar scalar; blst_scalar_from_bendian(&scalar, &ptr[128]); const auto& s = scalars.emplace_back(scalar); @@ -231,6 +240,8 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept if (npoints == 0) { + // assert(x_org_npoints == 0); + assert(x_org_npoints != 0); memset(_rx, 0, 64); memset(_ry, 0, 64); return true; @@ -267,6 +278,7 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept scalars.reserve(npoints); scalars_ptrs.reserve(npoints); + [[maybe_unused]] const auto x_org_npoints = npoints; auto ptr = _xycs; for (size_t i = 0; i < npoints; ++i) { @@ -279,11 +291,18 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept // Point at infinity must be filtered out for BLST library. if (blst_p2_affine_is_inf(&*p_affine)) + { + [[maybe_unused]] const auto xs = be::unsafe::load(ptr + 256); + // assert(xs == 0); + // assert(xs != 0); + assert(xs != 1); continue; + } const auto& p = p2_affines.emplace_back(*p_affine); p2_affine_ptrs.emplace_back(&p); + // assert((ptr[256] & 0x80) != 0); blst_scalar scalar; blst_scalar_from_bendian(&scalar, &ptr[256]); const auto& s = scalars.emplace_back(scalar); @@ -296,6 +315,8 @@ void store(uint8_t _rx[128], const blst_fp2& _x) noexcept if (npoints == 0) { + // assert(x_org_npoints == 0); + assert(x_org_npoints != 0); memset(_rx, 0, 128); memset(_ry, 0, 128); return true; diff --git a/test/state/precompiles.cpp b/test/state/precompiles.cpp index 81c1d3576e..cf2b4fcd9e 100644 --- a/test/state/precompiles.cpp +++ b/test/state/precompiles.cpp @@ -187,6 +187,8 @@ PrecompileAnalysis bls12_g1mul_analyze(bytes_view, evmc_revision) noexcept PrecompileAnalysis bls12_g1msm_analyze(bytes_view input, evmc_revision) noexcept { + // assert(!input.empty()); + // assert(input.size() % 160 == 0); if (input.empty() || input.size() % 160 != 0) return {GasCostMax, 0}; @@ -208,6 +210,8 @@ PrecompileAnalysis bls12_g2mul_analyze(bytes_view, evmc_revision) noexcept PrecompileAnalysis bls12_g2msm_analyze(bytes_view input, evmc_revision) noexcept { + // assert(!input.empty()); + // assert(input.size() % 288 == 0); if (input.empty() || input.size() % 288 != 0) return {GasCostMax, 0};