Smart Contract Security Part 2: Access Control, tx.origin, Randomness, Oracles, Front-Running and Upgrade Risks

Blockchain Developer 55 min min read Updated: Nov 17, 2026 Intermediate
Smart Contract Security Part 2: Access Control, tx.origin, Randomness, Oracles, Front-Running and Upgrade Risks
Intermediate Topic 2 of 3

Quick Reference Table

ProblemWhat happensPrevention
Missing access controlAnyone can call an admin function such as mint or withdrawonlyOwner, roles, and test who can call what
tx.origin for authA malicious contract tricks you into calling it, and tx.origin is still youUse msg.sender
Weak randomnessblock.timestamp or block data can be predicted or influencedUse a verifiable randomness service
Oracle manipulationAn attacker moves a thin market price used by your contractUse time-weighted or multi-source price feeds
Front-running (MEV)Bots see your pending transaction and jump aheadSlippage limits, commit-reveal, private transaction routes
Unchecked external callsA failed call is ignored and logic continuesAlways check the result
Denial of serviceOne bad address or huge loop blocks everyonePull payments, avoid unbounded loops
Integer problemsSolidity 0.8+ reverts on overflow, but casts and unchecked blocks can still wrapAvoid unchecked unless proven safe, check casts
Insecure upgradesAdmin key or bad proxy setup lets someone replace the codeMultisig, timelock, tested upgrade tools

Missing Access Control Example

solidity // BAD: anyone can take the money function withdrawAll() external { payable(msg.sender).transfer(address(this).balance); } // GOOD function withdrawAll() external onlyOwner { payable(owner).transfer(address(this).balance); }

tx.origin Phishing

solidity // BAD function sendTo(address payable to, uint256 amount) external { require(tx.origin == owner); // can be tricked to.transfer(amount); } // GOOD function sendTo(address payable to, uint256 amount) external { require(msg.sender == owner); to.transfer(amount); }

Pull Over Push

Instead of sending money to many people in one loop, let each person withdraw their own share. One failing receiver cannot block the others.

Randomness

Everything on a blockchain is public and deterministic, so true randomness is hard. Use a verifiable random function from an oracle network for lotteries and games.

Upgradeable Contracts

  • Proxy patterns let you change logic later, but they add complexity and trust
  • Users must trust whoever controls the upgrade key
  • Use multisig plus timelock and publish the upgrade policy

Practice

  1. Review your PiggyBank: who can call each function?
  2. Why is msg.sender safer than tx.origin?
  3. Why is block.timestamp a poor random number?

Conclusion

Most losses come from simple mistakes: missing permission checks, trusting weak data, unsafe calls and risky upgrades. Review every function for who can call it and what it trusts.

Quick Summary: table; access control; tx.origin; pull payments; randomness; upgrades.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators