Base

Notes on base


Starting from scratch

What is it?

  • ETH Layer 2 build on top of OP Stack (Bedrock release)
  • OP Stack is a stack of smart contracts that run on Ethereum Virtual Machine (EVM) that add functionality and capacilities based on a modular architecture.
  • Allows to only modify specific modules or swap them out completely

OP Stack

  • It uses an Optimistic Rollup for state communitments pushed to the L1

  • Optimistic rollup moves computation and state storage off-chain ex: Execute transactions outside ETH but post tx data to ETH mainnet as calldata

  • Called Optimistic because they assume off-chain txs are valid and don't public proof of validity for transactions published on chain.

  • rely on a frau proving process where anyone can challenge a rollup batch by computing a fault proof.

  • Base combines off-chain tx together in batches befor sending to L1 which spread fees among tx and reduces fees for those using Base.

  • Uses on-chain ETH contracts for storing rollups, monitoring state updates and tracking user deposits.

  • Uses off-chain VM for computation and storage

  • On L2s build on the OP Stack there exists the concept of sequencer, which is in charge of posting data to the underlayer L1, constructing and excuting L2 blocks and providing tx confirmations.

  • If it tries to ignore a legitimate L1 transation, the state would be inconsisten with the verfiers, thus achieving consistency

  • Block production time is 2s

  • The sequencer reads transactions submitted on the L1, called deposits, and uses this the block to which they correspond to in the L1 as their epoch. The first block of the epoch includes all the deposits that happened in the L1 block to which it corresponds.

  • Forced inclussion is when a L1 tx is sent to submit an L2 tx, bypassing the op-batcher

  • compresion is done in sequence batches in channels. When a channel is full, it is sent to the L1

  • Ther exists comptibility for digital assets, including ERC20 between L1 and L2, allowing to excange tokens between L1 and L2 or even withdrawals

SEtup

Hardhat

  • start -> pnpx hardhat init
  • hardhat.config.ts -> config file, specify solidty version, networks, paths, etc
  • compile -> hardhat compile compile solidity files returning the resulting json file (contains the abi of the program)
  • deploy --network base_sepolia -> Deploy to the base sepolia network

Foundry

Command line tool formed by 4 smaller CLI tools:

  • forge -> Compile, test and deploy contracts
  • cast -> Interact with blockchain though RPC calls
  • chisel -> Solidity REPL
  • anvil -> Local blockchain

In order to create a project run forge init project_name. This will create a folder like

├── lib          # all the libraries installed
├── script       # scripts folder, e.g., deploy scripts
├── src          # smart contracts folder
├── test         # tests folder
└── foundry.toml # foundry configuration file

for compiling the contract run forge build

Anatomy of a smart contract

Made out of:

  • Functions: Here we can find the constructor, which runs when program is initialized and defines certain params and additional functions that can be called

  • Data: Variables to be store data are defined when creating the contract so taht we save that space on the blockchain

There is a difference between contract accounts (where these programs are deployed) and EOAs(externally owned accounts). The latter control the contract activities. contract account can just respond to actions, not initiate them One particular component of both EOAs and SC accoutns is the nonce. It is a number that is incremented each time a tx is sent from the account. This is used to prevent replay attacks.

Links

Base EVM Architecture