-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement SignedDivRemHint * Implement hint method * Debug implementation, add testcases * Debug implementation * Fix merge problems * Resolved comments from the PR * Replace PrimeHigh calculation with const, modify the bound check condition for value * Add as_int method * Added test case for the as_int() functionality * Applied suggestions from the comments * Move AsInt to math_utils, make AsInt return BigInt pointer
- Loading branch information
1 parent
73a2a57
commit 722b840
Showing
6 changed files
with
229 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package utils | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp" | ||
) | ||
|
||
func AsInt(valueFelt *fp.Element) *big.Int { | ||
var valueBig big.Int | ||
valueFelt.BigInt(&valueBig) | ||
boundBig := new(big.Int).Div(fp.Modulus(), big.NewInt(2)) | ||
|
||
// val if val < prime // 2 else val - prime | ||
if valueBig.Cmp(boundBig) == -1 { | ||
return &valueBig | ||
} | ||
return new(big.Int).Sub(&valueBig, fp.Modulus()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters