AntelopeIO / leap

C++ implementation of the Antelope protocol
Other
116 stars 70 forks source link

bls_fp_mod intrinsic corrupts stack and leads to crash #1462

Closed dimas1185 closed 11 months ago

dimas1185 commented 1 year ago

this is reproduced on bls_integration branch. input data is from sig_verify_test

details of crash: interface::bls_fp_mod intrinsic calls bls12_381::fp::modPrime<8> and later calls bn_divn_low. here is the code part that corrupts the stack:

        carry = bn_lshb_low(a, a, sa, norm);
        if(carry)
        {
            a[sa++] = carry;
        }

sa here have a size of a and hence a[sa++] = carry changes memory beyond variable boundaries and corrupts a stack. here is how call to it looks in bls12_381::fp::modPrime<8>:

std::array<uint64_t, N> k;
//...
bn_divn_low(quotient.data(), remainder.data(), k.data(), N, modulus.data(), 6); // N is sa and k.data() is a
BenjaminGormanPMP commented 1 year ago

PR to support this issue https://github.com/AntelopeIO/bls12-381/pull/5 FYI @dimas1185 @elmato @yarkinwho.