Pular para o conteúdo
Skillpedia
Segurança6,5 mil · #14005

access-control

O que ela faz

Este roteiro orienta a revisão de quem pode alterar configurações importantes ou movimentar fundos em um contrato inteligente. Ele é para auditores e desenvolvedores que querem permissões verificadas.

Quando usar

  • ✓Quando um contrato em Solidity tem funções que alteram propriedade, configurações ou fundos.
  • ✓Quando você quer verificar se as checagens de função ou de dono estão corretas.
  • ✓Quando uma equipe quer encontrar funções públicas que deveriam ser restritas.

Link da skill

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/access-control/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/access-control/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Você pode verificar se alguma função administrativa do nosso contrato está sem a checagem correta de dono?”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente encontra cada função que altera estado, verifica qual modificador de permissão se aplica e sinaliza as funções com checagens ausentes ou incorretas.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

Access Control Playbook

Access control bugs are the most boring class — and the most common in production audits. They're cheap to find with grep + LSP. They drain millions when missed (LeetSwap, Audius, Saddle, Akropolis).

Audit steps

1. Find every state-changing function

# Functions that are NOT view/pure and NOT internal/private
grep -rE 'function [a-zA-Z_]+\(.*\)(public|external)' src/ | grep -v 'view\|pure'

# Or via slither
slither . --print function-summary

2. For each external/public state-changer, ask

  • Does it modify storage that affects user funds, ownership, or configuration?
  • Is there a modifier (onlyOwner, onlyRole, onlyDAO, custom auth)?
  • If yes, what's the modifier checking?
  • If no, should there be one?

3. Audit each modifier

Common modifier patterns + bugs:

Pattern Bug
require(msg.sender == owner) owner settable by anyone? setOwner unprotected?
require(msg.sender == tx.origin) Wrong — tx.origin breaks meta-transactions, AND it's phishable
_msgSender() in OZ ERC2771Context Forwarder trusted but anyone can forward — does the contract validate the forwarder?
onlyRole(MINTER) Who can grant MINTER? Is the admin a multisig or single key?
require(initialized == false) Initializer can be called twice if initialized writeable elsewhere
require(block.timestamp > deployTime + 24 hours) Time-based is often a fake delay — check if deployTime is settable
require(approvedSigners[msg.sender]) Approval list managed by single key?

4. Specific anti-patterns to grep

# Functions accidentally external (default in Solidity <0.5)
grep -rn 'function [a-zA-Z_]*[^ ]* *{' src/ | grep -v 'internal\|private\|public\|external'

# msg.sender == tx.origin (phishable)
grep -rn 'tx.origin' src/

# Reentrancy in access-control checks
grep -rn 'onlyOwner.*nonReentrant' src/   # both? often wrong order

# `delegatecall` without auth gate
grep -rn 'delegatecall' src/

# `selfdestruct` available
grep -rn 'selfdestruct\|suicide(' src/

5. Initializer bugs

// VULNERABLE
function initialize(address _owner) external {
    owner = _owner;
    // missing: require(!initialized); initialized = true;
}

// VULNERABLE (proxy implementation)
contract Impl {
    constructor() { ... }  // NEVER RUNS in proxy context
    // initialize() should set proxy state but doesn't gate
}

// SAFE
function initialize(address _owner) external initializer {
    // OZ's initializer modifier enforces single-call
    __Ownable_init(_owner);
}

For UUPS/Transparent proxies: check _authorizeUpgrade is overridden and gated. Default OZ override is empty (revert).

6. Function-selector collisions (proxies)

Transparent proxy admin function selectors collide w/ impl function selectors → admin functions become uncallable, OR impl functions are shadowed by admin. Check w/ slither:

slither-check-erc src/Impl.sol --erc ERC1967

7. Role grant/revoke

For AccessControl:

  • DEFAULT_ADMIN_ROLE is the admin of all roles by default
  • Anyone with DEFAULT_ADMIN_ROLE can grant any role to anyone
  • If init code grants DEFAULT_ADMIN_ROLE to deployer w/ no transfer to multisig → key person risk

Check role hierarchy:

grep -rn '_setRoleAdmin\|_setupRole\|grantRole' src/

PoC template (Foundry)

function test_unauth_call() public {
    address attacker = address(0xBEEF);
    vm.prank(attacker);

    // Call the function that should require auth
    target.dangerousFunction(arg1, arg2);

    // Assert state change happened
    assertEq(target.criticalParam(), expectedManipulatedValue);
    // No revert = vulnerable
}

function test_role_takeover() public {
    address attacker = address(0xBEEF);
    vm.startPrank(attacker);

    // If grantRole is callable by anyone
    target.grantRole(target.MINTER_ROLE(), attacker);
    assertTrue(target.hasRole(target.MINTER_ROLE(), attacker));

    // Now exploit MINTER_ROLE
    target.mint(attacker, 1_000_000 ether);
}

function test_init_re_entry() public {
    // Call initialize twice
    target.initialize(address(this));
    vm.expectRevert("Initializable: contract is already initialized");
    target.initialize(attacker);
}

function test_upgrade_no_auth() public {
    address attacker = address(0xBEEF);
    address malicious = address(new MaliciousImpl());

    vm.prank(attacker);
    target.upgradeTo(malicious);

    // Now any call goes to
Perguntas frequentes

Por que essa classe de bug é comum?

O roteiro diz que ela é a classe mais comum em auditorias de produção, e é barata de encontrar com buscas simples.

Qual padrão errado é comum?

Usar tx.origin para autorização, o que o roteiro diz estar errado e pode ser explorado por phishing.

O que o agente verifica sobre papéis?

Quem pode conceder papéis e se o administrador é uma multisig ou uma chave única.

Detalhes

Descrição original do autor

Missing modifiers, wrong msg.sender checks, default-public functions, missing onlyOwner / onlyRole / onlyDAO authorization.

repo: BitterSecurity/Decepticon

Popularidade

Estrelas no GitHub
6,5 mil
Posição no ranking
#14005
Licença
Apache-2.0
Atualizada em
01/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas