Skip to content

Commit 56708cf

Browse files
authored
fix(forge): redact pk in signDelegation* traces (#10061)
1 parent 7e903eb commit 56708cf

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

crates/evm/traces/src/decoder/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,14 @@ impl CallTraceDecoder {
464464

465465
Some(decoded.iter().map(format_token).collect())
466466
}
467+
"signDelegation" | "signAndAttachDelegation" => {
468+
let mut decoded = func.abi_decode_input(&data[SELECTOR_LEN..], false).ok()?;
469+
// Redact private key and replace in trace for
470+
// signAndAttachDelegation(address implementation, uint256 privateKey)
471+
// signDelegation(address implementation, uint256 privateKey)
472+
decoded[1] = DynSolValue::String("<pk>".to_string());
473+
Some(decoded.iter().map(format_token).collect())
474+
}
467475
"parseJson" |
468476
"parseJsonUint" |
469477
"parseJsonUintArray" |

crates/forge/tests/cli/test_cmd.rs

+37
Original file line numberDiff line numberDiff line change
@@ -3279,3 +3279,40 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
32793279
32803280
"#]]);
32813281
});
3282+
3283+
// <https://github.com/foundry-rs/foundry/issues/10060>
3284+
forgetest_init!(should_redact_pk_in_sign_delegation, |prj, cmd| {
3285+
prj.add_test(
3286+
"Counter.t.sol",
3287+
r#"
3288+
import "forge-std/Test.sol";
3289+
contract CounterTest is Test {
3290+
function testCheckDelegation() external {
3291+
(address alice, uint256 key) = makeAddrAndKey("alice");
3292+
vm.signDelegation(address(0), key);
3293+
vm.signAndAttachDelegation(address(0), key);
3294+
}
3295+
}
3296+
"#,
3297+
)
3298+
.unwrap();
3299+
3300+
cmd.args(["test", "--mt", "testCheckDelegation", "-vvvv"]).assert_success().stdout_eq(str![[r#"
3301+
...
3302+
Ran 1 test for test/Counter.t.sol:CounterTest
3303+
[PASS] testCheckDelegation() ([GAS])
3304+
Traces:
3305+
[..] CounterTest::testCheckDelegation()
3306+
├─ [0] VM::addr(<pk>) [staticcall]
3307+
│ └─ ← [Return] alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6]
3308+
├─ [0] VM::label(alice: [0x328809Bc894f92807417D2dAD6b7C998c1aFdac6], "alice")
3309+
│ └─ ← [Return]
3310+
├─ [0] VM::signDelegation(0x0000000000000000000000000000000000000000, "<pk>")
3311+
│ └─ ← [Return] (0, 0x3d6ad67cc3dc94101a049f85f96937513a05485ae0f8b27545d25c4f71b12cf9, 0x3c0f2d62834f59d6ef0209e8a935f80a891a236eb18ac0e3700dd8f7ac8ae279, 0, 0x0000000000000000000000000000000000000000)
3312+
├─ [0] VM::signAndAttachDelegation(0x0000000000000000000000000000000000000000, "<pk>")
3313+
│ └─ ← [Return] (0, 0x3d6ad67cc3dc94101a049f85f96937513a05485ae0f8b27545d25c4f71b12cf9, 0x3c0f2d62834f59d6ef0209e8a935f80a891a236eb18ac0e3700dd8f7ac8ae279, 0, 0x0000000000000000000000000000000000000000)
3314+
└─ ← [Stop]
3315+
...
3316+
3317+
"#]]);
3318+
});

0 commit comments

Comments
 (0)