diff --git a/pkg/hintrunner/constants.go b/pkg/hintrunner/constants.go index 25d0d5012..a212f0178 100644 --- a/pkg/hintrunner/constants.go +++ b/pkg/hintrunner/constants.go @@ -1,13 +1,13 @@ package hintrunner import ( - "math/big" + "github.com/holiman/uint256" f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp" ) -func MaxU128() *big.Int { - return big.NewInt(0).SetBits([]big.Word{18446744073709551615, 18446744073709551615}) +func MaxU128() *uint256.Int { + return uint256.NewInt(0).SetBytes([]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}) } func MaxU128Felt() *f.Element { diff --git a/pkg/hintrunner/hint.go b/pkg/hintrunner/hint.go index 581b10726..52befc778 100644 --- a/pkg/hintrunner/hint.go +++ b/pkg/hintrunner/hint.go @@ -4,6 +4,8 @@ import ( "fmt" "math/big" + "github.com/holiman/uint256" + VM "github.com/NethermindEth/cairo-vm-go/pkg/vm" "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory" f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp" @@ -129,18 +131,18 @@ func (hint WideMul128) Execute(vm *VM.VirtualMachine) error { 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))) + mul := uint256.NewInt(1).Mul(uint256.MustFromBig(lhsFelt.BigInt(big.NewInt(1))), uint256.MustFromBig(rhsFelt.BigInt(big.NewInt(1)))) mask := MaxU128() - low := big.NewInt(1) - high := big.NewInt(1) + low := uint256.NewInt(1) + high := uint256.NewInt(1) low.And(mul, mask) high.Rsh(mul, 128) lowFelt := &f.Element{} - lowFelt.SetBigInt(low) + lowFelt.SetBigInt(low.ToBig()) highFelt := &f.Element{} - highFelt.SetBigInt(high) + highFelt.SetBigInt(high.ToBig()) lowCell, err := hint.low.Get(vm) if err != nil {