Skip to content
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

Add costs to libfunctions #173

Open
kwkr opened this issue Jun 4, 2024 · 1 comment
Open

Add costs to libfunctions #173

kwkr opened this issue Jun 4, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@kwkr
Copy link
Contributor

kwkr commented Jun 4, 2024

There is a field costs returned on the requests that runs the code that contains the information about costs for specific libfunctions. The costs object looks as follows:

{
  "costs": {
    "function_costs": {
      "main::main::main": {
        "const_cost": 200,
        "step": 0,
        "hole": 0,
        "range_checks": 0,
        "pedersen": 0,
        "poseidon": 0,
        "bitwise": 0,
        "ec_op": 0
      }
    },
    "variable_costs": {},
    "statements_costs": {
      "0": [
        {
          "statement_type": "Invocation",
          "statement_index": 0,
          "costs": {
            "const_cost": 0,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ],
      "1": [
        {
          "statement_type": "Invocation",
          "statement_index": 1,
          "costs": {
            "const_cost": 0,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ],

      "2": [
        {
          "statement_type": "Invocation",
          "statement_index": 2,
          "costs": {
            "const_cost": 100,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ],
      "3": [
        {
          "statement_type": "Invocation",
          "statement_index": 3,
          "costs": {
            "const_cost": 0,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ],
      "4": [
        {
          "statement_type": "Invocation",
          "statement_index": 4,
          "costs": {
            "const_cost": 100,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ],
      "5": [
        {
          "statement_type": "Return",
          "statement_index": 5,
          "costs": {
            "const_cost": 0,
            "step": 0,
            "hole": 0,
            "range_checks": 0,
            "pedersen": 0,
            "poseidon": 0,
            "bitwise": 0,
            "ec_op": 0
          }
        }
      ]
    }
  }
}

The costs should be included next to the specific statements in the Sierra code here:
image
For this purpose, the property statements_costs should be used. It contains a mapping statement_index => array of costs for a specific statement. If there are multiple elements in the array, they should be just listed next to each other as they represent costs for different branches. The value that should be displayed is the const_cost from the costs object.

The costs above are for the following sample code

use core::felt252;

fn main() -> felt252 {
    let n = 2 + 3;
    n
}
@kwkr kwkr added the help wanted Extra attention is needed label Jun 4, 2024
@ScottyDavies
Copy link

@kwkr can you please assign this issue to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants