Skip to content

Conversation

PoulavBhowmick03
Copy link
Contributor

@PoulavBhowmick03 PoulavBhowmick03 commented Apr 23, 2025

Description

Related issue

Fixes #3149

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features
    • Added automatic warnings during every build if the Sierra file size or CASM bytecode size exceeds recommended limits, with clear colored messages.
  • Enhancements
    • Statistics for the world and its resources are now always collected during compilation, regardless of options selected.

@PoulavBhowmick03
Copy link
Contributor Author

@glihm is this the intended solution?

Copy link
Contributor

coderabbitai bot commented Apr 23, 2025

Walkthrough

Ohayo sensei! This change updates the build command in the Sozo CLI to always load world statistics and check contract size limits during every compilation, regardless of whether the --stats flag is used. The code now emits warnings to stderr if the Sierra file exceeds 4,089,446 bytes or if the CASM bytecode exceeds 81,920 felts. The statistics table is only displayed when the --stats option is enabled, but the limit checks and warnings are always performed.

Changes

Files/Paths Change Summary
bin/sozo/src/commands/build.rs Refactored to always load and check world statistics for Sierra and CASM size limits, emitting warnings unconditionally; stats table display remains conditional on the --stats flag.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Emit warning during compilation if Sierra file > 4MB or CASM bytecode > 81,920 felts (#3149)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
bin/sozo/src/commands/build.rs (2)

170-193: The warning messages look good, but found a typo in the error message

The implementation correctly checks Sierra file size and CASM bytecode size against network limits, emitting warnings to stderr when exceeded. This helps users identify potential deployment issues early.

However, there's a minor issue with the error message text:

-                    "{}: Sierra file size ({:.2}MB, {} bytes) exceeds network limit of 4,089,446 \
-                     bytes bytes - {}",
+                    "{}: Sierra file size ({:.2}MB, {} bytes) exceeds network limit of 4,089,446 \
+                     bytes - {}",

173-173: Standardize limit values using constants

The limit values are hardcoded in multiple places with an inconsistency between the check value (81,920) and the table coloring value (81,290). Consider defining these as constants at the module level to avoid duplication and ensure consistency.

// Add at module level
+ const MAX_SIERRA_SIZE_BYTES: usize = 4_089_446;
+ const MAX_CASM_FELTS: usize = 81_920;

// Then use these constants in both places
- if stat.sierra_file_size > 4_089_446 {
+ if stat.sierra_file_size > MAX_SIERRA_SIZE_BYTES {

- if stat.casm_bytecode_size > 81_920 {
+ if stat.casm_bytecode_size > MAX_CASM_FELTS {

// Also update line 278
- const MAX_CASM_FELTS: usize = 81_290;
+ const MAX_CASM_FELTS: usize = 81_920;

Also applies to: 185-185, 277-278

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daae54d and 5c1903f.

📒 Files selected for processing (1)
  • bin/sozo/src/commands/build.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (2)
bin/sozo/src/commands/build.rs (2)

158-168: Ohayo sensei! LGTM - Always collecting stats for limit checks

The code now unconditionally loads the World data and collects statistics for all resources, which is necessary for the limit checks. This changes the previous behavior where stats were only loaded when the --stats flag was provided.


195-195: LGTM - Conditional display of statistics table

The code now properly separates the limit checking (always done) from the statistics table display (only when requested). This gives users important warnings while keeping the output clean when detailed stats aren't needed.

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

I think this should be dynamic based on the network we're migrating the World to. These limits are only being enforced by Starknet Mainnet/Sepolia at the moment, and not on katana-based chains yet. So, ideally, we should first try to determine what chain we may be migrating to, using the rpc url specified in the dojo_*.toml, and show the warnings accordingly.

We should also be very clear about which chain the limits apply to.

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Thank you @PoulavBhowmick03 for the work there. Some remarks. :)

// Check limits and emit warnings for EVERY compilation
for stat in &stats {
// Sierra file size check (4,089,446 bytes)
if stat.sierra_file_size > 4_089_446 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we move those magic values to constants? They are used below in the code, they may be extracted from the from implementation and put at the top of this module (with a link to the sn doc that mentioned those limits).

// Sierra file size check (4,089,446 bytes)
if stat.sierra_file_size > 4_089_446 {
eprintln!(
"{}: Sierra file size ({:.2}MB, {} bytes) exceeds network limit of 4,089,446 \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rework a bit the text to make it more readable:

  1. We can remove warning word, and print in yellow is ok to note a warning.
  2. Wdyt about something like
    Resource <TAG> exceeds network Sierra file size (#bytes)
    Resource <TAG> exceeds network Casm byte code size (#felts)

@glihm
Copy link
Collaborator

glihm commented Apr 23, 2025

I think this should be dynamic based on the network we're migrating the World to. These limits are only being enforced by Starknet Mainnet/Sepolia at the moment, and not on katana-based chains yet. So, ideally, we should first try to determine what chain we may be migrating to, using the rpc url specified in the dojo_*.toml, and show the warnings accordingly.

We should also be very clear about which chain the limits apply to.

I do agree on the dynamism this should have. However at the build time, we may not be aware of the chain.

So we could move those changes into migrate instead of build, which could make more sense and the dynamism you described will be applied more easily. 👍

@kariy
Copy link
Member

kariy commented Apr 24, 2025

> I do agree on the dynamism this should have. However at the build time, we may not be aware of the chain.

So we could move those changes into migrate instead of build, which could make more sense and the dynamism you described will be applied more easily. 👍

Yes, agree on this. Makes more sense to show the warning at sozo migrate especially at the very start of the migration process. If the migration fails due to exceeding the limits, then the warnings would be more easily accessible and doesn't get lost in the terminal.

The built contracts are agnostic to the chain that it would be migrated to, so let's push this feature over to sozo migrate instead. cc @PoulavBhowmick03

@glihm
Copy link
Collaborator

glihm commented Apr 28, 2025

@PoulavBhowmick03 if you have any blocker or questions, don't hesitate to ask. 🫡

@PoulavBhowmick03
Copy link
Contributor Author

gm @glihm , i was actually at the hospital. getting it done by tonight

@glihm
Copy link
Collaborator

glihm commented Apr 30, 2025

gm @glihm , i was actually at the hospital. getting it done by tonight

Oh shoot, hopefully you're doing good man.. No pressure, when you have a chance.

@glihm
Copy link
Collaborator

glihm commented May 12, 2025

Any update @PoulavBhowmick03? Hopefully you're feeling better. 🙏

@glihm
Copy link
Collaborator

glihm commented May 30, 2025

@PoulavBhowmick03 I do hope you're doing better man, and don't hesitate to drop off to recover on your end. 🙏

@glihm glihm marked this pull request as draft July 14, 2025 23:21
@glihm
Copy link
Collaborator

glihm commented Sep 9, 2025

Will close this since we now rely on Scarb to build files. So it would be a different code, using the stats right after the build to evaluate if some contracts are too big. 👍

Hope you're doing better @PoulavBhowmick03 and things are going well.

@glihm glihm closed this Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add warning message about limits at compilation

3 participants