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(blockifier): add address and selector for intermediate cairo1 revert errors #1459

Conversation

dorimedini-starkware
Copy link
Collaborator

No description provided.

@lotem-starkware
Copy link
Contributor

This change is Reviewable

Copy link

codecov bot commented Oct 19, 2024

Codecov Report

Attention: Patch coverage is 95.16129% with 3 lines in your changes missing coverage. Please review.

Project coverage is 67.23%. Comparing base (b0cfe82) to head (251c7e1).
Report is 487 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/execution/stack_trace.rs 94.00% 1 Missing and 2 partials ⚠️

❗ There is a different number of reports uploaded between BASE (b0cfe82) and HEAD (251c7e1). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (b0cfe82) HEAD (251c7e1)
3 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1459      +/-   ##
==========================================
- Coverage   74.18%   67.23%   -6.96%     
==========================================
  Files         359      102     -257     
  Lines       36240    13680   -22560     
  Branches    36240    13680   -22560     
==========================================
- Hits        26886     9198   -17688     
+ Misses       7220     4081    -3139     
+ Partials     2134      401    -1733     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-test_blockifier_named_values_in_test branch from 3e385dd to 65fde15 Compare October 19, 2024 16:54
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from bf939d7 to 16e16d5 Compare October 19, 2024 16:54
Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 6 files at r1.
Reviewable status: 2 of 6 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


crates/blockifier/src/execution/stack_trace.rs line 157 at r1 (raw file):

}

pub fn extract_trailing_cairo1_revert_trace(root_callinfo: &CallInfo) -> String {

call/call_info

Suggestion:

(root_call: &CallInfo)

crates/blockifier/src/execution/stack_trace.rs line 159 at r1 (raw file):

pub fn extract_trailing_cairo1_revert_trace(root_callinfo: &CallInfo) -> String {
    root_callinfo
        .tail_iter()

Document why is it enough to iterate the tail

Code quote:

    root_callinfo
        .tail_iter()

crates/blockifier/src/execution/stack_trace.rs line 160 at r1 (raw file):

    root_callinfo
        .tail_iter()
        .map(|callinfo| {

call/call_info

Code quote:

|callinfo

crates/blockifier/src/execution/stack_trace.rs line 168 at r1 (raw file):

            )
        })
        .join("\n\n")

You should stop iterating when you see call_info.failed == 0.
Also, you should pop out ENTRYPOINT_FAILED in every iteration.
If anything goes wrong (not enough ENTRYPOINT_FAILED, too much ENTRYPOINT_FAILED)
fallback the the flat retdata string.

Please add a simple test to extract_trailing_cairo1_revert_trace

Code quote:

        .tail_iter()
        .map(|callinfo| {
            format!(
                "Error in contract (contract address: {:#064x}, selector: {:#064x}):\n{}",
                callinfo.call.storage_address.0.key(),
                callinfo.call.entry_point_selector.0,
                format_panic_data(&callinfo.execution.retdata.0)
            )
        })
        .join("\n\n")

crates/blockifier/src/execution/stack_trace_test.rs line 229 at r1 (raw file):

Error in contract (contract address: {test_contract_address_2_felt:#064x}, selector: \
         {inner_entry_point_selector_felt:#064x}):
0x6661696c ('fail').

I think that this is the desired output

Suggestion:

Error in contract (contract address: {account_address_felt:#064x}, selector: \
         {execute_selector_felt:#064x}):

Error in contract (contract address: {test_contract_address_felt:#064x}, selector: \
         {external_entry_point_selector_felt:#064x}):
         
Error in contract (contract address: {test_contract_address_2_felt:#064x}, selector: \
         {inner_entry_point_selector_felt:#064x}):
0x6661696c ('fail').

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-test_blockifier_named_values_in_test branch 2 times, most recently from 1ec23a9 to 9932c7b Compare October 20, 2024 07:21
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from 16e16d5 to 6fd50ef Compare October 20, 2024 07:21
@dorimedini-starkware dorimedini-starkware changed the base branch from 10-19-test_blockifier_named_values_in_test to graphite-base/1459 October 20, 2024 07:48
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from 6fd50ef to 9c095c5 Compare October 20, 2024 07:48
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/1459 to main October 20, 2024 07:48
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from 9c095c5 to c033bb8 Compare October 20, 2024 07:48
@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 159 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Document why is it enough to iterate the tail

Why aren't you looking at the ret_data?

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a 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 6 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


crates/blockifier/src/execution/stack_trace.rs line 159 at r1 (raw file):

Previously, ilyalesokhin-starkware wrote…

Why aren't you looking at the ret_data?

You're right, see my comment below.
I meant here - why is it enough to look at the rightmost call branch (given that the failure flag is on and the retdata is legit)

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from c033bb8 to d462d20 Compare October 20, 2024 09:22
Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a 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 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 159 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

You're right, see my comment below.
I meant here - why is it enough to look at the rightmost call branch (given that the failure flag is on and the retdata is legit)

better?


crates/blockifier/src/execution/stack_trace.rs line 168 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

You should stop iterating when you see call_info.failed == 0.
Also, you should pop out ENTRYPOINT_FAILED in every iteration.
If anything goes wrong (not enough ENTRYPOINT_FAILED, too much ENTRYPOINT_FAILED)
fallback the the flat retdata string.

Please add a simple test to extract_trailing_cairo1_revert_trace

Done.
Added negative tests only (top of stack), positive cases are covered by the other stack trace tests.
If you have a particular edge case in mind that I haven;t thought of PLMK


crates/blockifier/src/execution/stack_trace_test.rs line 229 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

I think that this is the desired output

Done.

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch 2 times, most recently from bb88184 to 06ddc79 Compare October 20, 2024 10:05
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from 68e71d9 to a0c104e Compare October 21, 2024 08:49
Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a 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 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware)


crates/blockifier/src/execution/stack_trace.rs line 176 at r4 (raw file):

Previously, ilyalesokhin-starkware wrote…

Maybe we should do this according to the retdata of the outermost call?

Hmmm, I think it should be equivalent. Do you have a (natural) scenario where the result is different?

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch 2 times, most recently from 36b4800 to 93a8b55 Compare October 21, 2024 10:44
Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r5, all commit messages.
Reviewable status: 4 of 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware)

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch 4 times, most recently from 4ff75dd to dcc2473 Compare October 21, 2024 19:20
@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 176 at r4 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Hmmm, I think it should be equivalent. Do you have a (natural) scenario where the result is different?

Code snippet:

let res = call_contract(...)
let _ =  call_contract(...)
res.unwrap_syscall(...)

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 202 at r6 (raw file):

            // Inner failure is either not unique, or does not exist (malformed retdata).
            _ => return fallback_value,
        };

Suggestion:

        let expected_inner_retdata = retdata[..retdata.len() - 1];
        let mut potential_inner_failures_iter: Vec<&CallInfo> = call
            .inner_calls
            .iter()
            .filter(|inner_call| {
                inner_call.execution.failed
                    && inner_call.execution.retdata.0 == expected_inner_retdata
            })
            .collect();
        call = potential_inner_failures_iter.next() {
            Some(unique_inner_failure) if potential_inner_failures_iter.next().is_none()  => unique_inner_failure,
            // Inner failure is either not unique, or does not exist (malformed retdata).
            _ => return fallback_value,
        };

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a 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 6 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 176 at r4 (raw file):

        // Even if the next inner call is also in failed state, assume a scenario where the current
        // call panicked after ignoring the error result of the inner call.
        if call.execution.retdata.0.last() != Some(&entrypoint_failed_felt) {

Done.


crates/blockifier/src/execution/stack_trace.rs line 202 at r6 (raw file):

            // Inner failure is either not unique, or does not exist (malformed retdata).
            _ => return fallback_value,
        };

Done.

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch 4 times, most recently from 50e14cd to 6494b11 Compare October 22, 2024 09:31
@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

    let mut error_calls: Vec<&CallInfo> = vec![];
    let mut call = root_call;
    let mut expected_retdata = call.execution.retdata.0.clone();

is this clone nessiary?

Code quote:

let mut expected_retdata = call.execution.retdata.0.clone();

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a 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 6 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, ilyalesokhin-starkware wrote…

is this clone nessiary?

I don't want to mutate the original call's retdata, I need a new copy
If I drop the clone won't calling pop mutate call.execution.retdata?

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 2 of 6 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, dorimedini-starkware wrote…

I don't want to mutate the original call's retdata, I need a new copy
If I drop the clone won't calling pop mutate call.execution.retdata?

you can use last instead of pop

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, ilyalesokhin-starkware wrote…

you can use last instead of pop

like in r6

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a 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 6 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, ilyalesokhin-starkware wrote…

like in r6

in r6 I had an addition expected_inner_retdata variable initialized once per iteration, with retdata[..X].as_vec(). Isn't this also a copy operation?
I think this way is better - I maintain the "current" expected retdata by popping once per loop, and only cloning data once before the loop starts

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, dorimedini-starkware wrote…

in r6 I had an addition expected_inner_retdata variable initialized once per iteration, with retdata[..X].as_vec(). Isn't this also a copy operation?
I think this way is better - I maintain the "current" expected retdata by popping once per loop, and only cloning data once before the loop starts

Yes, but the as_vec was unnecessary as well.

You can compare the relevant slices, there is no need to copy anything

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_add_address_and_selector_for_intermediate_cairo1_revert_errors branch from 6494b11 to 251c7e1 Compare October 22, 2024 11:51
Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a 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 6 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)


crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, ilyalesokhin-starkware wrote…

Yes, but the as_vec was unnecessary as well.

You can compare the relevant slices, there is no need to copy anything

ah, right
better?

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 2 files at r5, 1 of 2 files at r6.
Reviewable status: 4 of 6 files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 166 at r7 (raw file):

Previously, dorimedini-starkware wrote…

ah, right
better?

yes

Copy link
Collaborator Author

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r3, 1 of 1 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)

@dorimedini-starkware dorimedini-starkware merged commit 8ebeac1 into main Oct 22, 2024
12 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants