-
Notifications
You must be signed in to change notification settings - Fork 177
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
Cheatcode for getting hash of the block #2648
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PedroRosalba, unfortunately, your solution isn't proper.
Please study other pr's that introduce cheatcode e.g. #2634 or many other you can find in our repo history.
Your solution should contain:
- cheatcode implementation
- entry in snfoundry_std
- e2e tests (on cairo side)
- documentation
Hints for development:
If your tests pass, please submit your PR as ready to review. |
hey, can you review for some feedback? unfortunately I could not test the code (my computer even with no other tasks running cannot run cargo test e2e). sorry for the inconvenience. looking forward to continue working on this. sorry again. |
Do I have to deploy the contracts manually or smth like that? in the tests of CheatBlockHashChecker, I am getting an error that it is unable to find the contract. |
I have another question, is it allowed to 'request' changes in core lib files? //I thought of creating an attribute block_hash in get_block_info using the // pub extern fn get_block_hash_syscall( // //Is this allowed? Modifiying the core lib for example this. |
failures: Hey, the only tests that I am getting errors are these, which are files that I havent modified (and I guess I should not, also). Do you have any ideas of why? |
Hey, mind reviewing for the feedback? Sorry for the inconvenience again. |
Hey, I don't understand the log of the errors. In scarb fmt, it says Scarb.lock can't be find. Do you know why? ---- cheatcodes::cheat_block_hash::cheat_block_hash_simple stdout ---- In this second error, it is unable to find the contract. As I have already asked, is it necessary to declare or deploy these contracts separately? |
Hi! I will take a look today! |
alright, now I ran the scarbfmt scripts, things should be working properly. looking forward to the feedback, thx. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good job so far! We are almost done.
- Add an entry to
CHANGELOG.md
- In this Unify Felt usage #2655 pr, we unified felts in the entire repo, that's why some of your tests are failing, please replace it
alright now I believe its pretty done |
Are your questions still blocking? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing, because you didn't add the entry into lib.cairo
-> crates/cheatnet/tests/contracts/src/lib.cairo
Please format the code before committing :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some tests failing, could you take a look at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at failing tests below. Seems there's a problem with some cairo code introduced as well as with rust.
I'm trying to figure out what is failing. Still didn't. Sorry for late response. |
I can't understand why only some of the tests from the file crates/forge/tests/integration/cheat_block_hash.rs are failing and not all of them. I can't see issues w the code |
Failure data: This is the output referent to the code #[test]
why is it outputting this random address? |
|
||
fn get_block_hash(self: @ContractState) -> felt252 { | ||
let block_info = get_block_info().unbox(); | ||
let block_hash = get_block_hash_syscall(block_info.block_number - 10).unwrap_syscall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PedroRosalba Is there a reason block_number - 10
is used here? I think that's what causing problems, you're not checking the block hash of this block but 10 blocks in the past.
I don't believe that is the issue. Took off this -10 and got this error
running 1 test successes: successes: failures: ---- integration::cheat_block_hash::cheat_block_hash_complex stdout ---- Collected 1 test(s) from test_package package Failure data: Tests: 0 passed, 1 failed, 0 skipped, 0 ignored, 0 filtered out failures: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 276 filtered out; finished in 39.45s error: test failed, to rerun pass
This -10 was being used in a similar context before I started working on this pull request, so I just followed this pattern. And as you can see I don't think thats the issue. |
@PedroRosalba Verified this in depth: current block - 10 in syscall is okay, it won't work with more recent ones according to docs https://docs.starknet.io/architecture-and-concepts/smart-contracts/system-calls-cairo1/#get_block_hash However, the code you wrote is changing the block execution info that is fetched by the block execution info syscall however you want to change the result of get_block_hash syscall. So this changes won't work You have to match this selector here starknet-foundry/crates/cheatnet/src/runtime_extensions/cheatable_starknet_runtime_extension.rs Line 46 in 95a2681
cheated_syscalls.rs that is handling it similarly to how other cheated syscalls work.
|
Sorry, I did not understand the issue. pub fn get_block_hash(
} this is the impl of the function get_block_hash. see it is calling the correct get_block_hash. furthemrore the implementations of the funciton get_block_hash that I created all utilize the get_block_hash_syscall, which is the function that u use with the -10; and not the block execution info, as you described. So I did not understand, can you explain in a lil more details? |
basically I need to create a get_block_hash_syscall function inside this cheated_syscalls.rs file? and then add the correspondent logic to the match selector? but why do I need to do that if my functions get_block_hash are all defined to call get_block_hash_syscall ? that is what I am not understanding very well |
Don't know if I got it: the thing is, to get the block hash, I need to get the block number, and for that, I need to access the function get_block_info, which is implemented via the block execution info syscall. What I got from what u said is that I need to define my function to get the block hash differently, without utilizing the block info execution syscall; instead use the get block hash syscall. but to use the block hash syscall I need to have the block number, which I get from the block info execution syscall, so I need to use it anyways. Where am I misunderstanding? |
@PedroRosalba You can still use the block execution info syscall in Cairo tests to get the block number first. The problem is that in your implementation, you are changing the block hash stored in execution info. However, to check the hash of the block, you need to call the That's why, even though you change the block hash in execution info, the For the result of the |
In the The We handle this syscall in |
HI @PedroRosalba any updates here? |
Closes #684
Introduced changes
Checklist
CHANGELOG.md