Skip to content

@tank/solidity-mastery

1.0.0

Description

Solidity smart contract development, security, and tooling for EVM chains. Covers Solidity 0.8.x patterns, security vulnerabilities (reentrancy, flash loans, audit checklists), gas optimization, ERC standards (ERC-20/721/1155/4626), upgradeable contracts (UUPS, transparent proxy), Foundry toolchain (forge test, script, fuzz/invariant testing), OpenZeppelin 5.x, and multi-chain deployment..

Download
Verified
tank install @tank/solidity-mastery

Solidity Mastery

Core Philosophy

  1. Security before features -- Every function is a potential attack surface. Apply checks-effects-interactions, use OpenZeppelin battle-tested contracts, and audit before mainnet.
  2. Gas is user cost -- Every opcode costs money. Pack storage, prefer calldata over memory, use custom errors, and benchmark with forge snapshot.
  3. Immutability demands correctness -- Deployed contracts cannot be patched. Test exhaustively with fuzz and invariant tests before deployment.
  4. Compose from audited primitives -- Extend OpenZeppelin rather than reimplementing. Custom cryptography and token logic introduces unaudited risk.
  5. Upgradeability is a tradeoff -- Proxies add complexity and trust assumptions. Use only when the protocol genuinely requires post-deployment changes.

Quick-Start: Common Problems

"Which token standard do I need?"

Use CaseStandardKey Feature
Fungible currency/utility tokenERC-20Balances, approve/transferFrom
Unique collectibles/NFTsERC-721Token IDs, ownerOf
Mixed fungible + non-fungibleERC-1155Batch transfers, multi-token
Tokenized vault / yieldERC-4626Deposit/withdraw/shares math
-> See references/erc-standards.md

"My contract is too expensive to call"

  1. Run forge snapshot to baseline gas per test
  2. Pack storage variables (smaller types in same slot)
  3. Replace require(cond, "msg") with custom errors
  4. Use calldata instead of memory for read-only external args
  5. Wrap safe arithmetic in unchecked {} blocks -> See references/gas-optimization.md

"How do I test with Foundry?"

  1. Write unit tests extending forge-std/Test.sol
  2. Use vm.prank, vm.expectRevert, vm.deal cheatcodes
  3. Add fuzz tests with parameterized inputs
  4. Write invariant tests for protocol-wide properties
  5. Run forge test -vvv for full trace on failure -> See references/foundry-toolchain.md

"I need my contract to be upgradeable"

  1. Choose pattern: UUPS (lightweight) or Transparent Proxy (admin separation)
  2. Use OpenZeppelin upgradeable variants (@openzeppelin/contracts-upgradeable)
  3. Never define constructors -- use initializer functions
  4. Maintain storage layout compatibility across versions -> See references/upgradeable-contracts.md

"How do I prevent reentrancy?"

  1. Follow checks-effects-interactions: validate, update state, then call external
  2. Use OpenZeppelin ReentrancyGuard for defense-in-depth
  3. Consider transient storage locks (Solidity 0.8.28+, EIP-1153) -> See references/security-vulnerabilities.md

Decision Trees

Development Toolchain

SignalUse
Fast compilation, Solidity-native testsFoundry (forge)
JavaScript/TypeScript integration neededHardhat
Quick prototyping in browserRemix IDE
Production projectFoundry + Hardhat hybrid

Contract Architecture

SignalPattern
Simple standalone contractDirect deployment
Need post-deployment upgradesUUPS or Transparent Proxy
Deploy many identical contractsFactory (Clone/CREATE2)
Complex multi-contract systemDiamond (EIP-2535) or modular

Access Control

SignalPattern
Single privileged addressOwnable (OpenZeppelin)
Multiple roles with distinct permissionsAccessControl (role-based)
Time-delayed admin operationsTimelockController
Governance by token holdersGovernor + Timelock

Reference Index

FileContents
references/security-vulnerabilities.mdReentrancy, access control flaws, flash loan attacks, integer issues, front-running, tx.origin, delegatecall risks, audit checklist
references/gas-optimization.mdStorage packing, calldata vs memory, custom errors, unchecked math, immutable/constant, batch operations, compiler optimizer settings
references/erc-standards.mdERC-20, ERC-721, ERC-1155, ERC-4626 implementation patterns, extensions, common pitfalls, OpenZeppelin usage
references/foundry-toolchain.mdForge test, script, deploy, fuzz testing, invariant testing, cheatcodes, gas snapshots, Cast CLI, Anvil forking
references/upgradeable-contracts.mdUUPS, transparent proxy, beacon proxy, storage layout, initializers, upgrade safety, OpenZeppelin Upgrades
references/contract-patterns.mdFactory, clone (EIP-1167), CREATE2, diamond (EIP-2535), access control, state machines, pull payments
references/deployment-verification.mdMulti-chain deployment, Foundry scripts, constructor args encoding, Etherscan verification, deterministic deploys

Command Palette

Search skills, docs, and navigate Tank