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): limit characters in cairo1 revert trace #1468

Conversation

dorimedini-starkware
Copy link
Collaborator

No description provided.

@lotem-starkware
Copy link
Contributor

This change is Reviewable

Copy link

codecov bot commented Oct 20, 2024

Codecov Report

Attention: Patch coverage is 89.55224% with 7 lines in your changes missing coverage. Please review.

Project coverage is 67.35%. Comparing base (e3165c4) to head (44f85b6).
Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/execution/stack_trace.rs 89.55% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1468       +/-   ##
===========================================
+ Coverage   40.10%   67.35%   +27.24%     
===========================================
  Files          26      103       +77     
  Lines        1895    13800    +11905     
  Branches     1895    13800    +11905     
===========================================
+ Hits          760     9295     +8535     
- Misses       1100     4104     +3004     
- Partials       35      401      +366     

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

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from 925040d to 99eea64 Compare October 20, 2024 09:37
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from c12f6ca to 2a6741b Compare October 20, 2024 09:37
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from 99eea64 to a94d27b Compare October 20, 2024 10:05
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 2a6741b to c126f53 Compare October 20, 2024 10:05
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from a94d27b to cb1ae57 Compare October 20, 2024 14:38
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from c126f53 to bfef88e Compare October 20, 2024 14:38
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from cb1ae57 to 276265c Compare October 20, 2024 15:02
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from bfef88e to 586d8e8 Compare October 20, 2024 15:02
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 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware)

@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from 276265c to da3be39 Compare October 21, 2024 07:03
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 586d8e8 to b1a7928 Compare October 21, 2024 07:03
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from da3be39 to a5bacb8 Compare October 21, 2024 08:49
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from b1a7928 to d050f37 Compare October 21, 2024 08:49
@dorimedini-starkware dorimedini-starkware force-pushed the 10-19-feat_blockifier_structured_cairo1_stack_trace branch from a5bacb8 to 9869960 Compare October 21, 2024 09:43
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from d050f37 to 368e075 Compare October 21, 2024 09:43
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 55a8ac2 to 63ce81a Compare October 22, 2024 16:14
@dorimedini-starkware dorimedini-starkware changed the base branch from graphite-base/1468 to main October 22, 2024 16:15
@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 63ce81a to 4aa867b Compare October 22, 2024 16:15
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 4aa867b to 054bd31 Compare October 23, 2024 11:06
Copy link

Artifacts upload triggered. View details here

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


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

            .chars()
            .take(TRACE_LENGTH_CAP)
            .collect::<String>()

I really don't like the fact that we need this logic to support an edge-case character limitation...
a frame is 264 characters, so 56 frames fit in the cap bound, not including the innermost retdata which should be short (unless there are use cases for many felts in the failure reason?)...
@ilyalesokhin-starkware if it's worth the extra code, do you have any ideas for improvements / helpful assumptions that will simplify the logic?

Code quote:

        // Total string length is limited by TRACE_LENGTH_CAP.

        // Prioritize the failure reason felts over the frames.
        // If the failure reason is too long to include a minimal frame trace, display only the
        // failure reason (truncated if necessary).
        let failure_reason = format_panic_data(&self.last_retdata.0);
        if failure_reason.len() >= TRACE_LENGTH_CAP - *MIN_CAIRO1_FRAMES_STACK_LENGTH {
            let output = if failure_reason.len() <= TRACE_LENGTH_CAP {
                failure_reason
            } else {
                failure_reason
                    .chars()
                    .take(TRACE_LENGTH_CAP - Self::TRUNCATION_SEPARATOR.len())
                    .collect::<String>()
                    + &format!("{}", Self::TRUNCATION_SEPARATOR)
            };
            return write!(f, "{}", output);
        }

        let untruncated_string = self
            .stack
            .iter()
            .map(|frame| frame.to_string())
            .chain([failure_reason.clone()])
            .join("\n");
        if untruncated_string.len() <= TRACE_LENGTH_CAP {
            return write!(f, "{}", untruncated_string);
        }

        // If the number of frames is too large, drop frames above the last frame (two frames are
        // not too many, as checked above with MIN_CAIRO1_FRAMES_STACK_LENGTH).
        let n_frames_to_drop = (untruncated_string.len() - TRACE_LENGTH_CAP
            + Self::TRUNCATION_SEPARATOR.len())
        .div_ceil(*MIN_CAIRO1_FRAME_LENGTH);

        // Expect the number of frames to be at least the number of frames to drop + 2. If not,
        // fall back to the failure reason.
        if self.stack.len() < n_frames_to_drop + 2 {
            return write!(f, "{}", failure_reason);
        }

        write!(
            f,
            "{}",
            self.stack[..self.stack.len() - n_frames_to_drop - 1]
            .iter()
            .map(|frame| frame.to_string())
            .chain([
                String::from(Self::TRUNCATION_SEPARATOR),
                self.stack
                    .last()
                    .expect("Stack has at least two frames at this point.")
                    .to_string(),
                failure_reason,
            ])
            .join("\n")
            // Truncate again as a failsafe.
            .chars()
            .take(TRACE_LENGTH_CAP)
            .collect::<String>()

@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 054bd31 to 9f232fc Compare October 23, 2024 12:49
Copy link

Artifacts upload triggered. View details here

@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 9f232fc to 77832c9 Compare October 23, 2024 15:38
Copy link

Artifacts upload triggered. View details here

@ilyalesokhin-starkware
Copy link
Contributor

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

 .expect("Stack has at least two frames at this point.")

I'd rather not use expect her.

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace.rs line 205 at r3 (raw file):

Previously, dorimedini-starkware wrote…

this is getting a bit ugly... both the stack and the failure reason can hit this limit, we may need to truncate them both.
when would we realistically have a trace longer than 15K chars?
anyway, modified, LMK what you think

I guess I didn't think it was going to be that complicated.

but if you already wrote it lets keep it.

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 1 of 1 files at r5.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware)

@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from 77832c9 to c0953ac Compare October 27, 2024 09:09
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: 0 of 2 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


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

Previously, ilyalesokhin-starkware wrote…
 .expect("Stack has at least two frames at this point.")

I'd rather not use expect her.

done

Copy link

Artifacts upload triggered. View details here

@ilyalesokhin-starkware
Copy link
Contributor

crates/blockifier/src/execution/stack_trace_test.rs line 851 at r6 (raw file):

    assert!(
        format!("{}", extract_trailing_cairo1_revert_trace(&next_call_info)).len()
            <= TRACE_LENGTH_CAP

Is putting the actual string here bad?

as it is written the length is the only thing being tested.

Code quote:

        format!("{}", extract_trailing_cairo1_revert_trace(&next_call_info)).len()
            <= TRACE_LENGTH_CAP

@dorimedini-starkware dorimedini-starkware force-pushed the 10-20-feat_blockifier_limit_characters_in_cairo1_revert_trace branch from c0953ac to 44f85b6 Compare October 27, 2024 20:13
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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @ilyalesokhin-starkware)


crates/blockifier/src/execution/stack_trace_test.rs line 851 at r6 (raw file):

Previously, ilyalesokhin-starkware wrote…

Is putting the actual string here bad?

as it is written the length is the only thing being tested.

Done.

Copy link

Artifacts upload triggered. View details here

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 r4, 2 of 2 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)

@dorimedini-starkware dorimedini-starkware merged commit a3b26a1 into main Oct 28, 2024
12 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 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