Skip to content
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

Implement Uint256SquareRoot #134

Merged
merged 33 commits into from
Nov 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
213cfe4
added UpdatePc tests and fixed a bug in UpdatePc
mmk-1 Sep 22, 2023
1e1cfe7
Fixed accessing field value without Read()
mmk-1 Sep 25, 2023
39f71f6
Merge branch 'main' into main
mmk-1 Sep 26, 2023
60194fb
fixed failing tests
mmk-1 Sep 26, 2023
df8cd7f
small refactor for TestUpdatePcJump
mmk-1 Sep 26, 2023
98a3d1c
Merge branch 'NethermindEth:main' into main
mmk-1 Oct 2, 2023
1a2280f
Merge branch 'NethermindEth:main' into main
mmk-1 Oct 13, 2023
8dec869
Merge branch 'NethermindEth:main' into main
mmk-1 Oct 17, 2023
0447eff
added SquareRoot hint + test
mmk-1 Oct 17, 2023
0900990
removed usage of U256
mmk-1 Oct 18, 2023
1e0188d
fixed the hint for sqrt
mmk-1 Oct 20, 2023
1973382
removed unnecessary byte conversion in squareroot hint
mmk-1 Oct 20, 2023
b344646
u256sqrt Execute() function done. need test
mmk-1 Oct 20, 2023
e5e5562
remove unnecessary comment
mmk-1 Oct 20, 2023
a0eedf5
refactoring u256sqrt method
mmk-1 Oct 20, 2023
b793e2e
fixed uint256sqrt with added test
mmk-1 Oct 23, 2023
ae53fc3
add new test case for high bytes
mmk-1 Oct 23, 2023
e9be2d0
refactoring u256sqrt method
mmk-1 Oct 23, 2023
df57e98
more refactoring and removed a .clone()
mmk-1 Oct 23, 2023
c85abad
Merge branch 'main' into u256sqrt
mmk-1 Oct 23, 2023
084cc48
removed whitespace
mmk-1 Oct 23, 2023
b32a7b9
fix whitespace
mmk-1 Oct 23, 2023
65892ee
add new test
mmk-1 Oct 24, 2023
1a8e38a
Merge branch 'NethermindEth:main' into main
mmk-1 Oct 25, 2023
0e77687
Merge branch 'main' into u256sqrt
mmk-1 Oct 31, 2023
e12f6f7
minor fixes
mmk-1 Oct 31, 2023
8d08f1a
Merge branch 'NethermindEth:main' into main
mmk-1 Oct 31, 2023
f75ca1a
fix test error
mmk-1 Oct 31, 2023
66db9bd
removed the usage of Clone() in Uin256SqrtRoot
mmk-1 Nov 1, 2023
85052a0
add benchmark test
mmk-1 Nov 1, 2023
16bf020
minor refactor
mmk-1 Nov 2, 2023
6912eb4
Merge branch 'NethermindEth:main' into main
mmk-1 Nov 6, 2023
36d994f
Merge branch 'main' into u256sqrt
mmk-1 Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
minor fixes
mmk-1 committed Oct 31, 2023
commit e12f6f7558f372eee8027e1a1175c0493f8762ab
15 changes: 7 additions & 8 deletions pkg/hintrunner/hint.go
Original file line number Diff line number Diff line change
@@ -414,19 +414,20 @@ func (hint Uint256SquareRoot) Execute(vm *VM.VirtualMachine) error {

// value = {value_low} + {value_high} * 2**128
valueLowU256 := uint256.Int(valueLowFelt.Bits())
valueHighU256 := uint256.Int(valueHighFelt.Bits())
valueHighU256.Lsh(&valueHighU256, 128)
value := valueHighU256.Add(&valueHighU256, &valueLowU256)
value := uint256.Int(valueHighFelt.Bits())
value.Lsh(&value, 128)
value.Add(&value, &valueLowU256)

// root = math.isqrt(value)
root := value.Clone()
root.Sqrt(value)
root.Sqrt(&value)

// remainder = value - root ** 2
root2 := root.Clone()
var root2 *uint256.Int
// root2 := root.Clone()
root2.Mul(root, root)
remainder := value.Clone()
remainder.Sub(value, root2)
remainder.Sub(&value, root2)

// memory{sqrt0} = root & 0xFFFFFFFFFFFFFFFF
// memory{sqrt1} = root >> 64
@@ -437,11 +438,9 @@ func (hint Uint256SquareRoot) Execute(vm *VM.VirtualMachine) error {

sqrt0 := f.Element{}
sqrt0.SetBytes(rootMasked.Bytes())
fmt.Println(rootMasked.Dec())

sqrt1 := f.Element{}
sqrt1.SetBytes(rootShifted.Bytes())
fmt.Println(rootShifted.Dec())

sqrt0Addr, err := hint.sqrt0.Get(vm)
if err != nil {