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

impl GASPRICE opcode (#97) #377

Merged
merged 4 commits into from
Dec 19, 2022
Merged

Conversation

jobez
Copy link
Contributor

@jobez jobez commented Dec 16, 2022

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 #97

What is the new behavior?

  • a naming refactoring of the ExecutionContext.intrinsic_gas_cost -> ExecutionContext.gas_price
  • impl refactoring of
    • returns a felt of the cost, rather than an updated context
    • computes the calldata costs
      • a helper was created Helpers.count_nonzeroes that returns the count of the nonzeroes of the calldata array
  • adds calldata costs to the Constants.TRANSACTION_INTRINSIC_GAS_COST
  • where previous uses of ExecutionContext.compute_intrinsic_gas_cost
    • we call it and take the return value cost and pass that into ExecutionContext.increment_gas_used and use the context returned from that

Other information

@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Base: 87.53% // Head: 87.55% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (6314293) compared to base (71bcce9).
Patch coverage: 95.83% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #377      +/-   ##
==========================================
+ Coverage   87.53%   87.55%   +0.02%     
==========================================
  Files          23       23              
  Lines        3545     3553       +8     
==========================================
+ Hits         3103     3111       +8     
  Misses        442      442              
Impacted Files Coverage Δ
src/kakarot/instructions.cairo 38.82% <0.00%> (ø)
src/kakarot/execution_context.cairo 94.98% <94.44%> (-0.21%) ⬇️
...karot/instructions/environmental_information.cairo 100.00% <100.00%> (ø)
src/kakarot/instructions/system_operations.cairo 96.05% <100.00%> (ø)
src/kakarot/library.cairo 92.45% <100.00%> (+0.21%) ⬆️
src/utils/utils.cairo 90.10% <100.00%> (+0.37%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@ClementWalter ClementWalter left a comment

Choose a reason for hiding this comment

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

Looks good to me

ClementWalter
ClementWalter previously approved these changes Dec 16, 2022
let calldata_len = self.call_context.calldata_len;
let count = Helpers.count_nonzeroes(nonzeroes=0, idx=0, arr_len=calldata_len, arr=calldata);
let zeroes = calldata_len - count.nonzeroes;
let calldata_cost = zeroes * 4 + count.nonzeroes * 16;
Copy link
Member

Choose a reason for hiding this comment

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

You could also factorize like

Cost = 4*len + 12*nonzeroes

@jobez jobez marked this pull request as ready for review December 16, 2022 10:45
@ClementWalter ClementWalter merged commit 2395306 into kkrt-labs:main Dec 19, 2022
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: implement 0x3a - GASPRICE
3 participants