-
Notifications
You must be signed in to change notification settings - Fork 27
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: support reverts of inner calls #381
Conversation
52515d9
to
1c3275a
Compare
a09e992
to
6a36705
Compare
697a5f0
to
a362689
Compare
a362689
to
d56c432
Compare
This is not mandatory, but I felt it would be nicer to do it here than on every storage access. Code quote: let orig_values = std::mem::take(
&mut context
.revert_infos
.0
.last_mut()
.expect("Missing contract revert info.")
.orig_values,
); |
d56c432
to
5c1b557
Compare
I have no idea why we save 7 steps here :( Code quote: 164, |
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.
Reviewable status: 0 of 8 files reviewed, 5 unresolved discussions (waiting on @ilyalesokhin-starkware)
crates/blockifier/feature_contracts/cairo1/test_contract.cairo
line 80 at r3 (raw file):
contract_address: ContractAddress, entry_point_selector: felt252, calldata: Array::<felt252>
Don't we have syntactic sugar for calling contracts in Cairo1?
Code quote:
entry_point_selector: felt252,
calldata: Array::<felt252>
crates/blockifier/feature_contracts/cairo1/test_contract.cairo
line 94 at r3 (raw file):
}, }; assert(self.my_storage_var.read() == 0, 'values should not change.');
Suggestion:
};
// TODO(Yoni, 1/12/2024): test replace class once get_class_hash_at syscall is supported.
assert(self.my_storage_var.read() == 0, 'values should not change.');
crates/blockifier/src/execution/entry_point.rs
line 50 at r3 (raw file):
pub original_class_hash: ClassHash, /// The original storage values. pub orig_values: HashMap<StorageKey, Felt>,
Suggestion:
pub original_class_hash: ClassHash,
/// The original storage values.
pub original_values: HashMap<StorageKey, Felt>,
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 271 at r2 (raw file):
Previously, ilyalesokhin-starkware wrote…
This is not mandatory, but I felt it would be nicer to do it here than on every storage access.
Is it more efficient?
crates/blockifier/src/transaction/transactions_test.rs
line 1896 at r3 (raw file):
Previously, ilyalesokhin-starkware wrote…
I have no idea why we save 7 steps here :(
You compiled with 2.8.0 (the test contract was compiled with 2.7.0)
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.
Very cool. Tiny issue is with concurrency - the set of writes might contain values that were not written by the tx.
Should be okay since there is a read before every write.
cc @noaov1 - is it safe to save the diff instead of the writes here and here?
Reviewable status: 0 of 8 files reviewed, 5 unresolved discussions (waiting on @ilyalesokhin-starkware)
Previously, Yoni-Starkware (Yoni) wrote…
yes |
abd25cc
to
beffa75
Compare
@dorimedini-starkware, does the following make sense? Without it, the unwrap_err() here:
fails. Code quote: // If the execution of the outer call failed, revert the transction. |
Previously, Yoni-Starkware (Yoni) wrote…
yes, but then you can't pass the selector in the calldata. |
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.
Reviewable status: 0 of 9 files reviewed, 5 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/transaction/transactions_test.rs
line 1896 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
You compiled with 2.8.0 (the test contract was compiled with 2.7.0)
fixed.
"the set of writes might contain values that were not written by the tx." can you elaborate? what writes? |
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.
Reviewable status: 0 of 9 files reviewed, 5 unresolved discussions (waiting on @ilyalesokhin-starkware)
crates/blockifier/feature_contracts/cairo1/test_contract.cairo
line 80 at r3 (raw file):
Previously, ilyalesokhin-starkware wrote…
yes, but then you can't pass the selector in the calldata.
Why do you need it? why not calling test_revert_helper
?
Previously, Yoni-Starkware (Yoni) wrote…
I need to define a contract ABI for that. not sure it is worth the hustle, we don't do it in other tests. |
beffa75
to
98f0334
Compare
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.
Reviewed 1 of 4 files at r4, 1 of 5 files at r5.
Reviewable status: 2 of 11 files reviewed, all discussions resolved
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.
Reviewable status: 2 of 11 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @Yoni-Starkware)
crates/blockifier/src/transaction/transactions.rs
line 85 at r4 (raw file):
Previously, ilyalesokhin-starkware wrote…
@dorimedini-starkware, does the following make sense?
Without it, the unwrap_err() here:
let error = account_tx.execute(state, block_context, true, true).unwrap_err();
fails.
when txs revert (with your new feature), we want to return an Err
variant in the result of account_tx.execute
, right @Yoni-Starkware ?
if this is the case, then yes, this seems to make sense to me
Previously, dorimedini-starkware wrote…
Note that this is also temporary, in the future we would want to include prove reverted transactions and not use trusted reverts like we do today. |
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.
Reviewable status: 8 of 16 files reviewed, 10 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 855 at r10 (raw file):
if failed { raw_retdata .push(Felt::from_hex(ENTRYPOINT_FAILED_ERROR).map_err(SyscallExecutionError::from)?);
Need to do this in the OS as well, right?
Code quote:
.push(Felt::from_hex(ENTRYPOINT_FAILED_ERROR)
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.
Reviewable status: 8 of 16 files reviewed, 11 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)
crates/blockifier/feature_contracts/cairo1/test_contract.cairo
line 101 at r10 (raw file):
#[external(v0)] fn test_revert_helper(ref self: ContractState) { self.my_storage_var.write(17);
Can you add message + event + replace_class/deploy here before the panic?
Code quote:
#[external(v0)]
fn test_revert_helper(ref self: ContractState) {
self.my_storage_var.write(17);
I think most of those are returned by the OS. Code quote: Error codes returned by Cairo 1.0 code. |
Previously, Yoni-Starkware (Yoni) wrote…
yes |
Previously, ilyalesokhin-starkware wrote…
reverted |
6cbfaa7
to
37c9ae5
Compare
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.
Reviewed 2 of 8 files at r11, all commit messages.
Reviewable status: 6 of 17 files reviewed, 12 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)
crates/blockifier/src/execution/call_info.rs
line 206 at r11 (raw file):
if call_info.execution.failed { continue; }
You have this, and this...
it's risky. I'll try to improve this in a preliminary PR
Code quote:
for call_info in self.iter() {
if call_info.execution.failed {
continue;
}
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.
Reviewable status: 6 of 17 files reviewed, 12 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)
crates/blockifier/src/execution/call_info.rs
line 206 at r11 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
You have this, and this...
it's risky. I'll try to improve this in a preliminary PR
Oh, you cleared them. Great
So remove this skip - a reverted entrypoint should be considered here - we load its class and storage in the OS
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.
Reviewable status: 6 of 17 files reviewed, 8 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 212 at r10 (raw file):
// "ENTRYPOINT_FAILED"; pub const ENTRYPOINT_FAILED_ERROR: &str = "0x000000000000000000000000000000454e545259504f494e545f4641494c4544";
Done.
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 851 at r10 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
We need to handle events and messages. Safer to remove them. Otherwise we need to change
summarize
here and python's equivalent
Done.
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 860 at r10 (raw file):
let retdata_segment = create_retdata_segment(vm, syscall_handler, &raw_retdata)?; Ok(retdata_segment)
Done.
crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs
line 41 at r10 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Isn't it enough?
Done.
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.
Reviewable status: 6 of 17 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 848 at r11 (raw file):
// Delete events and l2_to_l1_messages from the reverted call. let execution = &mut syscall_handler.inner_calls.last_mut().unwrap().execution;
Oh basa. What about inner calls?
I'll ask @ArielElp
Code quote:
// Delete events and l2_to_l1_messages from the reverted call.
let execution = &mut syscall_handler.inner_calls.last_mut().unwrap().execution;
37c9ae5
to
34c0526
Compare
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.
Reviewable status: 5 of 17 files reviewed, 2 unresolved discussions (waiting on @ArielElp, @dorimedini-starkware, and @Yoni-Starkware)
crates/blockifier/src/execution/syscalls/hint_processor.rs
line 848 at r11 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Oh basa. What about inner calls?
I'll ask @ArielElp
Done.
crates/blockifier/src/execution/call_info.rs
line 206 at r11 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Oh, you cleared them. Great
So remove this skip - a reverted entrypoint should be considered here - we load its class and storage in the OS
Done.
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.
Reviewed 2 of 13 files at r7, 3 of 8 files at r11, 6 of 6 files at r12, all commit messages.
Reviewable status: 16 of 17 files reviewed, all discussions resolved (waiting on @dorimedini-starkware)
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.
(Fix the OS with ENTRYPOINT_FAILED before merging)
Reviewable status: 16 of 17 files reviewed, all discussions resolved (waiting on @dorimedini-starkware)
350769b
to
4109980
Compare
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.
Reviewed 1 of 4 files at r4, 3 of 3 files at r13, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware)
crates/blockifier/src/execution/entry_point_execution.rs
line 108 at r13 (raw file):
)?; if call_info.execution.failed && !context.versioned_constants().enable_reverts {
Revert new line
Suggestion:
)?;
if call_info.execution.failed && !context.versioned_constants().enable_reverts {
4109980
to
591e086
Compare
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.
Reviewed 2 of 2 files at r14, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)
dcf6b17
to
bbebe80
Compare
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.
Reviewed 9 of 9 files at r15, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware)
crates/blockifier/src/execution/syscalls/syscall_tests/call_contract.rs
line 20 at r15 (raw file):
#[test] fn test_call_contract_that_panics() {
@noaov1 TODO: test also with native once integrated
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.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)
bbebe80
to
318ef2e
Compare
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.
Reviewed 1 of 4 files at r4, 2 of 13 files at r7, 1 of 10 files at r9, 2 of 8 files at r11, 2 of 6 files at r12, 1 of 3 files at r13, 7 of 9 files at r15, 2 of 2 files at r16, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)
This change is