-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: gas computation / unexpected cycle in computation issue with recursive type definition #5524
Comments
Tell me if you need more explanation, context or whatever ! |
Thank you for the report! |
Awesome ! Thanks @orizi for your quick fix ! What is the good way to reorder function definitions to fix the issue ? Because I could use this trick to have my feature branch working on Dojo while waiting for your fix to be merged :) |
It seems that if you define the functions with the loops first it works better. (Before the function that calls them) |
Ah yes, it looks like this trick works fine with Cairo 2.5.4 but not with Cairo 2.6.3. Thanks for the feedback 👍 |
probably has something to do with the changes in inlining that changed the scheduling of the algorithm. |
Bug Report
Cairo version:
At least on
2.5.4
and2.6.3
Current behavior:
For the Dojo project, we use the following types to define the layout of our data that will be stored in a dedicated smart contract:
Then, we have 3 functions to read/write/delete an object based on its layout.
This code leads to:
Failed calculating gas usage, it is likely a call for
gas::withdraw_gasis missing.
error when we try to run our test suite.Compiling Sierra class to CASM with compiler version 2.5.4... Error: found an unexpected cycle during cost computation
when we try to declare the compiled contract class on Katana.I built the following tiny project outside of Dojo to reproduce the issue : https://github.com/remybar/scarb-recursion
In this project, there is only these 2 types and the
entity()
function which reads an object thanks to the_read_layout()
function.This project has exactly the same issues than our Dojo project.
If I remove the
Struct: Span<FieldLayout>
variant fromLayout
, I can runscarb test
and declare the contract class on Katana.Also, if the
_read_layout()
function does not have any loop inside, everything works well.So, I guess the issue is due to the fact that 2 variants from
Layout
refers, directly on indirectly through an intermediate type, to itself (theLayout
type). And if we loop on this type, the gas computation failed.Expected behavior:
At a first glance, this Cairo code seems legit to me and should work fine.
Steps to reproduce:
Just run
scarb test
and/or declare the contract class onKatana
.Related code:
https://github.com/remybar/scarb-recursion
The text was updated successfully, but these errors were encountered: