Skip to content

Commit

Permalink
Fix bigint pack div mod test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsc2 committed Sep 29, 2023
1 parent 7522950 commit 465cb15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/hints/bigint_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions pkg/hints/bigint_hint_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hints_test

import (
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -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)),
},
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 465cb15

Please sign in to comment.