Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Sep 23, 2023
1 parent 70b51ed commit 1dbd540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 6 additions & 8 deletions pkg/hintrunner/hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ func (hint WideMul128) String() string {
}

func (hint WideMul128) Execute(vm *VM.VirtualMachine) error {
u128Max := big.NewInt(1).Lsh(big.NewInt(1), 128)
u128Max = big.NewInt(1).Sub(u128Max, big.NewInt(1))
u128MaxFelt := &f.Element{}
u128MaxFelt.SetBigInt(u128Max)
u128MaxFelt := MaxU128Felt()

lsh, err := hint.lhs.Resolve(vm)
lhs, err := hint.lhs.Resolve(vm)
if err != nil {
return fmt.Errorf("resolve lhs operand %s: %v", hint.lhs, err)
}
Expand All @@ -116,7 +113,7 @@ func (hint WideMul128) Execute(vm *VM.VirtualMachine) error {
return fmt.Errorf("resolve rhs operand %s: %v", hint.rhs, err)
}

lhsFelt, err := lsh.ToFieldElement()
lhsFelt, err := lhs.ToFieldElement()
if err != nil {
return err
}
Expand All @@ -129,14 +126,15 @@ func (hint WideMul128) Execute(vm *VM.VirtualMachine) error {
return err
}
if rhsFelt.Cmp(u128MaxFelt) > 0 {
return fmt.Errorf("lhs operand %s should be u128", rhsFelt)
return fmt.Errorf("rhs operand %s should be u128", rhsFelt)
}

mul := big.NewInt(1).Mul(lhsFelt.BigInt(big.NewInt(1)), rhsFelt.BigInt(big.NewInt(1)))
mask := MaxU128()

low := big.NewInt(1)
high := big.NewInt(1)
low.And(mul, u128Max)
low.And(mul, mask)
high.Rsh(mul, 128)

lowFelt := &f.Element{}
Expand Down
1 change: 0 additions & 1 deletion pkg/hintrunner/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func TestWideMul128(t *testing.T) {

low := &f.Element{}
low.SetBigInt(big.NewInt(1).Lsh(big.NewInt(1), 127))
require.Nil(t, err)

require.Equal(
t,
Expand Down

0 comments on commit 1dbd540

Please sign in to comment.