Incorrect _ Essential init() function is used in TaikoToken making snapshooter devoid of calling snapshot()
The TaikoToken contract initialised the inherited EssentialContract using the variant that sets only the owner and not the address manager. As a result, the snapshooter role could never be resolved, so any snapshooter calling snapshot() would revert and only the owner could take snapshots.
MrPotatoMagic Follow with Limbooo, imare and 1 other
Originally disclosed on Code4rena
Submitted by MrPotatoMagic, also found by Limbooo, imare, and t0x1c
https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/L1/TaikoToken.sol#L34 https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/L1/TaikoToken.sol#L52
The EssentialContract.sol contract is inherited by the TaikoToken contract. This essential contract contains two _Essentialinit() functions, one with an owner parameter only (see here) and the other with owner and address manager parameters (see here).
The issue with the current code is that it uses the _Essentialinit() function with the owner parameter only. This would cause the onlyFromOwnerOrNamed(“snapshooter”) modifier on the snapshot function to not be able to resolve the snapshooter role since the address manager contract was never set during initialization, thus causing a revert.
Due to this:
- Snapshooter role is denied from taking snapshots.
- Timely snapshots for certain periods could have failed by the snapshooter since they would have required the owner to jump in by the time the issue was realized.
- Correct/Intended functionality of the protocol is affected i.e. the snapshooter role assigned to an address cannot ever perform its tasks validly.
Proof of Concept
Here is the whole process:
- Snapshooter address calls the snapshot() function. The onlyFromOwnerOrNamed(“snapshooter”) modifier is encountered first.
File: TaikoToken.sol
57: function snapshot() public onlyFromOwnerOrNamed("snapshooter") {
58: _snapshot();
59: }
- In the second condition, the modifier calls the resolve() function with the “snapshooter” role as
_namein order to check if the caller (msg.sender) is indeed the address approved by the owner.
File: EssentialContract.sol
46: modifier onlyFromOwnerOrNamed(bytes32 _name) {
47: if (msg.sender != owner() && msg.sender != resolve(_name, true))
48: revert RESOLVER_DENIED();
49: _;
50: }
- The resolve() function is called which internally calls the function _resolve(). In the function _resolve(), the condition on Line 69 evaluates to true and we revert. This is because the addressManager address was never set during initialization using the _Essentialinit() function with the owner and address manager parameters. Due to this, the snapshooter address is denied from performing it’s allocated tasks.
File: AddressResolver.sol
64: function _resolve(
65: uint64 _chainId,
66: bytes32 _name,
67: bool _allowZeroAddress
68: ) private view returns (address payable addr_) {
69: if (addressManager == address(0)) revert RESOLVER_INVALID_MANAGER();
70:
71: addr_ = payable(
72: IAddressManager(addressManager).getAddress(_chainId, _name)
73: );
74:
75: if (!_allowZeroAddress && addr_ == address(0)) {
76: revert RESOLVER_ZERO_ADDR(_chainId, _name);
77: }
78: }
Recommended Mitigation Steps
In the init() function, consider using the _Essentialinit() function with the owner and address manager parameters instead of the _Essentialinit() function with the owner parameter. This would allow the snapshooter address to proceed with taking snapshots as expected.
dantaik (Taiko) confirmed and commented:
This is a valid bug report. The bug is fixed by https://github.com/taikoxyz/taiko-mono/commit/c64ec193c95113a4c33692289e23e8d9fa864073
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
The snapshooter role could never take snapshots, so only the owner could, and timely snapshots could be missed until the owner stepped in.
What the attacker needed
TaikoToken deployed with the owner-only initialiser; caller holds the snapshooter role
The fix
The token's init() should call the EssentialContract initialiser that takes both an owner and an address manager; the report says this was fixed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract can inherit setup code from a parent contract. Here the parent had two setup functions: one that records just an owner, and one that records an owner plus a helper contract used to look up named roles. The token used the first, so when it later tried to look up the 'snapshooter' role it had no helper contract to ask and the call failed.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.