Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article uses Bunzz's new DeCipher feature to examine the NounsDAOExecutor contract in Nouns.
DeCipher is a service that uses AI to generate contract documentation automatically.
For details on how to use it, see the following article.
This article describes my own experience using DeCipher. If you notice any inaccuracies, please let me know in the comments.
Here is the DeCipher page used in this article.
Here is the Etherscan page.
Overview
The NounsDAOExecutor contract is a key component of Nouns DAO (a decentralized autonomous organization).
The contract executes governance decisions and manages the treasury of Nouns DAO. In other words, it is responsible for carrying out the DAO's decisions and managing its funds.
It is designed to process transactions securely and in a decentralized manner. The contract ensures that only authorized actions are executed and that DAO funds are managed transparently and securely.
The main responsibilities of the NounsDAOExecutor contract are as follows.
Transaction management
The contract oversees transaction execution. Transactions can only be executed when properly authorized and when specific conditions are met. For example, a transaction must first be queued and cannot be executed until a specified time has elapsed.
Event recording
The contract emits events for important actions, including queuing, executing, and canceling transactions and changing the administrator role. These events provide a transparent record of contract activity for monitoring and auditing.
Administrator role management
The contract manages the administrator role, including assigning a new administrator and allowing the pending administrator to accept the role. This controls who is authorized to perform specific actions.
Timelock management
The contract uses a timelock mechanism to prevent actions from being executed immediately. An action cannot be executed until the specified delay has elapsed, leaving time to review or cancel it.
From the perspective of Web3, blockchains, and dApps, NounsDAOExecutor is an important backend component of a decentralized application. It interacts with the Ethereum blockchain, enabling users to interact with the DAO in a decentralized and reliable manner. It also uses blockchain transparency and security to maintain a verifiable record of DAO activities.
Usage
The NounsDAOExecutor smart contract manages transactions within a decentralized autonomous organization (DAO). It provides functions for queuing, executing, and canceling transactions.
Purpose
The contract aims to manage DAO transactions securely and efficiently. It introduces a timelock mechanism so that transactions can be executed only after a specified delay. This gives DAO members time to consider transactions before execution and to cancel them if errors or other problems arise.
The following steps describe how to use the contract.
-
Deploy the contract Deploy NounsDAOExecutor to the Ethereum blockchain.
-
Configure the administrator After deploying the contract, configure the administrator. Call
setPendingAdminwith the new administrator's address, then have the new administrator callacceptAdminto accept the role. -
Queue a transaction Call
queueTransactionto add a transaction to the queue. Specify the target address, transaction value, function signature, data, and estimated execution time (eta). Theetamust be at least the current block timestamp plus the configured delay. -
Execute the transaction Once
etahas been reached, callexecuteTransactionusing the same parameters. The transaction must be executed within the specified grace period; it becomes invalid after that period. -
Cancel the transaction To cancel a transaction, call
cancelTransactionusing the same parameters asqueueTransaction. Only the administrator can cancel transactions.
Use cases
-
Routine transaction management The NounsDAOExecutor contract is used to manage routine DAO transactions, including queuing, executing, and canceling them.
-
Emergency transaction cancellation In an emergency, the administrator can cancel a transaction before execution, for example if a malicious transaction has been queued or an incorrect operation has been requested.
-
Administrator role transfer The administrator role can be transferred to a new address. This is useful if the current administrator can no longer fulfill their duties.
Parameters
admin_
The initial administrator address of the contract. The administrator is authorized to execute, cancel, and queue transactions.
delay_
The delay, in seconds, before a queued transaction can be executed. This delay must not exceed the maximum delay.
delay_ specifies the time between queuing a transaction and executing it, measured in seconds.
The configured delay is subject to minimum and maximum bounds.
Minimum delay The shortest time between queuing and executing a transaction. It generally ensures that other members have time to review the transaction and cancel it if necessary before execution.
Maximum delay The upper bound on the configured delay between queuing and executing transactions. It is intended to keep execution timing manageable and support efficient operation.
Execution is subject to the time specified by delay_. After a transaction is queued, execution is deferred until the configured delay has elapsed. Other members can review the transaction and arrange for cancellation if necessary during this time.
By delaying transaction execution, delay_ supports transaction management and security.
Contract
NounsDAOExecutor
admin
admin
address public admin;Overview A variable that stores the current administrator's address.
Details It stores the contract's initial administrator address when initialized. The administrator is authorized to execute, cancel, and queue transactions.
pendingAdmin
pendingAdmin
address public pendingAdmin;Overview A variable identifying the address of the pending new administrator.
Details If a new administrator is pending, this variable stores that address. The new administrator can accept the pending role to become the actual administrator.
delay
delay
uint256 public delay;Overview A variable storing the delay between queuing a transaction and executing it.
Details
It stores the transaction execution delay. Once queued, a transaction cannot be executed until the time specified by delay has elapsed.
GRACE_PERIOD
GRACE_PERIOD
uint256 public constant GRACE_PERIOD = 14 days;Overview The grace period associated with a queued transaction.
Details
Transactions may be executed within this period, provided they have not been canceled. The variable is declared as a uint256 and set to 14 days. The days time unit here represents 14 days. A transaction can also be canceled during this period.
MINIMUM_DELAY
MINIMUM_DELAY
uint256 public constant MINIMUM_DELAY = 2 days;Overview A constant representing the minimum permitted execution delay.
Details
At least this amount of time must elapse before an uncanceled transaction can be executed. This uint256 constant is set to 2 days. The days time unit here represents two days. A transaction cannot be executed sooner.
MAXIMUM_DELAY
MAXIMUM_DELAY
uint256 public constant MAXIMUM_DELAY = 30 days;Overview A constant representing the maximum permitted execution delay.
Details
The maximum configured delay constrains how long execution can be deferred. The constant is declared as a uint256 and set to 30 days. The days time unit here represents 30 days. A delay beyond this bound requires additional conditions.
admin
admin
address public admin;Overview The address of the contract administrator.
Details This address has administrative privileges and can perform specified operations.
pendingAdmin
pendingAdmin
address public pendingAdmin;Overview A variable identifying the new administrator address awaiting confirmation.
Details This stores the proposed administrator address until the new administrator accepts the role.
delay
delay
uint256 public delay;Overview A variable representing the transaction execution delay.
Details Execution is delayed by the duration configured in this variable.
queuedTransactions
queuedTransactions
mapping(bytes32 => bool) public queuedTransactions;Overview A mapping used to track queued transactions.
Details This mapping stores a Boolean indicating whether a particular transaction is queued.
Parameters
key- The byte sequence used as the mapping key.
Returns
bool- Whether the transaction is queued.
setDelay
setDelay
function setDelay(uint256 delay_) public {
require(msg.sender == address(this), 'NounsDAOExecutor::setDelay: Call must come from NounsDAOExecutor.');
require(delay_ >= MINIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must exceed minimum delay.');
require(delay_ <= MAXIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must not exceed maximum delay.');
delay = delay_;
emit NewDelay(delay);
}Overview Sets the delay of NounsDAOExecutor.
Details
- Configures
delay_. - Checks that the message sender is NounsDAOExecutor itself.
- Checks that
delay_is at least the minimum delay. - Checks that
delay_does not exceed the maximum delay. - Updates the delay and emits the
NewDelayevent.
Parameters
delay_- The duration to set as the delay.
Returns None.
acceptAdmin
acceptAdmin
function acceptAdmin() public {
require(msg.sender == pendingAdmin, 'NounsDAOExecutor::acceptAdmin: Call must come from pendingAdmin.');
admin = msg.sender;
pendingAdmin = address(0);
emit NewAdmin(admin);
}Overview
Allows pendingAdmin to accept the administrator (admin) role.
Details
- Checks that the caller is
pendingAdmin. - Sets the caller as the new administrator (
admin) and clearspendingAdmin. - Emits the
NewAdminevent.
setPendingAdmin
setPendingAdmin
function setPendingAdmin(address pendingAdmin_) public {
require(
msg.sender == address(this),
'NounsDAOExecutor::setPendingAdmin: Call must come from NounsDAOExecutor.'
);
pendingAdmin = pendingAdmin_;
emit NewPendingAdmin(pendingAdmin);
}Overview
Sets pendingAdmin.
Details
- Checks that the message sender is NounsDAOExecutor itself.
- Sets
pendingAdminto the specified address. - Emits the
NewPendingAdminevent.
Parameters
pendingAdmin_- The address to set as
pendingAdmin.
- The address to set as
Returns None.
queueTransaction
queueTransaction
function queueTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public returns (bytes32) {
require(msg.sender == admin, 'NounsDAOExecutor::queueTransaction: Call must come from admin.');
require(
eta >= getBlockTimestamp() + delay,
'NounsDAOExecutor::queueTransaction: Estimated execution block must satisfy delay.'
);
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = true;
emit QueueTransaction(txHash, target, value, signature, data, eta);
return txHash;
}Overview Adds a transaction to the queue.
Details
- Checks that the message sender is the administrator (
admin). - Checks that the scheduled execution timestamp satisfies the delay requirement.
- Generates a hash from the transaction parameters and records it in the
queuedTransactionsmapping. - Emits the
QueueTransactionevent.
Parameters
target- The target address of the transaction.
value- The amount of funds to transfer in the transaction.
signature- The function signature.
data- Transaction data.
eta- The timestamp at which execution is scheduled.
Returns
txHash- The hash of the queued transaction.
cancelTransaction
cancelTransaction
function cancelTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public {
require(msg.sender == admin, 'NounsDAOExecutor::cancelTransaction: Call must come from admin.');
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = false;
emit CancelTransaction(txHash, target, value, signature, data, eta);
}Overview Cancels a queued transaction.
Details
- Checks that the message sender is the administrator (
admin). - Generates a hash from the transaction parameters and marks the transaction as canceled in the
queuedTransactionsmapping. - Emits the
CancelTransactionevent.
Parameters
target- The target address of the transaction.
value- The amount of funds to transfer in the transaction.
signature- The function signature.
data- Transaction data.
eta- The timestamp at which execution is scheduled.
Returns None.
executeTransaction
executeTransaction
function executeTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public returns (bytes memory) {
require(msg.sender == admin, 'NounsDAOExecutor::executeTransaction: Call must come from admin.');
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
require(queuedTransactions[txHash], "NounsDAOExecutor::executeTransaction: Transaction hasn't been queued.");
require(
getBlockTimestamp() >= eta,
"NounsDAOExecutor::executeTransaction: Transaction hasn't surpassed time lock."
);
require(
getBlockTimestamp() <= eta + GRACE_PERIOD,
'NounsDAOExecutor::executeTransaction: Transaction is stale.'
);
queuedTransactions[txHash] = false;
bytes memory callData;
if (bytes(signature).length == 0) {
callData = data;
} else {
callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
}
// solium-disable-next-line security/no-call-value
(bool success, bytes memory returnData) = target.call{ value: value }(callData);
require(success, 'NounsDAOExecutor::executeTransaction: Transaction execution reverted.');
emit ExecuteTransaction(txHash, target, value, signature, data, eta);
return returnData;
}Overview Executes a queued transaction.
Details
- Checks that the message sender is the administrator (
admin). - Generates a hash from the transaction parameters and checks that the transaction is queued in the
queuedTransactionsmapping. - Checks the transaction's timelock.
- Checks that execution is within the permitted time window.
- Removes the transaction from the queue.
- Constructs the transaction calldata and calls the target contract.
- Checks whether the transaction execution succeeded.
Parameters
target- The target address of the transaction.
value- The amount of funds to transfer in the transaction.
signature- The function signature.
data- Transaction data.
eta- The timestamp at which execution is scheduled.
Returns
returnData- Data returned by the transaction execution (
bytes).
- Data returned by the transaction execution (
getBlockTimestamp
getBlockTimestamp
function getBlockTimestamp() internal view returns (uint256) {
// solium-disable-next-line security/no-block-members
return block.timestamp;
}Overview Returns the current block timestamp.
Details
- Retrieves the current block timestamp using
block.timestamp.
Returns
- The current block timestamp.
Events
NewAdmin
NewAdmin
event NewAdmin(address indexed newAdmin);Overview Emitted when a new administrator is set.
Details Emitted when a new administrator address is set, with that address supplied as a parameter. The new administrator is authorized to execute, cancel, and queue transactions.
Parameters
newAdmin- The new administrator address.
NewPendingAdmin
NewPendingAdmin
event NewPendingAdmin(address indexed newPendingAdmin);Overview Emitted when a new pending administrator is set.
Details Emitted when a new administrator address is set as pending, with that address supplied as a parameter. The new administrator can accept the pending role to become the actual administrator.
Parameters
newPendingAdmin- The new administrator address.
NewDelay
NewDelay
event NewDelay(uint256 indexed newDelay);Overview Emitted when a new delay is set.
Details Emitted when a new delay is configured, with the delay supplied as a parameter. It indicates that the delay between queuing a transaction and executing it has changed.
Parameters
newDelay- The new delay in seconds.
CancelTransaction
CancelTransaction
event CancelTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);Overview Emitted when a transaction is canceled.
Parameters
txHash- The transaction hash.
target- The target address of the transaction.
value- The amount of funds transferred in the transaction.
signature- The transaction's function signature.
data- Transaction data.
eta- The scheduled execution time.
ExecuteTransaction
ExecuteTransaction
event ExecuteTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);Overview Emitted when a transaction is executed.
Parameters
txHash- The transaction hash.
target- The target address of the transaction.
value- The amount of funds transferred in the transaction.
signature- The transaction's function signature.
data- Transaction data.
eta- The scheduled execution time.
QueueTransaction
QueueTransaction
event QueueTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);Overview Emitted when a transaction is queued.
Parameters
txHash- The transaction hash.
target- The target address of the transaction.
value- The amount of funds transferred in the transaction.
signature- The transaction's function signature.
data- Transaction data.
eta- The scheduled execution time.
Code
NounsDAOExecutor.sol
// SPDX-License-Identifier: BSD-3-Clause
/// @title The Nouns DAO executor and treasury
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
// LICENSE
// NounsDAOExecutor.sol is a modified version of Compound Lab's Timelock.sol:
// https://github.com/compound-finance/compound-protocol/blob/20abad28055a2f91df48a90f8bb6009279a4cb35/contracts/Timelock.sol
//
// Timelock.sol source code Copyright 2020 Compound Labs, Inc. licensed under the BSD-3-Clause license.
// With modifications by Nounders DAO.
//
// Additional conditions of BSD-3-Clause can be found here: https://opensource.org/licenses/BSD-3-Clause
//
// MODIFICATIONS
// NounsDAOExecutor.sol modifies Timelock to use Solidity 0.8.x receive(), fallback(), and built-in over/underflow protection
// This contract acts as executor of Nouns DAO governance and its treasury, so it has been modified to accept ETH.
pragma solidity ^0.8.6;
contract NounsDAOExecutor {
event NewAdmin(address indexed newAdmin);
event NewPendingAdmin(address indexed newPendingAdmin);
event NewDelay(uint256 indexed newDelay);
event CancelTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);
event ExecuteTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);
event QueueTransaction(
bytes32 indexed txHash,
address indexed target,
uint256 value,
string signature,
bytes data,
uint256 eta
);
uint256 public constant GRACE_PERIOD = 14 days;
uint256 public constant MINIMUM_DELAY = 2 days;
uint256 public constant MAXIMUM_DELAY = 30 days;
address public admin;
address public pendingAdmin;
uint256 public delay;
mapping(bytes32 => bool) public queuedTransactions;
constructor(address admin_, uint256 delay_) {
require(delay_ >= MINIMUM_DELAY, 'NounsDAOExecutor::constructor: Delay must exceed minimum delay.');
require(delay_ <= MAXIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must not exceed maximum delay.');
admin = admin_;
delay = delay_;
}
function setDelay(uint256 delay_) public {
require(msg.sender == address(this), 'NounsDAOExecutor::setDelay: Call must come from NounsDAOExecutor.');
require(delay_ >= MINIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must exceed minimum delay.');
require(delay_ <= MAXIMUM_DELAY, 'NounsDAOExecutor::setDelay: Delay must not exceed maximum delay.');
delay = delay_;
emit NewDelay(delay);
}
function acceptAdmin() public {
require(msg.sender == pendingAdmin, 'NounsDAOExecutor::acceptAdmin: Call must come from pendingAdmin.');
admin = msg.sender;
pendingAdmin = address(0);
emit NewAdmin(admin);
}
function setPendingAdmin(address pendingAdmin_) public {
require(
msg.sender == address(this),
'NounsDAOExecutor::setPendingAdmin: Call must come from NounsDAOExecutor.'
);
pendingAdmin = pendingAdmin_;
emit NewPendingAdmin(pendingAdmin);
}
function queueTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public returns (bytes32) {
require(msg.sender == admin, 'NounsDAOExecutor::queueTransaction: Call must come from admin.');
require(
eta >= getBlockTimestamp() + delay,
'NounsDAOExecutor::queueTransaction: Estimated execution block must satisfy delay.'
);
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = true;
emit QueueTransaction(txHash, target, value, signature, data, eta);
return txHash;
}
function cancelTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public {
require(msg.sender == admin, 'NounsDAOExecutor::cancelTransaction: Call must come from admin.');
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
queuedTransactions[txHash] = false;
emit CancelTransaction(txHash, target, value, signature, data, eta);
}
function executeTransaction(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) public returns (bytes memory) {
require(msg.sender == admin, 'NounsDAOExecutor::executeTransaction: Call must come from admin.');
bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta));
require(queuedTransactions[txHash], "NounsDAOExecutor::executeTransaction: Transaction hasn't been queued.");
require(
getBlockTimestamp() >= eta,
"NounsDAOExecutor::executeTransaction: Transaction hasn't surpassed time lock."
);
require(
getBlockTimestamp() <= eta + GRACE_PERIOD,
'NounsDAOExecutor::executeTransaction: Transaction is stale.'
);
queuedTransactions[txHash] = false;
bytes memory callData;
if (bytes(signature).length == 0) {
callData = data;
} else {
callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data);
}
// solium-disable-next-line security/no-call-value
(bool success, bytes memory returnData) = target.call{ value: value }(callData);
require(success, 'NounsDAOExecutor::executeTransaction: Transaction execution reverted.');
emit ExecuteTransaction(txHash, target, value, signature, data, eta);
return returnData;
}
function getBlockTimestamp() internal view returns (uint256) {
// solium-disable-next-line security/no-block-members
return block.timestamp;
}
receive() external payable {}
fallback() external payable {}
}Conclusion
This article examined the NounsDAOExecutor contract in Nouns using Bunzz's new DeCipher feature. I plan to continue exploring specific NFTs and contracts in future articles.



