From a2e02582e5bb5239aeaa2f29fc210a687a0de1dd Mon Sep 17 00:00:00 2001 From: Elkana Tovey <40407298+elkanatovey@users.noreply.github.com> Date: Tue, 20 May 2025 19:51:25 +0300 Subject: [PATCH] Optimize BabyDbl implementation for constraint efficiency Replace the current BabyDbl implementation with an optimized version that directly implements Edwards doubling formulas rather than reusing BabyAdd. This improves constraint efficiency by getting rid of unnecessary intermediate calculations. --- circuits/babyjub.circom | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/circuits/babyjub.circom b/circuits/babyjub.circom index 36810fee..3782fb56 100644 --- a/circuits/babyjub.circom +++ b/circuits/babyjub.circom @@ -55,14 +55,22 @@ template BabyDbl() { signal output xout; signal output yout; - component adder = BabyAdd(); - adder.x1 <== x; - adder.y1 <== y; - adder.x2 <== x; - adder.y2 <== y; - - adder.xout ==> xout; - adder.yout ==> yout; + var a = 168700; + var d = 168696; + signal x2 <== x * x; + signal y2 <== y * y; + signal xy <== x * y; + signal xy2 <== xy * xy; + + signal denomx <== 1 + d * xy2; + signal denomy <== 1 - d * xy2; + + + xout <-- (2 * xy) / denomx; + yout <-- (y2 - a * x2) / denomy; + + denomx * xout === 2 * xy; + denomy * yout === y2 - a * x2; }