I tried to build a wrapper around the precompiled contracts as follows: https://gist.github.com/AlexXiong97/9c24bbd4541323a61fa63100860a5f89
If you paste it into Remix and deploy it, inputting any (valid) scalar into scalarBaseMult
function would result in a VM revert, which indicates a failure in parameters provided to the precompiled contract.
However, I'm pretty confident the parameters are correct as I generate them directly from Cloudflare's bn256 library which is exactly what Geth uses. Here's my script: https://gist.github.com/AlexXiong97/217f42ee4d0dedc6182b182134caeed9
If you input (1, 2, 3)
into scalarMult
, the correct result will be returned which makes sense as (1,2) is indeed a point on the bn256 curve y^2 = x^3 +3
I once suspect my computed generator coordinates are wrong, but as specified here: the generator is (1, -2) mod p, where p's value is here, thus I'm quite sure there's nothing wrong with their value.
Can anyone help me understand what might cause the VM exception?