kkrt-labs / cairo-vm-ts

A typescript implementation of the Cairo VM
Apache License 2.0
18 stars 13 forks source link

Feat: Add lessThanOrEqualAddress cairo hint #132

Open renzobanegass opened 1 month ago

renzobanegass commented 1 month ago

Closes #122

This pull request implements the TestLessThanOrEqualAddress hint as described in the issue. The hint checks whether the value at lhs (a relocatable address) is less than or equal to the value at rhs (another relocatable address) and stores the boolean result (0 or 1) at dst. I'll leave it as a draft for now as I didn't create the cairo integration test yet, I would like some help with that because I don't get how those programs work RN. And would like to get feedback over the implementation and the tests.

Changes Made

zmalatrax commented 1 month ago

@renzobanegass For the integration test, you have to write a Cairo program in the cairo_programs/cairo/hints folder that makes use of the TestLessThanOrEqualAddress.

This hint is used by the multi_pop_front() and multi_pop_back() methods of corelib array.cairo. So you should make a Cairo program using such methods

A simple program such as

fn main() {
    let mut span = array![1, 2, 3].span();
    let _ = span.multi_pop_back::<2>();
}
renzobanegass commented 1 month ago

@renzobanegass For the integration test, you have to write a Cairo program in the cairo_programs/cairo/hints folder that makes use of the TestLessThanOrEqualAddress.

This hint is used by the multi_pop_front() and multi_pop_back() methods of corelib array.cairo. So you should make a Cairo program using such methods

A simple program such as

fn main() {
    let mut span = array![1, 2, 3].span();
    let _ = span.multi_pop_back::<2>();
}

When trying to compile cairo I got this error: image

renzobanegass commented 1 month ago

I pushed some changes, I couldn't compile the cairo programs because of the error I showed you before, I added two, one for the multi_pop_front() and other for the multi_pop_back()

The unit tests are working.

zmalatrax commented 1 month ago

When trying to compile cairo I got this error:

It looks like you haven't the Cairo Zero toolchain (cairo-lang 0.13.1) installed in your current python environment.

Poetry facilitates the management of dependencies, you should have Poetry installed, installation guide here

Then in the root of the project set a poetry env to use python3.10: poetry use python3.10 And install the dependencies of the project (i.e. cairo-lang): poetry install

Then you should be able to compile Cairo Zero files.

zmalatrax commented 1 month ago

⚠️ Your commits are not signed, please configure a GPG key to sign your commits

Also, your typescript files are not formatted as expected. We're using Trunk, install the IDE extension if you're using VSCode or Neovim, otherwise install their CLI and run trunk fmt

renzobanegass commented 1 month ago

Okay, I can now sign my commits, should I do a rebase to sign the previous commits?

I have this error after running poetry install, I already set the env using poetry env use python3.10. image

renzobanegass commented 1 month ago

I solved it, don't worry. I'll check the programs are working.

renzobanegass commented 1 month ago

When running any programs I get this error image

zmalatrax commented 1 month ago

When running any programs I get this error

You're using the cairo-lang command cairo-run which is made for Cairo Zero programs only. cairo-lang is only used for compilation purposes and diff-testing against other Cairo VM implementations.

You should use the the Cairo VM TS CLI command, check the README

You can do make build and then you'll have the Cairo VM TS CLI commands available. The target make compile will compile all the available Cairo and Cairo Zero programs. Check the availables options with cairo --help or cairo run --help

For your program, something like this would execute it: cairo run --layout recursive cairo_programs/cairo/hints/test_less_than_or_equal_address.json

renzobanegass commented 1 month ago

Thanks! I missed that part completely. image

renzobanegass commented 1 month ago

All done!