Anyone can update the address of the Router in the DcntEth contract to any address they would like to set.
Submitted by NPCsCorp, also found by seraviz, dutra, 0xSimeon, EV_om, azanux, Aymen0909, 0xprinc, ZdravkoHr, 0x11singh99, CDSecurity, nuthan2x, GhK3Ndf, 0xAadi, Eeyore, ZanyBonzy (1, 2), DadeKuma, Matue, Timeless, Giorgio, slylandro_star, 0xdice91, Nikki, ke1caM, cu5t0mpeo, Greed, nobody2018, Tendency, Inference, al88nsk, DarkTower, th13vn, Soliditors, Timenov, wangxx2026, NentoR, ether_sky, peanuts, MrPotatoMagic, ravikiranweb3, mrudenko, Kaysoft, deth, 0xBugSlayer, nmirchev8, GeekyLumberjack, Aamir, adeolu, stealth, simplor, PUSH0, 0xabhay, darksnow, haxatron, m4ttm, 0xE1, boredpukar, abiih, 0xSmartContract, bareli, mgf15 (1, 2, 3, 4), vnavascues, d4r3d3v1l, zaevlad, 0xPluto, rouhsamad, Krace, kodyvim, Tigerfrake, JanuaryPersimmon2024, and piyushshukla
By allowing anybody to set the address of the Router contract to any address they want to set it allows malicious users to get access to the mint and burn functions of the DcntEth contract.
Proof of Concept
The DcntEth::setRouter() function has not an access control to restrict who can call this function. This allows anybody to set the address of the router contract to any address they’d like to set it.
DcntEth.sol
//@audit-issue => No access control to restrict who can set the address of the router contract
function setRouter(address _router) public {
router = _router;
}
The functions DcntEth::mint() function & DcntEth::burn() function can be called only by the router contract.
DcntEth.sol
//@audit-info => Only the router can call the mint()
function mint(address _to, uint256 _amount) public onlyRouter {
_mint(_to, _amount);
}
//@audit-info => Only the router can call the burn()
function burn(address _from, uint256 _amount) public onlyRouter {
_burn(_from, _amount);
}
A malicious user can set the address of the router contract to an account of their own and:
- Gain access to mint unlimited amounts of DcntEth token, which could be used to disrupt the crosschain accounting mechanism, or to steal the deposited weth in the DecentEthRouter contract.
- Burn all the DcntEth tokens that were issued to the DecentEthRouter contract when liquidity providers deposited their WETH or ETH into it.
- Cause a DoS to the add and remove liquidity functions of the DecentEthRouter contract. All of these functions end up calling the
DcntEth::mint() functionor theDcntEth::burn() function, if the router address is set to be different than the address of the DecentEthRouter, all the calls made from the DecentEthRouter to the DcnEth contract will revert.
DecentEthRouter.sol
/// @inheritdoc IDecentEthRouter
function addLiquidityEth()
public
payable
onlyEthChain
userDepositing(msg.value)
{
weth.deposit{value: msg.value}();
//@audit-issue => If router in the dcnteth contract is not set to the address of the DecentEthRouter, this call will revert
dcntEth.mint(address(this), msg.value);
}
/// @inheritdoc IDecentEthRouter
function removeLiquidityEth(
uint256 amount
) public onlyEthChain userIsWithdrawing(amount) {
//@audit-issue => If router in the dcnteth contract is not set to the address of the DecentEthRouter, this call will revert
dcntEth.burn(address(this), amount);
weth.withdraw(amount);
payable(msg.sender).transfer(amount);
}
/// @inheritdoc IDecentEthRouter
function addLiquidityWeth(
uint256 amount
) public payable userDepositing(amount) {
weth.transferFrom(msg.sender, address(this), amount);
//@audit-issue => If router in the dcnteth contract is not set to the address of the DecentEthRouter, this call will revert
dcntEth.mint(address(this), amount);
}
/// @inheritdoc IDecentEthRouter
function removeLiquidityWeth(
uint256 amount
) public userIsWithdrawing(amount) {
//@audit-issue => If router in the dcnteth contract is not set to the address of the DecentEthRouter, this call will revert
dcntEth.burn(address(this), amount);
weth.transfer(msg.sender, amount);
}
Recommended Mitigation Steps
Make sure to add an Acess Control mechanism to limit who can set the address of the Router in the DcnEth contract.
This and all relevant submissions correctly specify that the lack of access control in the
DcntEth::setRouterfunction can be exploited maliciously and effectively compromise the entire TVL of the Decent ETH token.A high-risk severity is appropriate, and this submission was selected as the best due to detailing all possible impacts:
- Arbitrary mints of the token to withdraw funds provided as liquidity to
UTB- Arbitrary burns to sabotage liquidity pools and other escrow-based contracts
- Sabotage of liquidity provision function invocations
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity access control bug in Decent. Code4rena made it public on 22 March 2024. Found in the 2024-01-decent audit contest (finding H-01), also found by 68 other wardens.
About 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.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.