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

[KGA-82] [KGA-80] fix: codehash commitment #1566

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Nov 4, 2024

Fixes the codehash assigned to an account upon deployment as per https://github.com/code-423n4/2024-09-kakarot-findings/issues/10

  • In any case, the codehash of an account is keccak(code_bytes)
  • IF that account has no code, nonce nor balance, then extcodehash opcode returns 0.

As such, upon deploying the starknet contract corresponding to an account, we should always set the codehash to self.code_hash


This change is Reviewable

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 63.4%. Comparing base (5c96bb7) to head (cdaddf4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cairo_zero/backend/starknet.cairo 0.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1566   +/-   ##
=====================================
  Coverage   63.4%   63.4%           
=====================================
  Files         44      44           
  Lines       8349    8350    +1     
=====================================
+ Hits        5298    5300    +2     
+ Misses      3051    3050    -1     

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

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.

remove the set_code_hash call in if (self.created != FALSE) { then

@ClementWalter ClementWalter changed the title fix: codehash commitment [KGA-82] fix: codehash commitment Nov 4, 2024
Copy link

@ClementWalter ClementWalter changed the title [KGA-82] fix: codehash commitment [KGA-82] [KGA-80] fix: codehash commitment Nov 4, 2024
Copy link

@enitrat
Copy link
Collaborator Author

enitrat commented Nov 5, 2024

remove the set_code_hash call in if (self.created != FALSE) { then

I think you should always set the codehash when writing the bytecode. Perhaps there are instances where the starknet contract is already deployed and the code is re-written: re-deployed selfdestructed contracts.

@ClementWalter ClementWalter merged commit d5932d4 into main Nov 5, 2024
16 checks passed
@ClementWalter ClementWalter deleted the fix/codehash-commitment branch November 5, 2024 10:44
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.

2 participants