skills/bap578-security-audit/SKILL.md
Use this skill when auditing, hardening, or verifying the security posture of BAP-578 Non-Fungible Agent deployments, including threat models, NFA-specific vulnerabilities, and remediation guidance.
npx skillsauth add chatandbuild/skills-repo BAP-578 Security AuditInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill to audit, harden, and verify the security posture of BAP-578 Non-Fungible Agents deployments. This skill provides a structured threat model, detailed audit checklist, vulnerability patterns specific to the NFA architecture, and remediation guidance.
The security layer validates trust boundaries and prevents loss. Security auditing for BAP-578 ensures that the contract's identity guarantees (ownership, metadata integrity, fund safety) cannot be subverted by attackers, malicious logic contracts, or administrative errors. The auditor's role is to verify that every claim the contract makes about identity, memory, capability, and trust is actually enforced.
Security memory includes known attack patterns, prior audit findings, guard rails built into the contract, and the threat model specific to BAP-578's architecture. Key patterns to remember:
_authorizeUpgrade is not properly guardedRun a structured security audit that produces:
Every finding maps to a specific function, modifier, or pattern in the contract source. Findings reference line numbers, function names, and concrete attack scenarios. Trust in the audit comes from:
BAP-578 combines multiple patterns that each carry specific risks:
┌─────────────────────────────────────────┐
│ BAP-578 Contract │
├──────────┬──────────┬───────────────────┤
│ ERC-721 │ UUPS │ Custom State │
│ Standard │ Proxy │ (Agents, Funds) │
├──────────┼──────────┼───────────────────┤
│ Transfer │ Upgrade │ Mint (free/paid) │
│ Approval │ Auth │ Fund/Withdraw │
│ Metadata │ Storage │ Logic binding │
│ │ Layout │ Status toggle │
│ │ │ Metadata update │
└──────────┴──────────┴───────────────────┘
↓ ↓
External actors: Logic contracts
(users, attackers) (external code)
T1: Reentrancy attacks
Target: withdrawFromAgent and any function that sends BNB.
Attack scenario: A malicious contract calls withdrawFromAgent, and the fallback function re-enters the contract before state is updated. If the contract does not follow CEI pattern or use nonReentrant, the attacker can drain the agent's balance.
Verification steps:
withdrawFromAgent uses the nonReentrant modifier.fundAgent does not have re-entrancy paths.emergencyWithdraw) is also protected.T2: Access control bypass
Target: Owner-only and token-owner-only functions.
Attack scenario: An attacker calls setTreasury, setPaused, emergencyWithdraw, or grantAdditionalFreeMints without being the contract owner. Or calls withdrawFromAgent, setAgentStatus, setLogicAddress, or updateAgentMetadata without being the token owner.
Verification steps:
onlyOwner modifier.require(ownerOf(tokenId) == msg.sender)).transferOwnership is properly restricted.T3: Malicious logic contract binding
Target: setLogicAddress function.
Attack scenario: An attacker tricks a user into binding a malicious logic contract that steals funds or manipulates agent state. Or an attacker deploys a contract that appears safe but has a hidden backdoor.
Verification steps:
T4: Free mint abuse
Target: createAgent free mint logic.
Attack scenarios:
Verification steps:
to == msg.sender.isFreeMint mapping is correctly set at mint time.grantAdditionalFreeMints is owner-only.T5: Upgrade safety
Target: UUPS proxy mechanism.
Attack scenarios:
upgradeTo or upgradeToAndCall.Verification steps:
_authorizeUpgrade is guarded by onlyOwner.reinitializer is used for new initialization logic.T6: Fund management risks
Target: Agent balances, treasury, and BNB flows.
Attack scenarios:
Verification steps:
msg.value go at mint time?T7: Off-chain integrity
Target: vaultURI and vaultHash.
Attack scenarios:
Verification steps:
vaultHash is stored on-chain and updated with metadata updates.T8: Denial of service
Target: setPaused and contract availability.
Attack scenarios:
Verification steps:
tokensOfOwner or other view functions can be DOS'd by large token counts.T9: Merkle tree learning integrity
Target: vaultHash used as Merkle root for learning agents.
Attack scenarios:
Verification steps:
vaultHash root.updateAgentMetadata correctly updates vaultHash when the Merkle root changes.T10: Logic contract as learning module risks
Target: Logic contracts implementing RAG, MCP, or learning modules.
Attack scenarios:
Verification steps:
setTreasury requires onlyOwnersetPaused requires onlyOwneremergencyWithdraw requires onlyOwnergrantAdditionalFreeMints requires onlyOwnersetFreeMintsPerUser requires onlyOwner_authorizeUpgrade requires onlyOwnerwithdrawFromAgent requires token ownersetAgentStatus requires token ownersetLogicAddress requires token ownerupdateAgentMetadata requires token ownerwithdrawFromAgent uses nonReentrant modifierwithdrawFromAgentemergencyWithdraw is reentrancy-safefundAgent correctly updates balance before any external interactioncall.value or transfer patternsfundAgentwithdrawFromAgent_authorizeUpgrade guarded by onlyOwnerreinitializer version incremented for new versions_update or _beforeTokenTransfer hook enforces restrictionisFreeMint mapping set correctly at mint timeaddress(0) correctly unbinds logicCritical — Direct fund loss or irreversible control loss. Example: reentrancy allowing balance drain, unauthorized upgrade to malicious implementation.
High — Significant trust or integrity failure. Example: access control bypass on admin functions, transfer restriction bypass for free mints.
Medium — Operational risk or unsafe defaults. Example: missing events for state changes, no pause on critical functions during emergency.
Low — Gas optimization, UX issues, or missing convenience features. Example: unbounded loop in view function, missing input validation on non-critical fields.
Informational — Best practice recommendations, code quality notes, documentation gaps.
pip install slither-analyzer
slither contracts/NonFungibleAgents.sol --config-file slither.config.json
Key detectors relevant to BAP-578:
reentrancy-eth — reentrancy on BNB transfersunprotected-upgrade — missing _authorizeUpgrade guardunchecked-transfer — missing return value check on callscontrolled-delegatecall — delegatecall to user-controlled addressarbitrary-send-eth — unauthorized BNB transfersFor critical deployments, write formal verification rules:
rule withdrawPreservesInvariant {
env e;
uint256 tokenId;
uint256 amount;
uint256 balanceBefore = getAgentState(tokenId).balance;
withdrawFromAgent(e, tokenId, amount);
uint256 balanceAfter = getAgentState(tokenId).balance;
assert balanceAfter == balanceBefore - amount;
}
Check that no function can be griefed by sending excessive gas or triggering out-of-gas:
tokensOfOwner with a user holding many tokensemergencyWithdraw with large contract balancecreateAgent with very long metadata stringsSolidity call returns a boolean. If not checked, failed transfers silently succeed in the contract's view.
// VULNERABLE
(bool success, ) = payable(owner).call{value: amount}("");
// Missing: require(success, "Transfer failed");
If mint fees or free mint allocations can be observed in the mempool, attackers may front-run to claim free mints or manipulate pricing.
Mitigation: Free mint allocation is per-address and checked on-chain, so front-running is limited. However, if dynamic pricing is added, commit-reveal patterns may be needed.
Solidity 0.8+ has built-in overflow checks. Verify the contract uses Solidity >= 0.8.0. If using unchecked blocks, verify arithmetic safety manually.
BAP-578 Security Audit Report
══════════════════════════════
Date: YYYY-MM-DD
Auditor: [name/team]
Commit: [git hash]
Scope: NonFungibleAgents.sol + dependencies
Summary
───────
Critical: 0
High: 0
Medium: 0
Low: 0
Informational: 0
Findings
────────
[ID] [Severity] [Title]
Location: [contract]:[function]:[line]
Description: [what was found]
Impact: [what could happen]
Recommendation: [how to fix]
Status: [open/fixed/acknowledged]
Conclusion
──────────
[overall assessment and deployment recommendation]
When asked to audit BAP-578, respond with:
bap578bap578-upgradebap578-scannerdocumentation
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.
development
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
devops
Deploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.
tools
Use this skill when designing and building durable command-line tools from API docs, OpenAPI specs, SDKs, curl examples, admin tools, web apps, or local scripts, especially when the CLI should expose composable commands, stable JSON output, auth/config handling, install-on-PATH behavior, and a companion skill.