SolidityIn

Technical Deep-Dive: Beyond Reentrancy: 5 Subtle Vulnerabilities Lurking in Your Solidity Code

November 5, 2026 · admin · Uncategorized


5 Subtle Vulnerabilities Lurking in Your Solidity Code

For many Web3 developers, the mention of “Smart Contract Security” immediately conjures images of the infamous DAO hack and the dreaded Reentrancy attack. While reentrancy remains a critical threat, the maturity of the Solidity compiler (especially post-v0.8.0) and the widespread use of ReentrancyGuard have made it easier to defend against.

However, as the complexity of DeFi protocols and NFT mechanics grows, a new class of subtle, logic-based vulnerabilities has emerged. These bugs don’t always result in a total drain of funds in a single transaction, but they can be just as devastating. Today, we dive into five subtle vulnerabilities you might be overlooking.

1. Arithmetic Precision Loss (The Order of Operations)

Solidity does not support floating-point numbers. While developers are aware of this, many fail to realize how the order of operations can lead to massive discrepancies in financial calculations.

The Vulnerability:

In integer math, division should always be the final step. Performing division before multiplication causes a loss of precision that can be exploited, especially in vault-based protocols.

// VULNERABLE
function calculateReward(uint amount) public view returns (uint) {
return amount / 100 * rewardRate; // If amount < 100, result is 0
}
// SECURE
function calculateReward(uint amount) public view returns (uint) {
return (amount * rewardRate) / 100;
}

In the vulnerable example, if amount is 99, 99 / 100 equals 0 in Solidity. Even if the reward rate is high, the user receives nothing. In large-scale yield farming, these “dust” amounts can accumulate or be manipulated to drain small portions of value over thousands of transactions.

2. Denial of Service (DoS) via Unexpected Revert

A smart contract can become “frozen” if it relies on an external call to succeed to complete its own state transition. This is particularly common in “Push vs. Pull” payment patterns.

The Scenario:

Imagine an auction contract that refunds the previous highest bidder when a new bid is placed.

// VULNERABLE
function bid() external payable {
require(msg.value > highestBid);
// Attempting to send funds back to the previous bidder
(bool success, ) = highestBidder.call{value: highestBid}("");
require(success, "Refund failed"); // If this fails, the whole bid fails
highestBidder = msg.sender;
highestBid = msg.value;
}

A malicious actor can create a contract that refuses to accept ETH (by lacking a receive() or fallback() function). Once they become the highest bidder, any subsequent bids will revert because the require(success) will fail, effectively ending the auction and locking the contract.

3. Front-Running: The Mempool Surveillance

Transaction Order Dependence (Front-running) occurs because transactions sit in the public mempool before being included in a block. Bots scan these transactions to find profitable opportunities.

The Subtle Twist:

It isn’t just about decentralized exchanges (DEXs). Consider a “Commit-Reveal” scheme where a user submits a solution to a puzzle. If the solution is sent in plain text, a bot can see the transaction, copy the solution, and set a higher gasPrice to ensure their transaction is processed first, stealing the reward.

Solution: Use cryptographic hashes. Require users to submit keccak256(address + solution + salt) first, and only allow the reveal after the commit is mined.

4. Delegatecall to Untrusted Callee

delegatecall is a powerful tool used in proxy patterns. It executes code from a target contract but uses the storage, balance, and address of the calling contract.

The Danger:

If your contract uses delegatecall on an address that can be modified or influenced by a user, you are essentially giving that user “root access” to your contract’s storage. An attacker can point the call to a malicious contract that overwrites the owner variable in Slot 0 of your storage.

// HIGHLY DANGEROUS
function executePlugin(address _plugin, bytes memory _data) external {
// An attacker can pass a plugin that overwrites the contract owner
(bool success, ) = _plugin.delegatecall(_data);
require(success);
}

5. Weak Randomness via Block Metadata

Many NFT mints or on-chain games require randomness. A common mistake is using block.timestamp, block.difficulty, or block.prevrandao as a source of entropy.

Why it fails:

Validators (miners) have a degree of control over these values. If a validator is also a participant in your game or NFT mint, they can choose to discard a block they produce if the “random” outcome isn’t in their favor. Furthermore, multiple transactions in the same block will generate the same “random” number.

The Fix: Always use a verifiable random function (VRF) like Chainlink VRF for high-stakes randomness.


Conclusion

As Solidity development moves into a more mature phase, the “obvious” bugs are becoming rarer. The real threats now lie in the nuances of logic, the intricacies of the EVM’s storage model, and the competitive nature of the public mempool. Always conduct professional audits and remember: Code is Law, but only if the law is written correctly.

Tags: , , ,