Skip to content

An Introduction to solmate (EVM Expeditions #01)

Notifications You must be signed in to change notification settings

byterocket/about-solmate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About solmate

This repository was created for EVM Expeditions #01, where merkleplant gave an intro to solmate. You can find the video here:

👉 Click here for the video 👈

History

  • Written by t11s
    • Famous for low-level gas optimizations & data-driven Solidity engineering
  • Started as a project inside of RariCapital
  • Then moved to t11s' private repo after they switched to Paradigm

Disclaimer about Security

Copied from README:

[...] these contracts are **not designed with user safety** in mind:

- There are implicit invariants these contracts expect to hold.
- **You can easily shoot yourself in the foot if you're not careful.**
- You should thoroughly read each contract you plan to use top to bottom.

Also:

Auditing Projects using solmate:

While solmate itself can be assumed to be secure (if using major version), the contracts used should be studied carefully anyway in order to check that the project uses them correctly.

Philosophical Differences to OpenZeppelin

OpenZeppelin:

solmate:

  • Optimizes as much as possible for the average case
    • -> Misses checks for corner cases
  • Highly opinionated
  • -> Should only be used by experienced Solditiy developers

Personal Note

IMHO solmate does a really good job of not reinventing the wheel but instead getting inspired from a ton of high quality and battle-proved projects.

What's inside?

   auth
   ├─ Owned"Simple single owner authorization"
-> ├─ Auth"Flexible and updatable auth pattern"
   ├─ authorities
   │  ├─ RolesAuthority"Role based Authority that supports up to 256 roles"
   │  ├─ MultiRolesAuthority"Flexible and target agnostic role based Authority"
   mixins
   ├─ ERC4626"Minimal ERC4626 tokenized Vault implementation"
   tokens
   ├─ WETH"Minimalist and modern Wrapped Ether implementation"
-> ├─ ERC20"Modern and gas efficient ERC20 + EIP-2612 implementation"
-> ├─ ERC721"Modern, minimalist, and gas efficient ERC721 implementation"
   ├─ ERC1155"Minimalist and gas efficient standard ERC1155 implementation"
   utils
   ├─ SSTORE2"Library for cheaper reads and writes to persistent storage"
   ├─ CREATE3"Deploy to deterministic addresses without an initcode factor"
   ├─ LibString"Library for creating string representations of uint values"
   ├─ SafeCastLib"Safe unsigned integer casting lib that reverts on overflow"
   ├─ SignedWadMath"Signed integer 18 decimal fixed point arithmetic library"
   ├─ MerkleProofLib"Efficient merkle tree inclusion proof verification library"
-> ├─ ReentrancyGuard"Gas optimized reentrancy protection for smart contracts"
   ├─ FixedPointMathLib"Arithmetic library with operations for fixed-point numbers"
   ├─ Bytes32AddressLib"Library for converting between addresses and bytes32 values"
-> ├─ SafeTransferLib"Safe ERC20/ETH transfer lib that handles missing return values"

Comparison of Documentation: solmate vs OpenZeppelin

See solmate's ReentrancyGuard vs OpenZeppelin's ReentrancyGuard.

OpenZeppelin:

Provides a lot of in-code documentation explaining the reasoning behind decisions (e.g. why are the lock's values 1 and 2 instead of 0 and 1?).

solmate:

Links to the OZ repo :)

tokens/ERC20.sol & tokens/ERC721.sol

Check comments inside the code:

Problem:

Invariant is not enforced in order to save gas and give downstream contracts, i.e. user/developers, more power over internal state.

Remember: with great power comes great responsibility 🕷

utils/SafeTransferLib or: How I learned to stop worrying and love assembly 💣

Check comments inside the code: