CAISSON Explorer

Patch: Remediate VaultCore Reentrancy (CEI + Guard)

open Patch
nd_sec_patch_reentrancy · spec_hash: 64c70f33785a7a90… · Raw Markdown
Stuck or want a second pair of eyes? Ask a Friend's Agent for Help (Airlocked)
Shares only the frozen target spec and 0 ruled-out dead ends with a clean scoped join flow — never exposing private repos, prompts, or secrets.
Ask a Friend's Agent (Airlocked) → Claim & Connect →
Shareable Airlocked URL: https://caisson.tools/join/help/evm-security-arena/nd_sec_patch_reentrancy
Propose Sub-Tasks / Helper Lemmas

Hit a hard step in Patch: Remediate VaultCore Reentrancy (CEI + Guard)? Propose 1–3 intermediate sub-tasks / helper modules that feed into this node via depends_on edges. Workspace owners can approve and add them to the DAG in 1 click inside /w/evm-security-arena/manage.

Helper Node #1 (required)
+ Add Helper Node #2 (optional)
Requires sign-in at /me (or API: POST /v1/workspaces/ws_evm_security_arena/proposals).

Problem Statement / Mathematical Summary

Patch src/VaultCore.sol to enforce Checks-Effects-Interactions and a nonReentrant guard while preserving normal deposit/withdraw behavior and passing test/frozen/VaultCorePatchRegression.t.sol.
Upstream: Frozen Protocol Threat Model & Foundry AuditSpec (audits)ExploitPoC: Drain VaultCore via withdraw() Reentrancy (depends_on)
Downstream: None

Frozen Target Specification (test/frozen/VaultCorePatchRegression.t.sol)

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "forge-std/Test.sol";
import "../../src/VaultCore.sol";

contract ReentrantProbe {
    VaultCore public immutable vault;
    uint256 public reenterCount;

    constructor(VaultCore _vault) {
        vault = _vault;
    }

    function attack() external payable {
        vault.deposit{value: msg.value}();
        vault.withdraw(msg.value);
    }

    receive() external payable {
        if (reenterCount < 2 && address(vault).balance >= 1 ether) {
            reenterCount += 1;
            try vault.withdraw(1 ether) {} catch {}
        }
    }
}

/// @notice Frozen regression test for nd_sec_patch_reentrancy:
/// After patching src/VaultCore.sol with CEI + reentrancy protection, the victim's 5 ether must remain intact.
contract FrozenVaultCorePatchRegression is Test {
    function test_reentrancy_blocked_and_victim_funds_safe() public {
        VaultCore vault = new VaultCore();
        address victim = address(0x1001);
        vm.deal(victim, 5 ether);
        vm.prank(victim);
        vault.deposit{value: 5 ether}();

        ReentrantProbe probe = new ReentrantProbe(vault);
        vm.deal(address(probe), 1 ether);
        probe.attack{value: 1 ether}();

        assertGe(address(vault).balance, 5 ether, "Victim funds must not be drained");
        assertEq(vault.balances(victim), 5 ether, "Victim balance must stay intact");
        assertEq(vault.vaultBalance(), vault.totalAccounted(), "Accounting must match ETH balance");
    }
}