Skip to content

Commit

Permalink
added some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh0g0-1758 committed Sep 26, 2024
1 parent 6497ed3 commit 2b5a41b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/vm/builtins/layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func getAllCairoLayout() Layout {
{Runner: &Keccak{ratio: 2048, cache: make(map[uint64]fp.Element)}, Builtin: KeccakType},
{Runner: &Poseidon{ratio: 256, cache: make(map[uint64]fp.Element)}, Builtin: PoseidonType},
{Runner: &RangeCheck{ratio: 8, RangeCheckNParts: 6}, Builtin: RangeCheck96Type},
{Runner: &ModBuiltin{ratio: 128, wordBitLen: 1, batchSize: 96, modBuiltinType: Add}, Builtin: AddModeType},
{Runner: &ModBuiltin{ratio: 256, wordBitLen: 1, batchSize: 96, modBuiltinType: Mul}, Builtin: MulModType},
{Runner: &ModBuiltin{ratio: 128, wordBitLen: 96, batchSize: 1, modBuiltinType: Add}, Builtin: AddModeType},
{Runner: &ModBuiltin{ratio: 256, wordBitLen: 96, batchSize: 1, modBuiltinType: Mul}, Builtin: MulModType},
}}
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/vm/builtins/modulo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The case c=x1, a=x2, b=None is currently completely symmetric in fill_value so i
func checkResult(runner ModBuiltin, inverse bool, p, x1, x2 big.Int) (*big.Int, error) {
mem := memory.Memory{}

mem.AllocateEmptySegment()
mem.AllocateBuiltinSegment(&runner)

offsetsPtr := memory.MemoryAddress{SegmentIndex: 0, Offset: 0}

Expand All @@ -81,7 +81,9 @@ func checkResult(runner ModBuiltin, inverse bool, p, x1, x2 big.Int) (*big.Int,
return nil, err
}

runner.writeNWordsValue(&mem, x1Addr, x1)

Check failure on line 84 in pkg/vm/builtins/modulo_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `runner.writeNWordsValue` is not checked (errcheck)
runner.writeNWordsValue(&mem, x2Addr, x2)

Check failure on line 85 in pkg/vm/builtins/modulo_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `runner.writeNWordsValue` is not checked (errcheck)

resAddr, err := x1Addr.AddOffset(int16(2 * N_WORDS))

if err != nil {
Expand All @@ -92,8 +94,6 @@ func checkResult(runner ModBuiltin, inverse bool, p, x1, x2 big.Int) (*big.Int,
x1Addr, resAddr = resAddr, x1Addr
}

runner.writeNWordsValue(&mem, x1Addr, x1)

runner.fillValue(&mem, ModBuiltinInputs{

Check failure on line 97 in pkg/vm/builtins/modulo_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `runner.fillValue` is not checked (errcheck)
p: p,
pValues: [N_WORDS]fp.Element{}, // not used in fillValue
Expand All @@ -102,6 +102,8 @@ func checkResult(runner ModBuiltin, inverse bool, p, x1, x2 big.Int) (*big.Int,
offsetsPtr: offsetsPtr,
}, 0, Operation(runner.modBuiltinType), Operation("Inv"+runner.modBuiltinType))

// return big.NewInt(0), nil

_, OutRes, err := runner.readNWordsValue(&mem, resAddr)
if err != nil {
return nil, err
Expand All @@ -111,7 +113,7 @@ func checkResult(runner ModBuiltin, inverse bool, p, x1, x2 big.Int) (*big.Int,
}

func TestAddModBuiltinRunnerAddition(t *testing.T) {
runner := NewModBuiltin(128, 1, 96, Add)
runner := NewModBuiltin(128, 96, 1, Add)
res1, err := checkResult(*runner, false, *big.NewInt(67), *big.NewInt(17), *big.NewInt(40))
require.NoError(t, err)
require.Equal(t, big.NewInt(57), res1)
Expand Down

0 comments on commit 2b5a41b

Please sign in to comment.