Skip to content
Quantix Security Labs

The Honest View

Explain how the lending market can be made to value pool shares at an inflated price even though the pool itself is protected by a reentrancy guard.
AdvancedSolidity · EthereumRead-only reentrancy45–60 minutes

Briefing

A pool holds ETH and a token and issues shares. A separate lending market accepts pool shares as collateral and prices them with `sharePrice()`.

EthPool.solsolidity
// Quantix Security Research Network — training challenge.// Intentionally vulnerable. Written for education; do not deploy.// SPDX-License-Identifier: MITpragma solidity 0.8.24; contract EthPool {    uint256 public totalShares;    uint256 public reserveEth;    uint256 public reserveToken;    mapping(address => uint256) public shares;    bool private locked;     modifier nonReentrant() {        require(!locked, "reentrant");        locked = true;        _;        locked = false;    }     /// Value of one share in ETH terms (1e18 precision).    function sharePrice() external view returns (uint256) {        return ((reserveEth * 2) * 1e18) / totalShares; // simplified valuation    }     function removeLiquidity(uint256 amount) external nonReentrant {        uint256 ethOut = (reserveEth * amount) / totalShares;        uint256 tokenOut = (reserveToken * amount) / totalShares;         shares[msg.sender] -= amount;        totalShares -= amount;         (bool ok, ) = msg.sender.call{value: ethOut}("");        require(ok, "eth transfer failed");         reserveEth -= ethOut;        reserveToken -= tokenOut;        // token transfer omitted for brevity    }}
ShareLending.sol (excerpt)solidity
function collateralValue(address user) public view returns (uint256) {    return (pool.shares(user) * pool.sharePrice()) / 1e18;} function borrow(uint256 amount) external {    require(debt[msg.sender] + amount <= collateralValue(msg.sender) * 70 / 100, "insufficient collateral");    debt[msg.sender] += amount;    weth.transfer(msg.sender, amount);}

Hints

Reveal one at a time. Each moves a step closer to the answer.

  1. H1

    Hidden

  2. H2

    Hidden

  3. H3

    Hidden

Solution

Try writing your own explanation and fix before opening it.

References