Skip to content
Merged
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: 1 addition & 3 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use proptest::test_runner::{RngAlgorithm, TestRng, TestRunner};
use rand::Rng;
use revm::{
interpreter::{
opcode as op, CallInputs, CallOutcome, CallScheme, CallValue, CreateInputs, CreateOutcome,
opcode as op, CallInputs, CallOutcome, CallScheme, CreateInputs, CreateOutcome,
EOFCreateInputs, EOFCreateKind, Gas, InstructionResult, Interpreter, InterpreterAction,
InterpreterResult,
},
Expand Down Expand Up @@ -1047,8 +1047,6 @@ where {
if let CallScheme::DelegateCall | CallScheme::ExtDelegateCall = call.scheme {
call.target_address = prank.new_caller;
call.caller = prank.new_caller;
let acc = ecx.journaled_state.account(prank.new_caller);
call.value = CallValue::Apparent(acc.info.balance);
if let Some(new_origin) = prank.new_origin {
ecx.env.tx.caller = new_origin;
}
Expand Down
3 changes: 3 additions & 0 deletions crates/forge/tests/it/repros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,6 @@ test_repro!(9643);

// https://github.com/foundry-rs/foundry/issues/7238
test_repro!(7238);

// https://github.com/foundry-rs/foundry/issues/10302
test_repro!(10302);
53 changes: 53 additions & 0 deletions testdata/default/repros/Issue10302.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";

contract A {
function foo() public pure returns (bool) {
return true;
}
}

contract Issue10302Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testDelegateFails() external {
vm.createSelectFork("sepolia");

Choose a reason for hiding this comment

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

This might fail if this address ever have a zero balance. Maybe best to specify a fork number.

A a = new A();
vm.startPrank(0x0fe884546476dDd290eC46318785046ef68a0BA9, true);
(bool success,) = address(a).delegatecall(abi.encodeWithSelector(A.foo.selector));
vm.stopPrank();
require(success, "Delegate call should succeed");
}

function testDelegatePassesWhenBalanceSetToZero() external {
vm.createSelectFork("sepolia");
A a = new A();

Choose a reason for hiding this comment

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

This might fail if this address ever gets a balance.

vm.startPrank(0x0fe884546476dDd290eC46318785046ef68a0BA9, true);
vm.deal(0x0fe884546476dDd290eC46318785046ef68a0BA9, 0 ether);
(bool success,) = address(a).delegatecall(abi.encodeWithSelector(A.foo.selector));
vm.stopPrank();
require(success, "Delegate call should succeed");
}

function testDelegateCallSucceeds() external {
vm.createSelectFork("sepolia");
A a = new A();
vm.startPrank(0xd363339eE47775888Df411A163c586a8BdEA9dbf, true);
(bool success,) = address(a).delegatecall(abi.encodeWithSelector(A.foo.selector));
vm.stopPrank();
require(success, "Delegate call should succeed");
}

function testDelegateFailsWhenBalanceGtZero() external {
vm.createSelectFork("sepolia");
A a = new A();
vm.startPrank(0xd363339eE47775888Df411A163c586a8BdEA9dbf, true);
vm.deal(0xd363339eE47775888Df411A163c586a8BdEA9dbf, 1 ether);
(bool success,) = address(a).delegatecall(abi.encodeWithSelector(A.foo.selector));
vm.stopPrank();
require(success, "Delegate call should succeed");
}
}