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
In-circuit implementation for BN254 precompiles: ecadd, ecmul and ecpairing. #444
base: main
Are you sure you want to change the base?
Conversation
) | ||
let gasToPay := ECADD_GAS_COST() | ||
|
||
let success := precompileCall(precompileParams, gasToPay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove all unused code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @vladbochok, the code I have left is used to check that the point is on the curve as well as coordinates are less than modulo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NikitaMasych You also left code related to Montgomery form. It is useful when you do many operations with the numbers, but you only need to check that the numbers are less than the modulo and are in the curve. Please remove all code related to Montgomery and instead use traditional math as it would be cheaper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I have just though that it is better to not modify audited code as it serves its purpose. Additionally, there is premature handling of corner-case operations involving Montgomery form, such as Inf + 0 etc. In-circuit we bring only after passing all the corner-cases and checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I would however try to leverage in-circuit checks, leaving a blank call to it from yul code to achieve end-to-end best performance and security
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I have just though that it is better to not modify audited code as it serves its purpose
We will reaudit it fully, please go ahead change & simplify :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if and(eq(x1, x2), eq(y1, y2)) {
I think circuit can handle this better than performing calculation in contract
Probably yes, however I guess there might be a necessity of vanguard validation, so that we won't get any issues with proof generation failing for bad input |
I think this is specific if branching was introduced to optimize the edge case, not because it is a special case. So you can remove this optimisation as circuit will do bettter job anywat |
Hey guys, @vladbochok @StanislavBreadless, I have simplified |
What ❔
yul
wrappers forecadd
andecmul
from contract implementation to circuit.ecpairing
contract-wrapper inyul
to delegate in-circuit.Why ❔
To improve performance and boost EVM equivalence.
Checklist