From 465cb1512a1214f844beb7cef7d5ff193b65094e Mon Sep 17 00:00:00 2001 From: Milton Date: Fri, 29 Sep 2023 08:27:56 -0300 Subject: [PATCH] Fix bigint pack div mod test --- pkg/hints/bigint_hint.go | 8 +++++++- pkg/hints/bigint_hint_test.go | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/hints/bigint_hint.go b/pkg/hints/bigint_hint.go index dd5ea75c..b1d04a6f 100644 --- a/pkg/hints/bigint_hint.go +++ b/pkg/hints/bigint_hint.go @@ -2,10 +2,12 @@ package hints import ( "errors" + "fmt" "math/big" . "github.com/lambdaclass/cairo-vm.go/pkg/hints/hint_utils" "github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks" + "github.com/lambdaclass/cairo-vm.go/pkg/math_utils" . "github.com/lambdaclass/cairo-vm.go/pkg/types" . "github.com/lambdaclass/cairo-vm.go/pkg/utils" . "github.com/lambdaclass/cairo-vm.go/pkg/vm" @@ -138,6 +140,7 @@ func calculateX(vm *VirtualMachine, idsData IdsManager) (big.Int, error) { x0 := x_bigint5[0] x1 := x_bigint5[1] x2 := x_bigint5[2] + var limbs = []lambdaworks.Felt{x0, x1, x2} x_lower := BigInt3{Limbs: limbs} @@ -173,9 +176,12 @@ func bigintPackDivMod(vm *VirtualMachine, execScopes *ExecutionScopes, idsData I if err != nil { return err } + x1 := x y := yUnpacked.Pack86() - res, _ := new(big.Int).DivMod(&x, &y, &p) + res, _ := math_utils.DivMod(&x1, &y, &p) + fmt.Println("x", x.Text(10)) + execScopes.AssignOrUpdateVariable("res", *res) execScopes.AssignOrUpdateVariable("value", *res) execScopes.AssignOrUpdateVariable("x", x) diff --git a/pkg/hints/bigint_hint_test.go b/pkg/hints/bigint_hint_test.go index 543e1bc5..b9c15184 100644 --- a/pkg/hints/bigint_hint_test.go +++ b/pkg/hints/bigint_hint_test.go @@ -1,6 +1,7 @@ package hints_test import ( + "fmt" "math/big" "testing" @@ -167,6 +168,7 @@ func TestBigintPackDivModHint(t *testing.T) { "x": { NewMaybeRelocatableFelt(lambdaworks.FeltFromHex("0x38a23ca66202c8c2a72277")), NewMaybeRelocatableFelt(lambdaworks.FeltFromHex("0x6730e765376ff17ea8385")), + NewMaybeRelocatableFelt(lambdaworks.FeltFromHex("0xca1ad489ab60ea581e6c1")), NewMaybeRelocatableFelt(lambdaworks.FeltFromUint(0)), NewMaybeRelocatableFelt(lambdaworks.FeltFromUint(0)), }, @@ -233,11 +235,17 @@ func TestBigintPackDivModHint(t *testing.T) { } p := pu.(big.Int) + fmt.Println("") + fmt.Println("") + fmt.Println("") + fmt.Println("") + fmt.Println("") + fmt.Println("") if res.Cmp(expected) != 0 { - t.Errorf("incorrect res expected: %s, got: %s", expected.Text(10), expected.Text(10)) + t.Errorf("incorrect res expected: %s, got: %s", expected.Text(10), res.Text(10)) } if value.Cmp(expected) != 0 { - t.Errorf("incorrect value expected: %s, got: %s", value.Text(10), expected.Text(10)) + t.Errorf("incorrect value expected: %s, got: %s", expected.Text(10), value.Text(10)) } if y.Cmp(yExpected) != 0 { t.Errorf("incorrect y expected: %s, got: %s", yExpected.Text(10), y.Text(10))