kakarot icon indicating copy to clipboard operation
kakarot copied to clipboard

feat: Precompile 0x08 ecPairing

Open Eikix opened this issue 2 years ago • 6 comments

Feature Request

Describe the Feature Request

feat: Explore / propose strategy (if applicable, MVP implementation) for EVM Precompiled contract -> 0x08 ecPairing

https://www.evm.codes/precompiled

Eikix avatar Dec 09 '22 11:12 Eikix

alt_bn128 pairing logic is implemented in this file https://github.com/tekkac/cairo-alt_bn128/blob/c2ec87cc9b57846f2d89861f77b4bee69e2a5720/alt_bn128_pair.cairo#L143-L167 , the main part being the Miller loop, but it uses unsafe hints from this file https://github.com/tekkac/cairo-alt_bn128/blob/main/alt_bn128_gt.cairo

The author originally thought these hints could be verified in Cairo like for ec_add and ec_mul, but this is another type of ellipitic curve the same tricks don't apply here. Native implementation (without hints + verification) implies arithmetics over FQ12 which are very costly. Nethermind has a more advanced implementation of the miller loop for bls12-381 https://github.com/NethermindEth/optimized_ecc_cairo/blob/main/lib/pairing.cairo , but the miller loop is ~1 million step per iteration, with tens of iterations at minimum.

The smartest move would be to discover if a hint can be used with a small verification cost, but this requires much deeper knowledge of maths, and we don't have the certainty that it is even possible.

feltroidprime avatar Dec 14 '22 08:12 feltroidprime

In fact in https://github.com/tekkac/cairo-alt_bn128/blob/main/alt_bn128_gt.cairo, There might be a trick to verify the hint of gt_line_slope though, but not the arithmetics like fq12_mul .

feltroidprime avatar Dec 14 '22 08:12 feltroidprime

I wrote the code above and I plan to work on it more soon. My idea is to use a larger field to verify the mutiplication using a new hint (polynomial division). It would increase the number of steps though, but we might get away with it. Will report back.

tekkac avatar Dec 15 '22 10:12 tekkac

Awesome!! Thank you for your input

Eikix avatar Dec 15 '22 21:12 Eikix

is this unlock with new Garaga builtins @enitrat ?

ClementWalter avatar Sep 07 '24 11:09 ClementWalter

it should be but felt told me it would take him a week or two

enitrat avatar Sep 07 '24 11:09 enitrat

waiting for cairo 2.9

ClementWalter avatar Oct 25 '24 08:10 ClementWalter