Crypto winter Developer guides
Developer practice

Review a missing access check in a Solidity contract

Reproduce an unauthorized fee update in a local EVM, add an owner check, and verify that the failed call leaves storage unchanged.

Prerequisites and commands

Install Foundry with Forge on PATH and enter the extracted solidity-access-review folder. The fixture pins Solidity 0.8.30. Forge may fetch the compiler on first use. No account, RPC URL, or Forge library is required.

Download the runnable source (ZIP)
Archive checksum (SHA-256)

218b4f52ed0d2fc03080a57d2a1730eb3283b401c05bb0b12151f4db8474df1c

forge test -vv

What the tests show

In FeeSettings.sol, the vulnerable setFeeBps function writes to storage without checking the caller. Caller in the test is a separate contract, so it reaches the target with a different msg.sender. The fixed contract assigns the deploying address as owner and checks it before the write.

function setFeeBps(uint256 nextFee) external {
        if (msg.sender != owner) revert Unauthorized(msg.sender);
        feeBps = nextFee;
    }
  • test_VulnerableAllowsNonOwner shows a caller changing the setting from 100 to 9000.
  • test_FixedRejectsNonOwnerAndPreservesState checks the exact Unauthorized(address) error and confirms the value stays at 100.
  • test_FixedAllowsOwner confirms the authorized caller can set the value to 250.

If your result differs

With the compiler cached, run forge test --offline -vv. Add -vvvv for call traces. If the owner path fails, trace msg.sender at the target and inspect who deployed it. Calling through the helper changes the caller seen by the target.

Scope and limits

The values are test fixtures in basis points. The exercise covers one setter, with no payments or public-network deployment. Real reviews also need to cover every privileged entry point, parameter bounds, and how ownership is assigned and transferred. The bundled tests establish the behavior of this fixture only.

Sources and further reading