The BURNER cannot burn tokens from accounts not KYC verified due to the check in _beforeTokenTransfer .
The BURNER_ROLE cannot burn tokens from an account that has been removed from the KYC list because the _beforeTokenTransfer check requires the 'from' address to be KYC verified. An attacker could not exploit this directly, but it prevents the burner from performing its intended function on non-KYC accounts.
Weipeng Jiang Follow with ni8mare, Limbooo and 13 others
Originally disclosed on Code4rena
Submitted by Krace, also found by ni8mare, Limbooo, leegh, ast3ros, radev_sw, Shubham, kartik_giri_47538, Arz, kaden, Tychai0s, yotov721, SpicyMeatball, ZanyBonzy, dvrkzy, and 0xDemon
Impact
The BURNER_ROLE cannot burn tokens if the target account has been removed from the KYC list.
Proof of Concept
When the BURNER_ROLE burns tokens of _account, it invokes _burnShares and then calls _beforeTokenTransfer to verify the KYC status of _account.
In accordance with a previous audit report, the BURNER_ROLE should have the capability to burn tokens of any account, even if the account is blacklisted; or, in this case, not KYC verified. However, there is no mechanism that allows BURNER_ROLE to burn tokens of accounts that are removed from KYC list.
function burn(
address _account,
uint256 _amount
) external onlyRole(BURNER_ROLE) {
uint256 ousgSharesAmount = getSharesByROUSG(_amount);
if (ousgSharesAmount < OUSG_TO_ROUSG_SHARES_MULTIPLIER)
revert UnwrapTooSmall();
_burnShares(_account, ousgSharesAmount);
ousg.transfer(
msg.sender,
ousgSharesAmount / OUSG_TO_ROUSG_SHARES_MULTIPLIER
);
emit Transfer(address(0), msg.sender, getROUSGByShares(ousgSharesAmount));
emit TransferShares(_account, address(0), ousgSharesAmount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256
) internal view {
// Check constraints when `transferFrom` is called to facliitate
// a transfer between two parties that are not `from` or `to`.
if (from != msg.sender && to != msg.sender) {
require(_getKYCStatus(msg.sender), "rOUSG: 'sender' address not KYC'd");
}
// When from is not KYC, BURNER can not burn their tokens
if (from != address(0)) {
// If not minting
require(_getKYCStatus(from), "rOUSG: 'from' address not KYC'd");
}
if (to != address(0)) {
// If not burning
require(_getKYCStatus(to), "rOUSG: 'to' address not KYC'd");
}
}
POC
Add the test to forge-tests/ousg/rOUSG.t.sol and run it with:
forge test --fork-url $(grep -w ETHEREUM_RPC_URL .env | cut -d '=' -f2) --fork-block-number $(grep -w FORK_FROM_BLOCK_NUMBER_MAINNET .env | cut -d '=' -f2) --nmc ASSERT_FORK --match-test test_burn_with_NOKYC
diff --git a/forge-tests/ousg/rOUSG.t.sol b/forge-tests/ousg/rOUSG.t.sol
index 67faa15..b39b4ac 100644
--- a/forge-tests/ousg/rOUSG.t.sol
+++ b/forge-tests/ousg/rOUSG.t.sol
@@ -13,6 +13,7 @@ contract Test_rOUSG_ETH is OUSG_BasicDeployment {
CashKYCSenderReceiver ousgProxied = CashKYCSenderReceiver(address(ousg));
vm.startPrank(OUSG_GUARDIAN);
ousgProxied.grantRole(ousgProxied.MINTER_ROLE(), OUSG_GUARDIAN);
+ ousgProxied.grantRole(ousgProxied.BURNER_ROLE(), OUSG_GUARDIAN);
vm.stopPrank();
// Sanity Asserts
@@ -26,6 +27,15 @@ contract Test_rOUSG_ETH is OUSG_BasicDeployment {
assertTrue(registry.getKYCStatus(OUSG_KYC_REQUIREMENT_GROUP, alice));
}
+ function test_burn_with_NOKYC() public dealAliceROUSG(1e18) {
+ vm.startPrank(OUSG_GUARDIAN);
+ _removeAddressFromKYC(OUSG_KYC_REQUIREMENT_GROUP, alice);
+ vm.stopPrank();
+
+ vm.startPrank(OUSG_GUARDIAN);
+ rOUSGToken.burn(alice, 1e18);
+ vm.stopPrank();
+ }
/*//////////////////////////////////////////////////////////////
rOUSG Metadata Tests
//////////////////////////////////////////////////////////////*/
Result:
Ran 1 test for forge-tests/ousg/rOUSG.t.sol:Test_rOUSG_ETH
[FAIL. Reason: revert: rOUSG: 'from' address not KYC'd] test_burn_with_NOKYC() (gas: 246678)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 11.44ms (1.15ms CPU time)
Ran 1 test suite in 1.12s (11.44ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in forge-tests/ousg/rOUSG.t.sol:Test_rOUSG_ETH
[FAIL. Reason: revert: rOUSG: 'from' address not KYC'd] test_burn_with_NOKYC() (gas: 246678)
Encountered a total of 1 failing tests, 0 tests succeeded
Tools Used
Foundry
Recommended Mitigation Steps
Allow the BURNER to burn tokens without checking the KYC of from address.
diff --git a/contracts/ousg/rOUSG.sol b/contracts/ousg/rOUSG.sol
index 29d9112..6809a28 100644
--- a/contracts/ousg/rOUSG.sol
+++ b/contracts/ousg/rOUSG.sol
@@ -594,7 +594,7 @@ contract ROUSG is
require(_getKYCStatus(msg.sender), "rOUSG: 'sender' address not KYC'd");
}
- if (from != address(0)) {
+ if (from != address(0) && !hasRole(BURNER_ROLE, msg.sender)) {
// If not minting
require(_getKYCStatus(from), "rOUSG: 'from' address not KYC'd");
}
Assessed type
Invalid Validation
The reasons why I opted to keep this as Medium is:
- The possibility of changing a contract implementation (in this case the registry) to a new implementation (that is not in scope) is not something that is generally accepted as a severity mitigation
- The same finding was already judged as a valid Medium in a previous audit with a different scope (rUSDY), that was not explicitly marked as a known issue in the README
cameronclifton (Ondo) disputed and commented:
We will not be addressing this as we have a safe workaround for this exact scenario.
Note: For full discussion, see here.
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
Root cause
Likely the _beforeTokenTransfer function enforces KYC status on the 'from' address for all transfers, including burns initiated by the BURNER_ROLE, without exempting the burner.
What the attacker needed
Caller has BURNER_ROLE; target account is not KYC verified
The fix
The check for the 'from' address's KYC status should be skipped when the caller has the BURNER_ROLE.
How it was found
- Grant BURNER_ROLE to the guardian account.
- Remove Alice from the KYC list.
- Call burn on Alice's account as the guardian.
- Observe the transaction reverts with 'from' address not KYC'd.
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.
This is a smart contract for a token where transfers are restricted to users who have passed a KYC (know-your-customer) check. A special role called BURNER is supposed to be able to destroy tokens from any account, but a check in the transfer logic blocks it if the account is no longer KYC verified. So the burner cannot do its job for those accounts.
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.