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

feat: MulticallCairo precompile #1503

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Oct 12, 2024

Time spent on this PR: 0.5d

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Resolves #1464

What is the new behavior?

  • Implements the MulticallCairo precompile - at address 0x75003, that receives an flattened array of cairo calls and executes them sequentially.
  • Permisionless precompile: anyone can call it, unlike 0x75001
  • ⚠️ For security purposes this precompile CANNOT be called with DELEGATECALL or CALLCODE ⚠️
  • Ignores return data of the Cairo calls
    • Highlights the requirement of a SinglecallCairo precompile that would be permissionless, and also have delegatecall deactivated ?

This change is Reviewable


// Load address and cairo selector called
// Unsafe to assume that the 32 bytes in input do not overflow a felt - responsibility of the caller to format its input correctly
let to_starknet_address = Helpers.bytes32_to_felt(calls);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform to Uint256 and compare to Prime to ensure this does not overflow ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes32_to_uint256 -> ensure not > PRIME -> reconstruct felt from (low, high)?

idk if we should put guard rails around this. @ClementWalter thoughts?

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 66.50246% with 68 lines in your changes missing coverage. Please review.

Project coverage is 61.8%. Comparing base (9c83960) to head (3d589e6).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...zero/kakarot/precompiles/kakarot_precompiles.cairo 63.5% 58 Missing ⚠️
...zero/kakarot/precompiles/precompiles_helpers.cairo 78.7% 7 Missing ⚠️
cairo_zero/kakarot/precompiles/precompiles.cairo 71.4% 2 Missing ⚠️
cairo_zero/kakarot/interpreter.cairo 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1503     +/-   ##
=======================================
- Coverage   61.9%   61.8%   -0.2%     
=======================================
  Files         44      44             
  Lines       8197    8327    +130     
=======================================
+ Hits        5078    5150     +72     
- Misses      3119    3177     +58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@enitrat enitrat force-pushed the feat/batch-call-precompiles branch 2 times, most recently from dba5f03 to 4d2d372 Compare October 14, 2024 16:39
// Input must be at least 4 + 3*32 bytes long.
let is_input_invalid = is_nn(99 - input_len);
// Input must be at least MIN_EVM_ENCODED_STARKNET_CALL_BYTES bytes long to be valid.
let is_call_invalid = is_nn(MIN_EVM_ENCODED_STARKNET_CALL_BYTES - (input_len + 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment about the fact that because of gas cost, input_len < 2**128


yield cairo_counter

tx = await cairo_counter.functions["set_counter"].invoke_v1(0, max_fee=max_fee)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to use our wrapper call and invoke as starknet py is not so stable, and so it's easier when we need to update/patch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call and invoke are good for contracts available in artifacts, not so much when passing an address because the calldata is not parsed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: multicall cairo precompile
3 participants