Skip to content

chore: update gas limit constant and configure linting rules#76

Merged
shuhuiluo merged 1 commit into
mainfrom
shuhui/gas
Sep 4, 2025
Merged

chore: update gas limit constant and configure linting rules#76
shuhuiluo merged 1 commit into
mainfrom
shuhui/gas

Conversation

@shuhuiluo

@shuhuiluo shuhuiluo commented Sep 4, 2025

Copy link
Copy Markdown
Contributor
  • Renamed and updated BLOCK_GAS_LIMIT to PER_TRANSACTION_GAS_LIMIT in line with EIP-7825.
  • Added granular linting configuration in foundry.toml, including severity levels and exclusions.

Summary by CodeRabbit

  • Refactor

    • Updated deployment gas checks to use a per-transaction limit (16,777,216) with clearer warning messages, aligning with the latest guidance for more accurate batch deployments.
  • Chores

    • Added lint configuration with severity levels (high, med, low, gas) and excluded rules for more targeted linting.
    • Bumped version to 0.6.3.

- Renamed and updated `BLOCK_GAS_LIMIT` to `PER_TRANSACTION_GAS_LIMIT` in line with EIP-7825.
- Added granular linting configuration in `foundry.toml`, including severity levels and exclusions.
@coderabbitai

coderabbitai Bot commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds lint configuration to foundry.toml, bumps package version to 0.6.3, and updates DeployFacet.s.sol to use a per-transaction gas limit (1 << 24 per EIP-7825) instead of a block gas limit during deployment batch checks and warnings.

Changes

Cohort / File(s) Summary
Lint config (Foundry)
foundry.toml
Added [lint] section with severity = ["high","med","low","gas"] and exclude_lints = ["asm-keccak256","erc20-unchecked-transfer","incorrect-shift"].
Package metadata
package.json
Version updated from 0.6.2 to 0.6.3.
Deployment gas gating
scripts/common/DeployFacet.s.sol
Renamed constant BLOCK_GAS_LIMITPER_TRANSACTION_GAS_LIMIT = 1 << 24 (16,777,216; EIP-7825). Updated batch gas check and warning messaging to use per-transaction limit.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant BD as BatchDeployer
  participant DF as DeployFacet
  participant EVM as Network/EVM

  Dev->>BD: Start deployment batch
  BD->>DF: estimateBatchGas(contracts)
  DF->>EVM: Simulate gas for batch
  EVM-->>DF: gasEstimate
  note over DF: Compare gasEstimate to PER_TRANSACTION_GAS_LIMIT (1<<24)

  alt gasEstimate <= per-transaction limit
    DF-->>BD: ok
    BD->>EVM: send deployment tx
    EVM-->>BD: receipt
  else gasEstimate > per-transaction limit
    DF-->>BD: warn("exceeds per-transaction limit: 16,777,216")
    BD->>Dev: surface warning / adjust batch
  end

  rect rgba(230, 245, 255, 0.5)
  note right of DF: Updated control: per-transaction limit replaces block-wide limit
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

Poem

I twitch my ears at version three,
New lints hop neatly, bug-free spree.
Gas checks trimmed to each tx’s bound,
1<<24—a tidy round.
With paws on keys, I sign and cheer,
Deploys now lighter—onward, dear! 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch shuhui/gas

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
foundry.toml (1)

24-27: Verify Foundry lint config support and scope exclusions
Run forge --version and forge config in your local environment to confirm that Foundry recognizes the [lint] section with severity and exclude_lints. Rather than globally excluding erc20-unchecked-transfer, use inline or file-level ignores (e.g. // forge-ignore-erc20-unchecked-transfer) to avoid hiding genuine issues.

scripts/common/DeployFacet.s.sol (3)

19-19: Make the limit self-documenting and linter-friendly.

Optional: use a decimal literal to avoid relying on the excluded incorrect-shift lint and document both forms.

-    uint256 internal constant PER_TRANSACTION_GAS_LIMIT = 1 << 24; // gas limit per EIP-7825
+    // 16,777,216 gas per EIP-7825 (1 << 24)
+    uint256 internal constant PER_TRANSACTION_GAS_LIMIT = 16_777_216;

101-111: Avoid stale hardcoded number and warn only on threshold crossing.

Precompute the per-add estimate, emit the warning once when crossing the threshold, and format the limit dynamically from the constant.

-        // estimate gas cost for this deployment
-        batchGasEstimate += estimateDeploymentGas(bytecode);
-
-        // check if adding this contract would exceed per-transaction gas limit
-        if (batchGasEstimate > PER_TRANSACTION_GAS_LIMIT) {
-            warn(
-                string.concat(
-                    "DeployFacet: Adding contract ",
-                    name,
-                    " may exceed per-transaction gas limit 16,777,216. Deploy current batch first."
-                )
-            );
-        }
+        // estimate gas cost for this deployment
+        uint256 est = estimateDeploymentGas(bytecode);
+        // warn once when crossing the limit to avoid log spam
+        if (batchGasEstimate <= PER_TRANSACTION_GAS_LIMIT && batchGasEstimate + est > PER_TRANSACTION_GAS_LIMIT) {
+            warn(
+                string.concat(
+                    "DeployFacet: Adding contract ",
+                    name,
+                    " would exceed per-transaction gas limit ",
+                    PER_TRANSACTION_GAS_LIMIT.toString(),
+                    ". Deploy current batch first."
+                )
+            );
+        }
+        batchGasEstimate += est;

18-24: Make PER_TRANSACTION_GAS_LIMIT chain-aware
Consider reading an optional environment variable (e.g. PER_TX_GAS_LIMIT) or applying a configurable safety margin (e.g. 95% of the current chain’s block gas limit) instead of the hardcoded 1<<24 to avoid OOG errors on networks with lower per-transaction ceilings.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bce6818 and 6f314c2.

📒 Files selected for processing (3)
  • foundry.toml (1 hunks)
  • package.json (1 hunks)
  • scripts/common/DeployFacet.s.sol (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Foundry project
🔇 Additional comments (1)
package.json (1)

3-3: Version bump looks good.

No issues spotted with the 0.6.3 increment.

@shuhuiluo shuhuiluo added this pull request to the merge queue Sep 4, 2025
Merged via the queue into main with commit d13a9cb Sep 4, 2025
2 checks passed
@shuhuiluo shuhuiluo deleted the shuhui/gas branch September 4, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants