Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Copy link
Member

Choose a reason for hiding this comment

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

please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback

I agree that saturating_sub may mask incorrect gas accounting.
Would you prefer:

  • an explicit fork-check (Cancun vs Prague), or
  • guarding the subtraction with a conditional + debug assertion, or
  • returning early when gas < stipend inside pauseGasMetering?

Happy to rework this to preserve gas semantics while avoiding the panic.

Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ jobs:
toolchain: nightly
components: rustfmt
- run: cargo fmt --all --check
env:
RUSTC_WRAPPER: ""

forge-fmt:
runs-on: depot-ubuntu-latest
Expand All @@ -126,6 +128,8 @@ jobs:
- name: forge fmt
shell: bash
run: ./.github/scripts/format.sh --check
env:
RUSTC_WRAPPER: ""

crate-checks:
runs-on: depot-ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions crates/forge/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ impl TestResult {
reason: Option<String>,
raw_call_result: RawCallResult,
) {
self.kind =
TestKind::Unit { gas: raw_call_result.gas_used.wrapping_sub(raw_call_result.stipend) };
self.kind = TestKind::Unit {
gas: raw_call_result.gas_used.saturating_sub(raw_call_result.stipend),
};

extend!(self, raw_call_result, TraceKind::Execution);

Expand Down
30 changes: 30 additions & 0 deletions crates/forge/tests/cli/test_cmd/repros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,33 @@ ParserError: Source "Missing.sol" not found: File not found. Searched the follow

"#]]);
});

// https://github.com/foundry-rs/foundry/issues/12803
forgetest_init!(issue_12803, |prj, cmd| {
prj.add_test(
"Issue12803.t.sol",
r#"
import {Test} from "forge-std/Test.sol";

contract Issue12803Test is Test {
uint a;
function test_negativeGas() public {
vm.pauseGasMetering();
a = 100;
vm.resumeGasMetering();
delete a;
}
}
"#,
);

// We expect success, but check for underflow in gas reporting if it fails or prints weird gas
cmd.args(["test", "--evm-version=cancun"]).with_no_redact().assert_success().stdout_eq(str![[
r#"
...
Ran 1 test for test/Issue12803.t.sol:Issue12803Test
[PASS] test_negativeGas() (gas: 0)
...
"#
]]);
});
Loading