From b5dac4caece7709f138d00ee0850354239e37dae Mon Sep 17 00:00:00 2001 From: Shourya Goel Date: Fri, 28 Jun 2024 17:19:47 +0530 Subject: [PATCH 1/6] Integration test for Is_Zero (#494) * Bug fix * Added integration test and fixed hintcode * clean * bug fix * Updated hint comments * Ran gofmt * Update is_zero.small.cairo * Bug Fix * Comment update * Update .env * Bump cairo-lang version * Updated test --- .github/workflows/integration-test.yml | 2 +- integration_tests/.env | 2 +- .../cairo_zero_hint_tests/is_zero.small.cairo | 31 +++++++++++++++++++ pkg/hintrunner/zero/hintcode.go | 2 +- pkg/hintrunner/zero/zerohint_ec.go | 7 +++-- 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 integration_tests/cairo_zero_hint_tests/is_zero.small.cairo diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f630180f9..b788a923e 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -18,7 +18,7 @@ jobs: python-version: '3.9' - name: Install cairo-lang - run: pip install cairo-lang==0.11 + run: pip install cairo-lang==0.13.1 - name: Build run: make build diff --git a/integration_tests/.env b/integration_tests/.env index 8ffc53953..b24a173e8 100644 --- a/integration_tests/.env +++ b/integration_tests/.env @@ -1,2 +1,2 @@ # Set to run some specific file tests (ex. fib.cairo,alloc.cairo) -INTEGRATION_TESTS_FILTERS= +INTEGRATION_TESTS_FILTERS=is_zero.small.cairo diff --git a/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo b/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo new file mode 100644 index 000000000..c1d5e8023 --- /dev/null +++ b/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo @@ -0,0 +1,31 @@ +// Returns 1 if x == 0 (mod secp256k1_prime), and 0 otherwise. +// Serves as integration test for the following hints : +// isZeroNondetCode +// isZeroPackCode +// isZeroDivModCode + +%builtins range_check + +from starkware.cairo.common.cairo_secp.field import is_zero, SumBigInt3 + +func main{range_check_ptr}() -> () { + + // Test One + let a = SumBigInt3(0, 0, 0); + let (res: felt) = is_zero(a); + assert res = 1; + + // Test Two + let b = SumBigInt3(42, 0, 0); + let (res: felt) = is_zero(b); + assert res = 0; + + // Test Three + let c = SumBigInt3( + 77371252455336262886226991, 77371252455336267181195263, 19342813113834066795298815 + ); + let (res: felt) = is_zero(c); + assert res = 1; + + return (); +} diff --git a/pkg/hintrunner/zero/hintcode.go b/pkg/hintrunner/zero/hintcode.go index 3df68b47d..45b54588f 100644 --- a/pkg/hintrunner/zero/hintcode.go +++ b/pkg/hintrunner/zero/hintcode.go @@ -94,7 +94,7 @@ ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])` ecDoubleAssignNewXV1Code string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nslope = pack(ids.slope, PRIME)\nx = pack(ids.point.x, PRIME)\ny = pack(ids.point.y, PRIME)\n\nvalue = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P" ecDoubleAssignNewYV1Code string = "value = new_y = (slope * (x - new_x) - y) % SECP_P" ecMulInnerCode string = "memory[ap] = (ids.scalar % PRIME) % 2" - isZeroNondetCode string = "x == 0" + isZeroNondetCode string = "memory[ap] = to_felt_or_relocatable(x == 0)" isZeroPackCode string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nx = pack(ids.x, PRIME) % SECP_P" isZeroDivModCode string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P\nfrom starkware.python.math_utils import div_mod\n\nvalue = x_inv = div_mod(1, x, SECP_P)" diff --git a/pkg/hintrunner/zero/zerohint_ec.go b/pkg/hintrunner/zero/zerohint_ec.go index 6d67362f9..62cdfc163 100644 --- a/pkg/hintrunner/zero/zerohint_ec.go +++ b/pkg/hintrunner/zero/zerohint_ec.go @@ -736,9 +736,10 @@ func createEcMulInnerHinter(resolver hintReferenceResolver) (hinter.Hinter, erro // i.e, 1 if `x == 0`, 0 otherwise func newIsZeroNondetHint() hinter.Hinter { return &GenericZeroHinter{ - Name: "IsZeroConditional", + Name: "IsZeroNondet", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { - //> x == 0 + //> python hint in cairo file: "x == 0" + //> compiled file hint: "memory[ap] = to_felt_or_relocatable(x == 0)" x, err := ctx.ScopeManager.GetVariableValueAsBigInt("x") if err != nil { @@ -775,6 +776,7 @@ func newIsZeroPackHint(x hinter.ResOperander) hinter.Hinter { Name: "IsZeroPack", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + //> x = pack(ids.x, PRIME) % SECP_P xAddr, err := x.GetAddress(vm) @@ -829,6 +831,7 @@ func newIsZeroDivModHint() hinter.Hinter { Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P //> from starkware.python.math_utils import div_mod + //> value = x_inv = div_mod(1, x, SECP_P) secPBig, ok := secp_utils.GetSecPBig() From dd54197c182d3c95e9a73c58d1530724edf43768 Mon Sep 17 00:00:00 2001 From: Shourya Goel Date: Fri, 28 Jun 2024 17:40:20 +0530 Subject: [PATCH 2/6] Bug Fix and Comment Update (#495) * env update * Updated comments --- integration_tests/.env | 2 +- pkg/hintrunner/zero/zerohint_ec.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/integration_tests/.env b/integration_tests/.env index b24a173e8..8ffc53953 100644 --- a/integration_tests/.env +++ b/integration_tests/.env @@ -1,2 +1,2 @@ # Set to run some specific file tests (ex. fib.cairo,alloc.cairo) -INTEGRATION_TESTS_FILTERS=is_zero.small.cairo +INTEGRATION_TESTS_FILTERS= diff --git a/pkg/hintrunner/zero/zerohint_ec.go b/pkg/hintrunner/zero/zerohint_ec.go index 62cdfc163..2b582995b 100644 --- a/pkg/hintrunner/zero/zerohint_ec.go +++ b/pkg/hintrunner/zero/zerohint_ec.go @@ -24,6 +24,7 @@ func newEcNegateHint(point hinter.ResOperander) hinter.Hinter { Name: "EcNegate", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + //> //> y = pack(ids.point.y, PRIME) % SECP_P //> # The modulo operation in python always returns a nonnegative number. //> value = (-y) % SECP_P @@ -84,6 +85,7 @@ func newNondetBigint3V1Hint(res hinter.ResOperander) hinter.Hinter { Name: "NondetBigint3V1", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import split + //> //> segments.write_arg(ids.res.address_, split(value)) address, err := res.GetAddress(vm) @@ -146,11 +148,12 @@ func newFastEcAddAssignNewXHint(slope, point0, point1 hinter.ResOperander) hinte Name: "FastEcAddAssignNewX", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack - // + //> //> slope = pack(ids.slope, PRIME) //> x0 = pack(ids.point0.x, PRIME) //> x1 = pack(ids.point1.x, PRIME) //> y0 = pack(ids.point0.y, PRIME) + //> //> value = new_x = (pow(slope, 2, SECP_P) - x0 - x1) % SECP_P slopeAddr, err := slope.GetAddress(vm) @@ -315,7 +318,7 @@ func newEcDoubleSlopeV1Hint(point hinter.ResOperander) hinter.Hinter { Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack //> from starkware.python.math_utils import ec_double_slope - // + //> //> # Compute the slope. //> x = pack(ids.point.x, PRIME) //> y = pack(ids.point.y, PRIME) @@ -389,6 +392,7 @@ func newReduceV1Hint(x hinter.ResOperander) hinter.Hinter { Name: "ReduceV1", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + //> //> value = pack(ids.x, PRIME) % SECP_P secPBig, ok := secp_utils.GetSecPBig() @@ -442,11 +446,11 @@ func newEcDoubleAssignNewXV1Hint(slope, point hinter.ResOperander) hinter.Hinter Name: "EcDoubleAssignNewXV1", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack - + //> //> slope = pack(ids.slope, PRIME) //> x = pack(ids.point.x, PRIME) //> y = pack(ids.point.y, PRIME) - + //> //> value = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P slopeAddr, err := slope.GetAddress(vm) @@ -593,7 +597,7 @@ func newComputeSlopeV1Hint(point0, point1 hinter.ResOperander) hinter.Hinter { Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack //> from starkware.python.math_utils import line_slope - + //> //> # Compute the slope. //> x0 = pack(ids.point0.x, PRIME) //> y0 = pack(ids.point0.y, PRIME) @@ -776,7 +780,7 @@ func newIsZeroPackHint(x hinter.ResOperander) hinter.Hinter { Name: "IsZeroPack", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack - + //> //> x = pack(ids.x, PRIME) % SECP_P xAddr, err := x.GetAddress(vm) @@ -831,7 +835,7 @@ func newIsZeroDivModHint() hinter.Hinter { Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P //> from starkware.python.math_utils import div_mod - + //> //> value = x_inv = div_mod(1, x, SECP_P) secPBig, ok := secp_utils.GetSecPBig() From d56008d134b3f2d424db4472d5b5f0bcaf4097f5 Mon Sep 17 00:00:00 2001 From: Tristan <122918260+TAdev0@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:54:36 +0200 Subject: [PATCH 3/6] Improve `ZeroDictionary` struct (#475) * improve zerodict pointers * fmt * fmt --------- Co-authored-by: Shourya Goel --- pkg/hintrunner/hinter/zero_dict.go | 21 ++++++++++--------- pkg/hintrunner/zero/hintparser.go | 8 +++---- pkg/hintrunner/zero/zerohint_dictionaries.go | 6 +++--- .../zero/zerohint_dictionaries_test.go | 4 ++-- pkg/hintrunner/zero/zerohint_keccak.go | 2 +- pkg/hintrunner/zero/zerohint_keccak_test.go | 2 +- pkg/hintrunner/zero/zerohint_utils_test.go | 4 ++-- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/pkg/hintrunner/hinter/zero_dict.go b/pkg/hintrunner/hinter/zero_dict.go index 0f6f1c08a..38fbf67f7 100644 --- a/pkg/hintrunner/hinter/zero_dict.go +++ b/pkg/hintrunner/hinter/zero_dict.go @@ -11,27 +11,27 @@ import ( // Used to keep track of all Dictionaries data type ZeroDictionary struct { // The Data contained in a dictionary - Data map[fp.Element]mem.MemoryValue + Data *map[fp.Element]mem.MemoryValue // Default value for key not present in the dictionary - DefaultValue mem.MemoryValue + DefaultValue *mem.MemoryValue // first free offset in memory segment of dictionary FreeOffset *uint64 } // Gets the memory value at certain key func (d *ZeroDictionary) at(key fp.Element) (mem.MemoryValue, error) { - if value, ok := d.Data[key]; ok { + if value, ok := (*d.Data)[key]; ok { return value, nil } - if d.DefaultValue != mem.UnknownValue { - return d.DefaultValue, nil + if *d.DefaultValue != mem.UnknownValue { + return *d.DefaultValue, nil } return mem.UnknownValue, fmt.Errorf("no value for key: %v", key) } // Given a key and a value, it sets the value at the given key func (d *ZeroDictionary) set(key fp.Element, value mem.MemoryValue) { - d.Data[key] = value + (*d.Data)[key] = value } // Given a incrementBy value, it increments the freeOffset field of dictionary by it @@ -63,8 +63,8 @@ func (dm *ZeroDictionaryManager) NewDictionary(vm *VM.VirtualMachine, data map[f newDictAddr := vm.Memory.AllocateEmptySegment() freeOffset := uint64(0) dm.Dictionaries[newDictAddr.SegmentIndex] = ZeroDictionary{ - Data: data, - DefaultValue: mem.UnknownValue, + Data: &data, + DefaultValue: &mem.UnknownValue, FreeOffset: &freeOffset, } return newDictAddr @@ -76,10 +76,11 @@ func (dm *ZeroDictionaryManager) NewDictionary(vm *VM.VirtualMachine, data map[f // querying the defaultValue will be returned instead. func (dm *ZeroDictionaryManager) NewDefaultDictionary(vm *VM.VirtualMachine, defaultValue mem.MemoryValue) mem.MemoryAddress { newDefaultDictAddr := vm.Memory.AllocateEmptySegment() + newData := make(map[fp.Element]mem.MemoryValue) freeOffset := uint64(0) dm.Dictionaries[newDefaultDictAddr.SegmentIndex] = ZeroDictionary{ - Data: make(map[fp.Element]mem.MemoryValue), - DefaultValue: defaultValue, + Data: &newData, + DefaultValue: &defaultValue, FreeOffset: &freeOffset, } return newDefaultDictAddr diff --git a/pkg/hintrunner/zero/hintparser.go b/pkg/hintrunner/zero/hintparser.go index 8df56c909..fe3b28e19 100644 --- a/pkg/hintrunner/zero/hintparser.go +++ b/pkg/hintrunner/zero/hintparser.go @@ -215,7 +215,7 @@ func (expression OffsetExp) Evaluate() (*int, error) { negNumber := -*expression.NegNumber return &negNumber, nil default: - return nil, fmt.Errorf("Expected a number") + return nil, fmt.Errorf("expected a number") } } @@ -226,7 +226,7 @@ func (expression DerefExp) Evaluate() (any, error) { } cellRef, ok := cellRefExp.(hinter.CellRefer) if !ok { - return nil, fmt.Errorf("Expected a CellRefer expression but got %s", cellRefExp) + return nil, fmt.Errorf("expected a CellRefer expression but got %s", cellRefExp) } return hinter.Deref{Deref: cellRef}, nil } @@ -301,7 +301,7 @@ func (expression LeftExp) Evaluate() (any, error) { case expression.DerefExp != nil: return expression.DerefExp.Evaluate() } - return nil, fmt.Errorf("Unexpected left expression in binary operation") + return nil, fmt.Errorf("unexpected left expression in binary operation") } func (expression RightExp) Evaluate() (any, error) { @@ -311,7 +311,7 @@ func (expression RightExp) Evaluate() (any, error) { case expression.Offset != nil: return expression.Offset.Evaluate() } - return nil, fmt.Errorf("Unexpected right expression in binary operation") + return nil, fmt.Errorf("unexpected right expression in binary operation") } func ParseIdentifier(value string) (hinter.Reference, error) { diff --git a/pkg/hintrunner/zero/zerohint_dictionaries.go b/pkg/hintrunner/zero/zerohint_dictionaries.go index 17c48deb7..d869c453c 100644 --- a/pkg/hintrunner/zero/zerohint_dictionaries.go +++ b/pkg/hintrunner/zero/zerohint_dictionaries.go @@ -230,7 +230,7 @@ func newDictSquashCopyDictHint(dictAccessesEnd hinter.ResOperander) hinter.Hinte } dictionaryDataCopy := make(map[fp.Element]memory.MemoryValue) - for k, v := range dictionary.Data { + for k, v := range *dictionary.Data { // Copy the key keyCopy := fp.Element{} keyCopy.Set(&k) @@ -490,7 +490,7 @@ func newSquashDictHint(dictAccesses, ptrDiff, nAccesses, bigKeys, firstKey hinte return err } if ptrDiffValue%DictAccessSize != 0 { - return fmt.Errorf("Accesses array size must be divisible by DictAccess.SIZE") + return fmt.Errorf("accesses array size must be divisible by DictAccess.SIZE") } //> n_accesses = ids.n_accesses @@ -506,7 +506,7 @@ func newSquashDictHint(dictAccesses, ptrDiff, nAccesses, bigKeys, firstKey hinte // __squash_dict_max_size is always in scope and has a value of 2**20, squashDictMaxSize := uint64(1048576) if nAccessesValue > squashDictMaxSize { - return fmt.Errorf("squash_dict() can only be used with n_accesses<={%d}. Got: n_accesses={%d}.", squashDictMaxSize, nAccessesValue) + return fmt.Errorf("squash_dict() can only be used with n_accesses<={%d}. Got: n_accesses={%d}", squashDictMaxSize, nAccessesValue) } //> # A map from key to the list of indices accessing it. diff --git a/pkg/hintrunner/zero/zerohint_dictionaries_test.go b/pkg/hintrunner/zero/zerohint_dictionaries_test.go index cbeacfb66..6f7bfaae3 100644 --- a/pkg/hintrunner/zero/zerohint_dictionaries_test.go +++ b/pkg/hintrunner/zero/zerohint_dictionaries_test.go @@ -599,7 +599,7 @@ func TestZeroHintDictionaries(t *testing.T) { ctx.operanders["first_key"], ) }, - errCheck: errorTextContains("Accesses array size must be divisible by DictAccess.SIZE"), + errCheck: errorTextContains("accesses array size must be divisible by DictAccess.SIZE"), }, { operanders: []*hintOperander{ @@ -625,7 +625,7 @@ func TestZeroHintDictionaries(t *testing.T) { ctx.operanders["first_key"], ) }, - errCheck: errorTextContains("squash_dict() can only be used with n_accesses<={1048576}. Got: n_accesses={1048577}."), + errCheck: errorTextContains("squash_dict() can only be used with n_accesses<={1048576}. Got: n_accesses={1048577}"), }, { operanders: []*hintOperander{ diff --git a/pkg/hintrunner/zero/zerohint_keccak.go b/pkg/hintrunner/zero/zerohint_keccak.go index c631cf324..c784223ad 100644 --- a/pkg/hintrunner/zero/zerohint_keccak.go +++ b/pkg/hintrunner/zero/zerohint_keccak.go @@ -109,7 +109,7 @@ func newUnsafeKeccakHint(data, length, high, low hinter.ResOperander) hinter.Hin //> f'Got: length={length}.' keccakMaxSize := uint64(1 << 20) if lengthVal > keccakMaxSize { - return fmt.Errorf("unsafe_keccak() can only be used with length<=%d.\n Got: length=%d.", keccakMaxSize, lengthVal) + return fmt.Errorf("unsafe_keccak() can only be used with length<=%d.\n Got: length=%d", keccakMaxSize, lengthVal) } dataPtr, err := hinter.ResolveAsAddress(vm, data) diff --git a/pkg/hintrunner/zero/zerohint_keccak_test.go b/pkg/hintrunner/zero/zerohint_keccak_test.go index a4d3f443b..996d1eb74 100644 --- a/pkg/hintrunner/zero/zerohint_keccak_test.go +++ b/pkg/hintrunner/zero/zerohint_keccak_test.go @@ -59,7 +59,7 @@ func TestZeroHintKeccak(t *testing.T) { makeHinter: func(ctx *hintTestContext) hinter.Hinter { return newUnsafeKeccakHint(ctx.operanders["data"], ctx.operanders["length"], ctx.operanders["high"], ctx.operanders["low"]) }, - errCheck: errorTextContains(fmt.Sprintf("unsafe_keccak() can only be used with length<=%d.\n Got: length=%d.", 1<<20, (1<<20)+1)), + errCheck: errorTextContains(fmt.Sprintf("unsafe_keccak() can only be used with length<=%d.\n Got: length=%d", 1<<20, (1<<20)+1)), }, { operanders: []*hintOperander{ diff --git a/pkg/hintrunner/zero/zerohint_utils_test.go b/pkg/hintrunner/zero/zerohint_utils_test.go index d72420ad6..6b87c2b21 100644 --- a/pkg/hintrunner/zero/zerohint_utils_test.go +++ b/pkg/hintrunner/zero/zerohint_utils_test.go @@ -297,8 +297,8 @@ func zeroDictInScopeEquals(dictAddress memory.MemoryAddress, expectedData map[fp t.Fatal(fmt.Errorf("no dictionary at address: %s", dictAddress)) } - assert.Equal(t, expectedData, dictionary.Data) - assert.Equal(t, expectedDefaultValue, dictionary.DefaultValue) + assert.Equal(t, expectedData, *dictionary.Data) + assert.Equal(t, expectedDefaultValue, *dictionary.DefaultValue) assert.Equal(t, expectedFreeOffset, *dictionary.FreeOffset) } } From 9e0187498c47ced0d53060ba4a61d494b38deb64 Mon Sep 17 00:00:00 2001 From: Tristan <122918260+TAdev0@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:16:35 +0200 Subject: [PATCH 4/6] `CompareKeccakFullRateInBytes` keccak hint (#482) * CompareKeccakFullRateInBytes * fmt * fmt * improve comment * add comment * update comment --------- Co-authored-by: Shourya Goel --- pkg/hintrunner/zero/hintcode.go | 5 ++- pkg/hintrunner/zero/zerohint.go | 2 + pkg/hintrunner/zero/zerohint_keccak.go | 43 +++++++++++++++++++++ pkg/hintrunner/zero/zerohint_keccak_test.go | 29 ++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/pkg/hintrunner/zero/hintcode.go b/pkg/hintrunner/zero/hintcode.go index 45b54588f..01363f815 100644 --- a/pkg/hintrunner/zero/hintcode.go +++ b/pkg/hintrunner/zero/hintcode.go @@ -123,8 +123,9 @@ ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])` inp = [0] * _keccak_state_size_felts padding = (inp + keccak_func(inp)) * _block_size segments.write_arg(ids.keccak_ptr_end, padding)` - keccakWriteArgsCode string = "segments.write_arg(ids.inputs, [ids.low % 2 ** 64, ids.low // 2 ** 64])\nsegments.write_arg(ids.inputs + 2, [ids.high % 2 ** 64, ids.high // 2 ** 64])" - blockPermutationCode string = "from starkware.cairo.common.keccak_utils.keccak_utils import keccak_func\n_keccak_state_size_felts = int(ids.KECCAK_STATE_SIZE_FELTS)\nassert 0 <= _keccak_state_size_felts < 100\noutput_values = keccak_func(memory.get_range(\nids.keccak_ptr - _keccak_state_size_felts, _keccak_state_size_felts))\nsegments.write_arg(ids.keccak_ptr, output_values)" + keccakWriteArgsCode string = "segments.write_arg(ids.inputs, [ids.low % 2 ** 64, ids.low // 2 ** 64])\nsegments.write_arg(ids.inputs + 2, [ids.high % 2 ** 64, ids.high // 2 ** 64])" + compareKeccakFullRateInBytesCode string = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)" + blockPermutationCode string = "from starkware.cairo.common.keccak_utils.keccak_utils import keccak_func\n_keccak_state_size_felts = int(ids.KECCAK_STATE_SIZE_FELTS)\nassert 0 <= _keccak_state_size_felts < 100\noutput_values = keccak_func(memory.get_range(\nids.keccak_ptr - _keccak_state_size_felts, _keccak_state_size_felts))\nsegments.write_arg(ids.keccak_ptr, output_values)" // ------ Dictionaries hints related code ------ dictNewCode string = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_dict(segments, initial_dict)\ndel initial_dict" diff --git a/pkg/hintrunner/zero/zerohint.go b/pkg/hintrunner/zero/zerohint.go index 34b84e8bb..6399e7f8c 100644 --- a/pkg/hintrunner/zero/zerohint.go +++ b/pkg/hintrunner/zero/zerohint.go @@ -167,6 +167,8 @@ func GetHintFromCode(program *zero.ZeroProgram, rawHint zero.Hint, hintPC uint64 return createUnsafeKeccakHinter(resolver) case unsafeKeccakFinalizeCode: return createUnsafeKeccakFinalizeHinter(resolver) + case compareKeccakFullRateInBytesCode: + return createCompareKeccakFullRateInBytesNondetHinter(resolver) case blockPermutationCode: return createBlockPermutationHinter(resolver) // Usort hints diff --git a/pkg/hintrunner/zero/zerohint_keccak.go b/pkg/hintrunner/zero/zerohint_keccak.go index c784223ad..8c27a445b 100644 --- a/pkg/hintrunner/zero/zerohint_keccak.go +++ b/pkg/hintrunner/zero/zerohint_keccak.go @@ -407,6 +407,49 @@ func createKeccakWriteArgsHinter(resolver hintReferenceResolver) (hinter.Hinter, return newKeccakWriteArgsHint(inputs, low, high), nil } +// CompareKeccakFullRateInBytes hint compares a value to KECCAK_FULL_RATE_IN_BYTES constant, i.e., 136 +// +// `newKeccakWriteArgsHint` takes 1 operander as argument +// - `nBytes` is the value to be compared with KECCAK_FULL_RATE_IN_BYTES +// +// `newKeccakWriteArgsHint` writes 1 or 0 to `ap` memory address depending on whether +// `n_bytes` is greater or equal to KECCAK_FULL_RATE_IN_BYTES or not +func newCompareKeccakFullRateInBytesHint(nBytes hinter.ResOperander) hinter.Hinter { + return &GenericZeroHinter{ + Name: "CompareKeccakFullRateInBytes", + Op: func(vm *VM.VirtualMachine, _ *hinter.HintRunnerContext) error { + //> python hint: ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES + //> JSON file hint: memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES) + + // n_bytes should fit into a uint64 + // we cannot 100% exclude the possibility that it doesn't + nBytesVal, err := hinter.ResolveAsUint64(vm, nBytes) + if err != nil { + return err + } + + apAddr := vm.Context.AddressAp() + var resultMv memory.MemoryValue + if nBytesVal >= uint64(utils.KECCAK_FULL_RATE_IN_BYTES) { + resultMv = memory.MemoryValueFromFieldElement(&utils.FeltOne) + } else { + resultMv = memory.MemoryValueFromFieldElement(&utils.FeltZero) + } + + return vm.Memory.WriteToAddress(&apAddr, &resultMv) + }, + } +} + +func createCompareKeccakFullRateInBytesNondetHinter(resolver hintReferenceResolver) (hinter.Hinter, error) { + nBytes, err := resolver.GetResOperander("n_bytes") + if err != nil { + return nil, err + } + + return newCompareKeccakFullRateInBytesHint(nBytes), nil +} + // BlockPermutation hint executes the Keccak block permutation function to a segment of memory // // `newBlockPermutationHint` takes 1 operander as argument diff --git a/pkg/hintrunner/zero/zerohint_keccak_test.go b/pkg/hintrunner/zero/zerohint_keccak_test.go index 996d1eb74..462d78648 100644 --- a/pkg/hintrunner/zero/zerohint_keccak_test.go +++ b/pkg/hintrunner/zero/zerohint_keccak_test.go @@ -430,6 +430,35 @@ func TestZeroHintKeccak(t *testing.T) { }, }, }, + "CompareKeccakFullRateInBytes": { + { + operanders: []*hintOperander{ + {Name: "n_bytes", Kind: fpRelative, Value: feltUint64(137)}, + }, + makeHinter: func(ctx *hintTestContext) hinter.Hinter { + return newCompareKeccakFullRateInBytesHint(ctx.operanders["n_bytes"]) + }, + check: apValueEquals(feltUint64(1)), + }, + { + operanders: []*hintOperander{ + {Name: "n_bytes", Kind: fpRelative, Value: feltUint64(136)}, + }, + makeHinter: func(ctx *hintTestContext) hinter.Hinter { + return newCompareKeccakFullRateInBytesHint(ctx.operanders["n_bytes"]) + }, + check: apValueEquals(feltUint64(1)), + }, + { + operanders: []*hintOperander{ + {Name: "n_bytes", Kind: fpRelative, Value: feltUint64(135)}, + }, + makeHinter: func(ctx *hintTestContext) hinter.Hinter { + return newCompareKeccakFullRateInBytesHint(ctx.operanders["n_bytes"]) + }, + check: apValueEquals(feltUint64(0)), + }, + }, "BlockPermutation": { { operanders: []*hintOperander{ From 036884a10f9595b8f0731e7f0dfa2d7eda1b6884 Mon Sep 17 00:00:00 2001 From: Tristan <122918260+TAdev0@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:27:06 +0200 Subject: [PATCH 5/6] `CompareBytesInWord` keccak hint (#481) * CompareBytesInWordHint * add comments to the hint * add comment for uint64 casting * update comment * fmt * fmt * fix --------- Co-authored-by: Shourya Goel --- pkg/hintrunner/zero/hintcode.go | 3 +- pkg/hintrunner/zero/zerohint.go | 2 + pkg/hintrunner/zero/zerohint_keccak.go | 44 +++++++++++++++++++++ pkg/hintrunner/zero/zerohint_keccak_test.go | 20 ++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/pkg/hintrunner/zero/hintcode.go b/pkg/hintrunner/zero/hintcode.go index 01363f815..c0c27b896 100644 --- a/pkg/hintrunner/zero/hintcode.go +++ b/pkg/hintrunner/zero/hintcode.go @@ -124,8 +124,9 @@ ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])` padding = (inp + keccak_func(inp)) * _block_size segments.write_arg(ids.keccak_ptr_end, padding)` keccakWriteArgsCode string = "segments.write_arg(ids.inputs, [ids.low % 2 ** 64, ids.low // 2 ** 64])\nsegments.write_arg(ids.inputs + 2, [ids.high % 2 ** 64, ids.high // 2 ** 64])" - compareKeccakFullRateInBytesCode string = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)" blockPermutationCode string = "from starkware.cairo.common.keccak_utils.keccak_utils import keccak_func\n_keccak_state_size_felts = int(ids.KECCAK_STATE_SIZE_FELTS)\nassert 0 <= _keccak_state_size_felts < 100\noutput_values = keccak_func(memory.get_range(\nids.keccak_ptr - _keccak_state_size_felts, _keccak_state_size_felts))\nsegments.write_arg(ids.keccak_ptr, output_values)" + compareBytesInWordCode string = "memory[ap] = to_felt_or_relocatable(ids.n_bytes < ids.BYTES_IN_WORD)" + compareKeccakFullRateInBytesCode string = "memory[ap] = to_felt_or_relocatable(ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES)" // ------ Dictionaries hints related code ------ dictNewCode string = "if '__dict_manager' not in globals():\n from starkware.cairo.common.dict import DictManager\n __dict_manager = DictManager()\n\nmemory[ap] = __dict_manager.new_dict(segments, initial_dict)\ndel initial_dict" diff --git a/pkg/hintrunner/zero/zerohint.go b/pkg/hintrunner/zero/zerohint.go index 6399e7f8c..4ec0f0b62 100644 --- a/pkg/hintrunner/zero/zerohint.go +++ b/pkg/hintrunner/zero/zerohint.go @@ -171,6 +171,8 @@ func GetHintFromCode(program *zero.ZeroProgram, rawHint zero.Hint, hintPC uint64 return createCompareKeccakFullRateInBytesNondetHinter(resolver) case blockPermutationCode: return createBlockPermutationHinter(resolver) + case compareBytesInWordCode: + return createCompareBytesInWordNondetHinter(resolver) // Usort hints case usortEnterScopeCode: return createUsortEnterScopeHinter() diff --git a/pkg/hintrunner/zero/zerohint_keccak.go b/pkg/hintrunner/zero/zerohint_keccak.go index 8c27a445b..c5c099d87 100644 --- a/pkg/hintrunner/zero/zerohint_keccak.go +++ b/pkg/hintrunner/zero/zerohint_keccak.go @@ -528,3 +528,47 @@ func createBlockPermutationHinter(resolver hintReferenceResolver) (hinter.Hinter return newBlockPermutationHint(keccakPtr), nil } + +// CompareBytesInWord hint compares a value to BYTES_IN_WORD constant, i.e., 8 +// +// `newCompareBytesInWordHint` takes 1 operander as argument +// - `nBytes` is the value to be compared with BYTES_IN_WORD +// +// `newCompareBytesInWordHint` writes 1 or 0 to `ap` memory address depending on whether +// `n_bytes` is lower than BYTES_IN_WORD or not +func newCompareBytesInWordHint(nBytes hinter.ResOperander) hinter.Hinter { + return &GenericZeroHinter{ + Name: "CompareBytesInWordHint", + Op: func(vm *VM.VirtualMachine, _ *hinter.HintRunnerContext) error { + //> python hint: ids.n_bytes < ids.BYTES_IN_WORD + //> JSON file hint: memory[ap] = to_felt_or_relocatable(ids.n_bytes < ids.BYTES_IN_WORD) + + // n_bytes should fit into a uint64 + // we cannot 100% exclude the possibility that it doesn't + nBytesVal, err := hinter.ResolveAsUint64(vm, nBytes) + if err != nil { + return err + } + + bytesInWord := uint64(8) + apAddr := vm.Context.AddressAp() + var resultMv memory.MemoryValue + if nBytesVal < bytesInWord { + resultMv = memory.MemoryValueFromFieldElement(&utils.FeltOne) + } else { + resultMv = memory.MemoryValueFromFieldElement(&utils.FeltZero) + } + + return vm.Memory.WriteToAddress(&apAddr, &resultMv) + }, + } +} + +func createCompareBytesInWordNondetHinter(resolver hintReferenceResolver) (hinter.Hinter, error) { + nBytes, err := resolver.GetResOperander("n_bytes") + if err != nil { + return nil, err + } + + return newCompareBytesInWordHint(nBytes), nil +} diff --git a/pkg/hintrunner/zero/zerohint_keccak_test.go b/pkg/hintrunner/zero/zerohint_keccak_test.go index 462d78648..8617d0cb0 100644 --- a/pkg/hintrunner/zero/zerohint_keccak_test.go +++ b/pkg/hintrunner/zero/zerohint_keccak_test.go @@ -585,5 +585,25 @@ func TestZeroHintKeccak(t *testing.T) { }), }, }, + "CompareBytesInWordHint": { + { + operanders: []*hintOperander{ + {Name: "n_bytes", Kind: fpRelative, Value: feltUint64(5)}, + }, + makeHinter: func(ctx *hintTestContext) hinter.Hinter { + return newCompareBytesInWordHint(ctx.operanders["n_bytes"]) + }, + check: apValueEquals(feltUint64(1)), + }, + { + operanders: []*hintOperander{ + {Name: "n_bytes", Kind: fpRelative, Value: feltUint64(10)}, + }, + makeHinter: func(ctx *hintTestContext) hinter.Hinter { + return newCompareBytesInWordHint(ctx.operanders["n_bytes"]) + }, + check: apValueEquals(feltUint64(0)), + }, + }, }) } From 6d939e42512553336c04b339d6edc3f466990e1c Mon Sep 17 00:00:00 2001 From: Shourya Goel Date: Fri, 28 Jun 2024 22:29:38 +0530 Subject: [PATCH 6/6] FEAT : Benchmark for integration tests (#477) * Added Benchmark for integration tests * Relocated time measuring code * nit * Minor design changes * Using tabwriter --- integration_tests/BenchMarks.txt | 81 +++++++++++++++++++++ integration_tests/cairozero_test.go | 105 ++++++++++++++++++++++++---- 2 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 integration_tests/BenchMarks.txt diff --git a/integration_tests/BenchMarks.txt b/integration_tests/BenchMarks.txt new file mode 100644 index 000000000..460afc40e --- /dev/null +++ b/integration_tests/BenchMarks.txt @@ -0,0 +1,81 @@ +=========================================================================================================================== +| File | PythonVM (ms) | GoVM (ms) | +=========================================================================================================================== +| get_point_from_x.small.cairo | 971 | 125 | +--------------------------------------------------------------------------------------------------------------------------- +| is_quad_residue.small.cairo | 963 | 152 | +--------------------------------------------------------------------------------------------------------------------------- +| reduce_v1.small.cairo | 931 | 130 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_unsigned_div_rem.small.cairo | 1061 | 132 | +--------------------------------------------------------------------------------------------------------------------------- +| set_add.small.cairo | 749 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| split64.small.cairo | 1014 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_signedNN.small.cairo | 752 | 114 | +--------------------------------------------------------------------------------------------------------------------------- +| split_felt.small.cairo | 841 | 145 | +--------------------------------------------------------------------------------------------------------------------------- +| split_int.small.cairo | 1037 | 133 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_add.small.cairo | 921 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| signed_div_rem.small.cairo | 816 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| sqrt.small.cairo | 960 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_sqrt.small.cairo | 1195 | 115 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_not_zero.cairo | 586 | 100 | +--------------------------------------------------------------------------------------------------------------------------- +| blake.starknet_with_keccak.cairo | 2498 | 144 | +--------------------------------------------------------------------------------------------------------------------------- +| import_secp256R1P.small.cairo | 699 | 123 | +--------------------------------------------------------------------------------------------------------------------------- +| memcpy.cairo | 704 | 124 | +--------------------------------------------------------------------------------------------------------------------------- +| unsigned_div_rem.small.cairo | 843 | 118 | +--------------------------------------------------------------------------------------------------------------------------- +| factorial.cairo | 1161 | 123 | +--------------------------------------------------------------------------------------------------------------------------- +| hintrefs.cairo | 676 | 127 | +--------------------------------------------------------------------------------------------------------------------------- +| cmp.small.cairo | 897 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| dict_squash.small.cairo | 1240 | 166 | +--------------------------------------------------------------------------------------------------------------------------- +| div_mod_n.small.cairo | 921 | 113 | +--------------------------------------------------------------------------------------------------------------------------- +| find_element.small.cairo | 939 | 124 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_mul_div_mod.small.cairo | 1032 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| verify_zero.small.cairo | 781 | 112 | +--------------------------------------------------------------------------------------------------------------------------- +| ec.small.cairo | 1042 | 129 | +--------------------------------------------------------------------------------------------------------------------------- +| memset.cairo | 701 | 128 | +--------------------------------------------------------------------------------------------------------------------------- +| pow.small.cairo | 887 | 112 | +--------------------------------------------------------------------------------------------------------------------------- +| search_sorted_lower.small.cairo | 836 | 134 | +--------------------------------------------------------------------------------------------------------------------------- +| alloc.cairo | 666 | 126 | +--------------------------------------------------------------------------------------------------------------------------- +| simple.cairo | 596 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_250_bits.small.cairo | 979 | 120 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_not_equal.cairo | 638 | 101 | +--------------------------------------------------------------------------------------------------------------------------- +| dict.cairo | 678 | 115 | +--------------------------------------------------------------------------------------------------------------------------- +| is_positive.small.cairo | 884 | 128 | +--------------------------------------------------------------------------------------------------------------------------- +| usort.small.cairo | 797 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| verify_ecdsa_signature.small.cairo | 758 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| fib.cairo | 634 | 116 | +=========================================================================================================================== diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index 0564ffe26..04653c83d 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -5,8 +5,11 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "testing" + "text/tabwriter" + "time" "github.com/NethermindEth/cairo-vm-go/pkg/vm" "github.com/consensys/gnark-crypto/ecc/stark-curve/fp" @@ -69,6 +72,8 @@ func TestCairoZeroFiles(t *testing.T) { filter := Filter{} filter.init() + benchmarkMap := make(map[string][2]int) + for _, dirEntry := range testFiles { if dirEntry.IsDir() || isGeneratedFile(dirEntry.Name()) { continue @@ -91,18 +96,20 @@ func TestCairoZeroFiles(t *testing.T) { continue } - pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) + elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) if err != nil { t.Error(err) continue } - traceFile, memoryFile, _, err := runVm(compiledOutput) + elapsedGo, traceFile, memoryFile, _, err := runVm(compiledOutput) if err != nil { t.Error(err) continue } + benchmarkMap[dirEntry.Name()] = [2]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds())} + pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) if err != nil { t.Error(err) @@ -125,10 +132,68 @@ func TestCairoZeroFiles(t *testing.T) { } } + WriteBenchMarksToFile(benchmarkMap) + clean(root1) clean(root2) } +// Save the Benchmarks for the integration tests in `BenchMarks.txt` +func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { + totalWidth := 123 + + border := strings.Repeat("=", totalWidth) + separator := strings.Repeat("-", totalWidth) + + var sb strings.Builder + w := tabwriter.NewWriter(&sb, 40, 0, 0, ' ', tabwriter.Debug) + + sb.WriteString(border + "\n") + fmt.Fprintln(w, "| File \t PythonVM (ms) \t GoVM (ms) \t") + w.Flush() + sb.WriteString(border + "\n") + + iterator := 0 + totalFiles := len(benchmarkMap) + + for key, values := range benchmarkMap { + row := "| " + key + "\t " + + for iter, value := range values { + row = row + strconv.Itoa(value) + "\t" + if iter == 0 { + row = row + " " + } + } + + fmt.Fprintln(w, row) + w.Flush() + + if iterator < totalFiles-1 { + sb.WriteString(separator + "\n") + } + + iterator++ + } + + sb.WriteString(border + "\n") + + fileName := "BenchMarks.txt" + file, err := os.Create(fileName) + if err != nil { + fmt.Println("Error creating file: ", err) + return + } + defer file.Close() + + _, err = file.WriteString(sb.String()) + if err != nil { + fmt.Println("Error writing to file: ", err) + } else { + fmt.Println("Benchmarks successfully written to:", fileName) + } +} + const ( compiledSuffix = "_compiled.json" pyTraceSuffix = "_py_trace" @@ -166,7 +231,7 @@ func compileZeroCode(path string) (string, error) { // given a path to a compiled cairo zero file, execute it using the // python vm and returns the trace and memory files location -func runPythonVm(testFilename, path string) (string, string, error) { +func runPythonVm(testFilename, path string) (time.Duration, string, string, error) { traceOutput := swapExtenstion(path, pyTraceSuffix) memoryOutput := swapExtenstion(path, pyMemorySuffix) @@ -191,19 +256,24 @@ func runPythonVm(testFilename, path string) (string, string, error) { cmd := exec.Command("cairo-run", args...) + start := time.Now() + res, err := cmd.CombinedOutput() + + elapsed := time.Since(start) + if err != nil { - return "", "", fmt.Errorf( + return 0, "", "", fmt.Errorf( "cairo-run %s: %w\n%s", path, err, string(res), ) } - return traceOutput, memoryOutput, nil + return elapsed, traceOutput, memoryOutput, nil } // given a path to a compiled cairo zero file, execute // it using our vm -func runVm(path string) (string, string, string, error) { +func runVm(path string) (time.Duration, string, string, string, error) { traceOutput := swapExtenstion(path, traceSuffix) memoryOutput := swapExtenstion(path, memorySuffix) @@ -230,14 +300,19 @@ func runVm(path string) (string, string, string, error) { path, ) + start := time.Now() + res, err := cmd.CombinedOutput() + + elapsed := time.Since(start) + if err != nil { - return "", "", string(res), fmt.Errorf( + return 0, "", "", string(res), fmt.Errorf( "cairo-vm run %s: %w\n%s", path, err, string(res), ) } - return traceOutput, memoryOutput, string(res), nil + return elapsed, traceOutput, memoryOutput, string(res), nil } @@ -316,7 +391,7 @@ func TestFailingRangeCheck(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/range_check.small.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.ErrorContains(t, err, "check write: 2**128 <") clean("./builtin_tests/") @@ -326,7 +401,7 @@ func TestBitwise(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/bitwise_builtin_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.NoError(t, err) clean("./builtin_tests/") @@ -336,7 +411,7 @@ func TestPedersen(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/pedersen_test.small.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 2089986280348253421170679821480865132823066470938446095505822317253594081284") @@ -347,7 +422,7 @@ func TestPoseidon(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/poseidon_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 442682200349489646213731521593476982257703159825582578145778919623645026501\n 2233832504250924383748553933071188903279928981104663696710686541536735838182\n 2512222140811166287287541003826449032093371832913959128171347018667852712082\n") require.Contains(t, output, "3016509350703874362933565866148509373957094754875411937434637891208784994231\n 3015199725895936530535660185611704199044060139852899280809302949374221328865\n 3062378460350040063467318871602229987911299744598148928378797834245039883769\n") @@ -358,7 +433,7 @@ func TestECDSA(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/ecdsa_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.NoError(t, err) clean("./builtin_tests/") @@ -368,7 +443,7 @@ func TestEcOp(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/ecop.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) // todo(rodro): This test is failing due to the lack of hint processing. It should be address soon require.Error(t, err) @@ -379,7 +454,7 @@ func TestKeccak(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/keccak_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 1304102964824333531548398680304964155037696012322029952943772\n 688749063493959345342507274897412933692859993314608487848187\n 986714560881445649520443980361539218531403996118322524237197\n 1184757872753521629808292433475729390634371625298664050186717\n 719230200744669084408849842242045083289669818920073250264351\n 1543031433416778513637578850638598357854418012971636697855068\n 63644822371671650271181212513090078620238279557402571802224\n 879446821229338092940381117330194802032344024906379963157761\n")