Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the Timelock pattern in blockchain?
The Timelock pattern is a security method that delays the execution of a transaction or contract change for a set time, allowing users to review and react before it happens.
Click to reveal answer
beginner
Why is the Timelock pattern important in smart contracts?
It prevents sudden changes or attacks by giving users time to notice and respond, increasing trust and safety in decentralized systems.
Click to reveal answer
intermediate
How does a Timelock contract typically work?
It stores a proposed action and a timestamp. The action can only be executed after the delay period passes, ensuring a waiting time before changes take effect.
Click to reveal answer
intermediate
What is a common use case for the Timelock pattern?
Governance changes in decentralized protocols, where proposals are delayed to allow community review and prevent rushed decisions.
Click to reveal answer
beginner
Name one risk if a Timelock pattern is not used in contract upgrades.
Without a Timelock, attackers or admins could make instant harmful changes, leaving no time for users to react or protect their assets.
Click to reveal answer
What does the Timelock pattern delay in blockchain?
AMining of new blocks
BExecution of transactions or contract changes
CUser wallet creation
DNetwork synchronization
✗ Incorrect
The Timelock pattern delays the execution of transactions or contract changes to provide a safety window.
Why is a delay important in the Timelock pattern?
ATo reduce gas fees
BTo speed up transactions
CTo allow users to review and react
DTo increase block size
✗ Incorrect
The delay gives users time to notice and respond to proposed changes.
Which of these is a typical use of the Timelock pattern?
ABlock validation
BInstant token transfers
CWallet password reset
DGovernance proposal execution
✗ Incorrect
Governance proposals often use Timelock to delay execution for community review.
What happens if a Timelock is not used for contract upgrades?
AChanges can happen instantly, risking security
BUpgrades become impossible
CUsers get free tokens
DNetwork speed increases
✗ Incorrect
Without Timelock, instant changes can be harmful and leave no reaction time.
How does a Timelock contract know when to execute an action?
AAfter a set delay time has passed
BImmediately after proposal
CWhen a user logs in
DWhen the network is busy
✗ Incorrect
The contract waits until the delay time expires before executing the action.
Explain the Timelock pattern and why it is used in blockchain smart contracts.
Think about how delaying changes helps protect users.
You got /4 concepts.
Describe a real-life scenario where the Timelock pattern improves safety in a decentralized system.
Consider how communities decide on important changes.
You got /4 concepts.
Practice
(1/5)
1.
What is the main purpose of the Timelock pattern in blockchain smart contracts?
easy
A. To delay certain actions until a specific time has passed
B. To speed up transaction processing
C. To encrypt user data
D. To reduce gas fees
Solution
Step 1: Understand the Timelock pattern concept
The Timelock pattern is designed to delay actions in smart contracts until a set time has passed.
Step 2: Identify the purpose of the delay
This delay helps protect users by preventing instant changes that could be harmful or unexpected.
Final Answer:
To delay certain actions until a specific time has passed -> Option A
Quick Check:
Timelock pattern = delay actions [OK]
Hint: Timelock means waiting before action happens [OK]
Common Mistakes:
Thinking it speeds up transactions
Confusing with encryption
Assuming it lowers gas fees
2.
Which of the following Solidity code snippets correctly enforces a timelock using block.timestamp?
function execute() public {
require(__________, "Too early to execute");
// action code
}
easy
A. block.timestamp >= unlockTime
B. block.timestamp < unlockTime
C. block.number >= unlockTime
D. block.difficulty > unlockTime
Solution
Step 1: Understand the condition for timelock
The action should only execute if the current time is equal or after the unlock time.
Step 2: Choose the correct comparison
Using block.timestamp >= unlockTime ensures the function runs only after the unlock time.
Final Answer:
block.timestamp >= unlockTime -> Option A
Quick Check:
Time check uses block.timestamp >= unlockTime [OK]
Hint: Use block.timestamp and >= for timelock checks [OK]
Common Mistakes:
Using < instead of >=
Using block.number instead of block.timestamp
Using unrelated block properties
3.
What will be the output of the following Solidity function call if block.timestamp is 1650000000 and unlockTime is 1650000100?
function canExecute() public view returns (bool) {
return block.timestamp >= unlockTime;
}
medium
A. true
B. Revert with error
C. Compilation error
D. false
Solution
Step 1: Compare block.timestamp and unlockTime values
Given block.timestamp = 1650000000 and unlockTime = 1650000100, block.timestamp is less than unlockTime.
Step 2: Evaluate the return statement
The expression block.timestamp >= unlockTime evaluates to false.
Final Answer:
false -> Option D
Quick Check:
1650000000 >= 1650000100 = false [OK]
Hint: Compare timestamps carefully for true/false output [OK]
Common Mistakes:
Assuming >= means true when timestamp is smaller
Confusing block.timestamp with block.number
Expecting errors instead of boolean
4.
Identify the error in this Solidity timelock function and choose the fix:
uint256 public unlockTime;
function execute() public {
require(block.timestamp > unlockTime, "Too early");
// perform action
}
medium
A. Use block.number instead of block.timestamp
B. Change block.timestamp > unlockTime to block.timestamp >= unlockTime
C. Remove the require statement
D. Change unlockTime to block.timestamp
Solution
Step 1: Analyze the require condition
The condition block.timestamp > unlockTime disallows execution exactly at unlockTime.
Step 2: Adjust condition to allow execution at unlockTime
Changing to block.timestamp >= unlockTime allows execution starting from unlockTime.
Final Answer:
Change block.timestamp > unlockTime to block.timestamp >= unlockTime -> Option B
Quick Check:
Use >= to include unlockTime moment [OK]
Hint: Use >= to allow execution at unlock time [OK]
Common Mistakes:
Using > excludes unlockTime moment
Removing require loses protection
Using block.number causes wrong timing
5.
You want to create a timelock contract that allows an admin to schedule a withdrawal only after 1 day from scheduling. Which approach correctly implements this?
contract Timelock {
address public admin;
uint256 public unlockTime;
constructor() {
admin = msg.sender;
}
function scheduleWithdrawal() public {
require(msg.sender == admin, "Not admin");
unlockTime = block.timestamp + 86400; // 1 day
}
function withdraw() public {
require(msg.sender == admin, "Not admin");
require(block.timestamp >= unlockTime, "Too early");
// withdrawal logic
}
}
hard
A. Admin cannot schedule withdrawal
B. Withdrawal can happen immediately after scheduling
C. Correctly enforces 1-day delay before withdrawal