Awesome Open Source
Awesome Open Source

Solidity Security Design Patterns

Code and slides of ICT Risk Assessment 2018/2019 seminar.

NEW! Now compatible with Solidity 0.5.1!

Design patterns are a commonly used technique to encode design guide-lines or best practices. They express an abstract or conceptual solution to a concrete, complex, and reoccurring problem.

Problem When a contract calls another contract, it hands over control to that other contract. The called contract can then, in turn, re-enter the contract by which it was called and try to manipulate its state or hijack the control flow through malicious code.
Solution Follow a recommended functional code order, in which calls to external contracts are always the last step, to reduce the attack surface of a contract being manipulated by its own externally called contracts.
Source security/ChecksEffectsInteraction.sol
Problem Since a deployed contract is executed autonomously on the Ethereum network, there is no option to halt its execution in case of a major bug or security issue.
Solution Incorporate an emergency stop functionality into the contract that can be triggered by an authenticated party to disable sensitive functions.
Source security/EmergencyStop.sol
Problem The simultaneous execution of sensitive tasks by a huge number of parties can bring about the downfall of a contract.
Solution Prolong the completion of sensitive tasks to take steps against fraudulent activities.
Source security/SpeedBump.sol
Problem A request rush on a certain task is not desired and can hinder the correct operational performance of a contract.
Solution Regulate how often a task can be executed within a period of time.
Source security/RateLimit.sol
Problem Re-entrancy attacks can manipulate the state of a contract and hijack the control flow.
Solution Utilize a mutex to hinder an external call from re-entering its caller function again.
Source security/Mutex.sol
Problem There is always a risk that a contract gets compromised due to bugs in the code or yet unknown security issues within the contract platform.
Solution Limit the maximum amount of funds at risk held within a contract.
Source security/LimitBalance.sol


Smart Contracts: Security Patterns in the Ethereum Ecosystem and Solidity

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Security (8,726
Blockchain (8,549
Ethereum (6,975
Solidity (6,365
Smart Contracts (2,246
Patterns (844
Related Projects