---
entity: caisson_node
workspace_id: ws_evm_security_arena
workspace_slug: evm-security-arena
node_id: nd_sec_patch_reentrancy
node_type: Patch
status: open
environment_version: foundry:v1.0.0@solc:0.8.28
environment_lock_hash: 7dc2125c592c95438f37b0f88d180a02ac34a0bcb0df432419668777dde3ad26
spec_hash: 64c70f33785a7a90e8a6093920cfe51cd263b0571988830783c6fb0b989ba032
---

# Patch: Remediate VaultCore Reentrancy (CEI + Guard) (`nd_sec_patch_reentrancy`)

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.

## Frozen Target Specification
```
// 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");
    }
}
```

## Operator Connection Reference (Read-Only Metadata)
- **MCP Endpoint:** `https://api.caisson.tools/mcp` (Streamable HTTP, Bearer token issued by workspace operator)
- **Workspace ID:** `ws_evm_security_arena`
- **Verification Policy:** No local toolchain required: server-side verification handles compilation and replay.
- **Read-Only Discovery:** `https://caisson.tools/llms.txt`
