/building-a-cryptocurrency:coin-security-and-the-build-guidefrom building-a-cryptocurrency
Audits chains and contracts for fund-draining failures, guides architecture decisions (ERC-20 vs L2 vs new chain), and provides a pre-mainnet launch checklist. Covers 2025-2026 loss data, design principles, key management, and build timelines.
Ships in building-a-cryptocurrency. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Part 8 of 8 of the Building a Cryptocurrency reference (plugin
building-a-cryptocurrency), covering §9–§10 — what actually loses money, and the ordered guide to building and launching a chain. Sibling skills:coin-what-it-is-and-the-three-architectures(§1 — the replicated-state-machine definition and the Bitcoin / Ethereum / Monero reference architectures),coin-cryptographic-primitives(§2 — the hashes, signatures, key derivation and commitment schemes a chain is built from),coin-consensus-and-finality(§3 — proof of work, proof of stake, Sybil resistance, fork choice and what finality actually means),coin-building-a-utxo-chain(§4 — the UTXO ledger model, script, transaction validation and what a fork of Bitcoin actually involves),coin-building-an-account-chain(§5 — the account/world-state model, the EVM, gas, and building a chain with smart contracts),coin-privacy-features(§6 — ring signatures, stealth addresses, confidential amounts and zero-knowledge approaches),coin-networking-and-tokenomics(§7–§8 — peer-to-peer gossip and propagation, then issuance, fees, supply schedules and incentive design),Section numbers are shared across the whole set: a reference written as §N →
skillpoints into that sibling skill. This is an engineering reference, not investment, legal or tax advice — deploying a chain that handles real value carries securities, AML/KYC and consumer-protection obligations that are a question for counsel in your jurisdiction.
SCOPE AND DISCLAIMER — carried forward verbatim from the front of the source document, because §10 covers launching, distributing and selling tokens. This is an engineering reference, not investment advice. Creating a cryptocurrency is a legitimate software engineering exercise with well-documented open-source reference implementations. However: deploying a cryptocurrency that handles real value carries serious legal, financial, and security responsibilities. Consult counsel regarding securities law, AML/KYC requirements, and consumer protection regulations in your jurisdiction before launching anything that distributes tokens to the public.
The security landscape for cryptocurrencies is unlike any other software domain. Deployed code is adversarial code running in public with money attached. Every function is callable by anyone, in any order, at any time, composed with contracts that don't exist yet, by attackers who read your source and have unlimited attempts. And you cannot patch it — immutability is the point and also the problem.
The 2025-2026 incident data is unambiguous about what loses money, and it should reorder your priorities.
| Category | 2025 losses (full year) | What It Is | Defense |
|---|---|---|---|
| Access control | ~$953M | Missing or incorrect permission checks on privileged functions; unprotected initializers or upgrade paths | Audit every privileged path. Use Ownable2Step or AccessControl. Timelocks on upgrades. |
| Logic errors | ~$64M | Incorrect business logic — wrong math, wrong conditions, unexpected state transitions | Formal verification. Invariant testing. Multiple audits. |
| Reentrancy | ~$36M | External call before state update allows re-entry that exploits stale state | Checks-Effects-Interactions ordering. nonReentrant guards. Watch cross-function and read-only reentrancy. |
| Flash loan exploits | ~$34M | Flash loans give attackers unlimited capital for one transaction, amplifying existing vulnerabilities | Assume every attacker has unlimited capital. Don't read DEX spot prices as oracle values. Use Chainlink/Pyth or TWAPs. |
Phishing is measured over a different period, so it gets its own table. The source's figure for it covers Q1 2026 alone — one quarter, against four full-year-2025 categories above. The two sets are not summable and not rankable against each other as they stand:
| Category | Q1 2026 losses (one quarter) | What It Is | Defense |
|---|---|---|---|
| Phishing / social engineering | ~$306M | Tricking users into signing malicious transactions or revealing keys | Show users what they're signing in human-readable terms. No blind signing. Hardware wallets. Education. |
THE PRIORITY REORDERING — AND WHICH DATASET EACH CLAIM RESTS ON
From the 2025 full-year column. Access control vulnerabilities cause roughly fifteen times the loss of logic errors and twenty-seven times reentrancy (computed from that table: 953/64 ≈ 14.9 and 953/36 ≈ 26.5). The most devastating attacks don't exploit exotic cryptography — they exploit mundane permission mistakes. These four categories are comparable with each other because they share a period.
From the Q1 2026 data. The source reports that phishing and social engineering account for nearly two-thirds of losses in that period, and that code audits have pushed smart-contract exploit losses down ~89% year-over-year. That two-thirds is the source's own figure: the Q1 2026 total across all categories is not given here, so the share cannot be recomputed from the ~$306M, and ~$306M in a quarter must not be set beside the 2025 rows as though the periods matched.
What the two datasets agree on is the direction, and that is what should reorder your priorities: the attackers moved to the humans. Your security budget is probably misallocated if it's all on code audits and none on key management, operational security, and social-engineering resistance.
false. A silent failure that goes unchecked is worse than a loud one.tx.origin for authorization — tx.origin is the original EOA that initiated the transaction. Any contract the user calls can relay a call to your contract and pass the check. This is a textbook phishing vector. Always use msg.sender.The algorithm choice is usually easy and usually not where you lose. Where keys live, who can reach them, and how they rotate is where systems actually fail. Hard-won lessons: hardware wallets for anything meaningful. Multisig (Safe) for protocol control. Verify what you're signing — blind signing is how multisig holders get drained. Separate deploy keys from admin keys from operational keys. Never put a private key or mnemonic in a repository, an env file, or a CI log. Key compromise produced the largest single losses in 2026's incident data.
This is the fastest path to a cryptocurrency. You're deploying a smart contract on an existing blockchain (Ethereum, an L2, or another EVM chain), not creating a new blockchain. The contract defines the token's supply, transfer rules, and any additional functionality. (The EVM, gas and the ERC-20 interface itself: §5 → coin-building-an-account-chain.)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.37;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/// @title MyCoin — a simple ERC-20 with fixed supply and vesting
contract MyCoin is ERC20, Ownable2Step, ReentrancyGuard {
uint256 public constant TOTAL_SUPPLY = 100_000_000 * 10**18; // 100M tokens
struct VestingSchedule {
uint256 totalAmount;
uint256 claimed;
uint256 startTimestamp;
uint256 durationSeconds;
}
mapping(address => VestingSchedule) public vesting;
/// @notice Tokens promised to beneficiaries and not yet paid out. Every
/// schedule adds to it; every claim subtracts from it. The contract's
/// balance minus this is what the owner is still free to promise.
uint256 public totalReserved;
event VestingSet(address indexed beneficiary, uint256 amount, uint256 durationSeconds);
event VestingClaimed(address indexed beneficiary, uint256 amount);
constructor() ERC20("MyCoin", "MYC") Ownable(msg.sender) {
_mint(address(this), TOTAL_SUPPLY);
}
/// @notice Set vesting for a team member or investor
function setVesting(address beneficiary, uint256 amount, uint256 duration)
external
onlyOwner
{
require(beneficiary != address(0), "Zero beneficiary");
require(amount > 0, "Zero amount");
require(duration > 0, "Zero duration");
require(vesting[beneficiary].totalAmount == 0, "Already vested");
// Check against the UNRESERVED balance. The raw balance still holds every
// token already promised to someone else.
require(amount <= balanceOf(address(this)) - totalReserved, "Insufficient unreserved balance");
totalReserved += amount;
vesting[beneficiary] = VestingSchedule({
totalAmount: amount,
claimed: 0,
startTimestamp: block.timestamp,
durationSeconds: duration
});
emit VestingSet(beneficiary, amount, duration);
}
/// @notice Claim vested tokens
function claimVesting() external nonReentrant {
VestingSchedule storage v = vesting[msg.sender];
require(v.totalAmount > 0, "No vesting");
uint256 elapsed = block.timestamp - v.startTimestamp;
// Clamp. Past the end of the schedule the whole allocation is vested and
// not one token more.
if (elapsed > v.durationSeconds) {
elapsed = v.durationSeconds;
}
uint256 vested = (v.totalAmount * elapsed) / v.durationSeconds;
uint256 claimable = vested - v.claimed;
require(claimable > 0, "Nothing to claim");
v.claimed += claimable;
totalReserved -= claimable;
emit VestingClaimed(msg.sender, claimable);
_transfer(address(this), msg.sender, claimable);
}
}
STATUS OF THIS LISTING: RECONSTRUCTED AND HAND-CHECKED, NOT MACHINE-COMPILED
Four lines are clipped at the right margin in the source document — the
TOTAL_SUPPLYcomment, theVestingSetevent signature, thesetVestingsignature, and the trailing semicolon of the balancerequire— and the source's vesting logic carries the two bugs described below. What is printed above is therefore reconstructed: the clipped lines restored, the two bugs fixed, because the recipe that follows tells you to write and deploy this contract and a damaged listing is not one you can deploy.It has been read line by line. It has not been through
solc. No compiler, no test suite and no audit has seen it, here or anywhere. Treat it as a starting point to compile, test and audit — not as something to deploy, and not as evidence that any particular Solidity version or OpenZeppelin release accepts it as written.
TWO BUGS IN THE SOURCE'S VESTING, FIXED ABOVE
It over-allocated. The source checked each new schedule against the contract's current balance. That balance still holds every token already promised to every other beneficiary, so an owner can write schedules that each fit and together do not — and the beneficiary who claims last finds the contract empty and their transaction reverting. Reserving is the fix:
totalReservedgoes up onsetVesting, down on each claim, and a new schedule is checked againstbalanceOf(address(this)) - totalReserved.It paid past the end of the schedule. The source computed
vested = totalAmount * elapsed / durationSecondswith nothing boundingelapsed. One duration after the startvestedequalstotalAmount, which is right; two durations after, the arithmetic claims twice the allocation, paid out of other beneficiaries' tokens. ClampingelapsedtodurationSecondsbefore the division is the whole fix.Both are ordinary logic errors — the ~$64M category in the table above, not exotic cryptography — and both are exactly what invariant testing catches. Assert, as invariants: the sum over all schedules of
totalAmount - claimednever exceedsbalanceOf(address(this)), and no beneficiary can ever be paid more than theirtotalAmount.
What you need to do: write the contract; test it with Foundry (unit tests, fuzzing, invariant testing); get it audited; deploy to a testnet (Sepolia, Holesky); exercise it; deploy to mainnet; verify the source on Etherscan; transfer ownership to a multisig + timelock; write an incident runbook.
If you want your own execution environment and fee market but don't want to bootstrap security from scratch, an L2 rollup inherits the L1's security. OP Stack (Optimism's stack) is the most established path for optimistic rollups; ZK Stack and Polygon CDK for ZK rollups. The trade-off: your chain depends on the L1 for data availability and settlement. Most rollups currently run a centralized sequencer (a censorship and liveness single point of failure), with forced inclusion via L1 as the escape hatch.
The three security questions to ask of any L2: who can censor you, who can steal from you, and can you exit without permission?
If you need a fully independent blockchain, this is the most ambitious path. You need to build or assemble:
coin-consensus-and-finality.)coin-networking-and-tokenomics.)| Component | Bitcoin-Style | Ethereum-Style | Privacy-Style |
|---|---|---|---|
| Language | C++, Rust | Go, Rust, C# | C++, Rust |
| Ledger | UTXO set | Account trie | UTXO + privacy extensions |
| Consensus | PoW (SHA-256d, RandomX, or custom) | PoS (Gasper-like, Tendermint) | PoW (RandomX or custom ASIC-resistant) |
| Signatures | Schnorr (secp256k1) | ECDSA (secp256k1) or BLS | Linkable ring signatures over Ed25519 — an Edwards-form Curve25519, not secp256k1 — with Bulletproofs+ range proofs on the amounts |
| Networking | P2P gossip, compact blocks | devp2p / libp2p | P2P with Dandelion++ |
| Wallet | HD (BIP-32/39), descriptors, PSBT | HD, mnemonic, EIP-712 signing | View key + spend key, subaddresses |
| Explorer | Electrum server + Esplora | The Graph / Ponder / custom | None (privacy) or view-key-based |
FOR SMART CONTRACTS / TOKENS Code audited by at least one reputable firm, findings resolved. Testnet-deployed and exercised under realistic conditions. Exact compiler version pinned (e.g.,
pragma solidity 0.8.37;, never floating pragmas). Optimizer settings recorded. Deterministic build reproducible. Constructor arguments verified. Source verified on the block explorer. Ownership transferred to a multisig (Safe) + timelock, never an EOA. Initializers called and locked. Pause mechanism tested. Monitoring live (Forta/Defender or custom). Incident runbook written before launch. Bug bounty listed (Immunefi). Events emitted generously (they are your API to the off-chain world).
FOR A NEW BLOCKCHAIN All of the above, plus: consensus mechanism tested under adversarial conditions (byzantine nodes, network partitions, double-spend attempts). Multi-client testing if you have more than one implementation (client bugs caused chain splits in Bitcoin and Ethereum history). Testnet running for months with public participation. Difficulty adjustment or staking parameters validated against simulations. Genesis block carefully constructed (no accidental pre-mines, no vulnerable initial distribution). Peer discovery robust. Block propagation time measured and acceptable. Wallet software tested across platforms. Block explorer operational. Documentation complete. A plan for exchange listings (if desired). Legal review of token distribution (securities law varies by jurisdiction). A community of miners/validators ready to secure the network at launch.
COMMON FATAL MISTAKES Launching without an audit. Using floating pragma (your deployed bytecode depends on whoever compiled it). Putting an EOA as the contract owner. Blind-signing transactions. Reusing addresses on a privacy chain. Assuming a contract safe on one EVM chain is safe on another. Letting users list arbitrary tokens. Reading a DEX spot price as an oracle. Using
tx.originfor authorization. Unbounded loops. Storing keys in code or CI. Launching with a tiny security budget on a PoW chain. Ignoring the regulatory landscape. Promising features you haven't built. All of these have caused real, expensive losses.
The two sections below are back matter of the source document, following Part X; they are carried here because this is the closing skill of the set.
k — reuse reveals the private key.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
8 skills in this plugin
/coin-building-an-account-chainUse when deciding between shipping an ERC-20 token, a new account-model chain, or an L2 rollup, and when designing or reviewing account state, EVM data locations, gas budgets, call semantics, or a fungible token contract. Covers the account world-state model, the EVM stack machine and its storage costs, the EIP-1559 gas system, the ERC-20 interface and its integration hazards. Part 5 of the Building a Cryptocurrency reference./coin-building-a-utxo-chainUse when designing or implementing a UTXO-based chain, modelling transaction inputs and outputs, writing or auditing Bitcoin Script locking and unlocking scripts, deciding which address formats a wallet or node must support, or forking Bitcoin. Covers the UTXO ledger model, block structure and chain linkage, the coinbase transaction and its maturity rule, Script validation, and the four Bitcoin address types. Part 4 of 8 of the Building a Cryptocurrency reference./coin-consensus-and-finalityUse when choosing a consensus mechanism for a new chain, sizing confirmation counts before releasing value, reasoning about 51 percent attacks and chain reorganizations, tuning difficulty retargeting, picking a proof-of-work algorithm, or deciding between probabilistic, explicit and instant finality. Covers proof of work, proof of stake, Gasper, BFT and DAG designs, slashing, nothing-at-stake and validator economics. Part 3 of 8 of the Building a Cryptocurrency reference.npx claudepluginhub the-vibey-project/vibey --plugin building-a-cryptocurrency