Posted on :: 1276 Words :: Tags: ,

Ethereum

Glossary

The Ethereum organization proposes some specs or improvements EIPs , this specs are what Architecture means for hardware*.*

Updates are released when a certain block height is met. All execution clients agree on the height.

Accounts → Difference between Externally Owned Account and Contract Account. selfdestruct - Redeploy a smart contract on the same address - Ethereum Stack Exchange

ERC-1271: Standard Signature Validation Method for Contracts

Types of Tx accepted by zkSync → EIP-712: Typed structured data hashing and signing

System Contracts → Contracts that provide general purpose code, some interact with the L1 like Diamond. Contract’s events:

You should emit an event anytime something occurs in your smart contract that some system outside the blockchain should be aware of so that the outside system may listen for such occurrences

What are Paymasters?

Gas Refund

ommer blocks

optional access lists

Rollups:

  • Optimistic
  • zk Rollups
    • Validium → Proofs are not stored on the blockchain.
    • Sometimes, a merkletree that contains all the transactions hashes is built and then the root composes the zk Proof that is later stored on the L1.

Rollup operation requires the assistance of an operator, who rolls transactions together, computes a zero-knowledge proof of the correct state transition, and affects the state transition by interacting with the rollup contract.

Sharding

zkEVM → Solves the problem of creating a general purpose verifier. Taking into account that the circuit (Arithmetization of the problem) has to be fixed in order to verify proofs, the idea is to have a so called Virtual Machine that operates like a processor whose proof takes into account each step of the execution.

  • TinyRAM inspires the zkSync’s zkEVM
  • How is the zkEVM compatible with Solidity? Solidity → compiles to → Yul → compiles to LLVM → Then the bytecode is interpreted by the zkEVM.

EVM

EVM Deep Dives: The Path to Shadowy Super Coder 🥷 💻 - Part 1

EVM Deep Dives: The Path to Shadowy Super Coder 🥷 💻 - Part 2

MISC

How to convert eth gas price in gwei to $. : r/ethereum:

1 ETH = 1e18 wei

1 Gwei (for giga wei) = 1e9wei = 0.000000001 ETH

A standard transaction costs 21_000 gas.

Assume gas price 131 gwei

131 gwei/gas * 21_000 gas = 2_751_000 gwei = 0.002751 ETH

Yul | EVM's "Assembly" lang

ZK Rollups

Blogposts:

Solidity

Kick off Contract:

// SPDX-License-Identifier: MIT // <-- License
pragma solidity ^0.8.0; // <-- Specify version

contract SimpleStorage {
    // State variable, stored in the Blockchain
    uint public n; // It is initialized to 0

    // A transaction is needed to change the state variable.
    function set(uint _n) public {
        n = _n;
    }

    // To read the variable you don't need to send a transaction.
    function get() public view returns (uint) {
        return n;
    }
    
    // Pure functions neither read nor write the Blockchain's state
    function add(uint i, uint j) public pure returns (uint) {
        return i + j;
    }
}
  • Solidity interprets the Contract keyword as the “entry point”, just like the main function in a programming language.

  • Smart Contracts are atomic, if one operation fails, the entire operation is reverted without altering the Blockchain’s state.

  • The variables that are outside functions are stored in the Blockchain. And are called State variables . A scheme of “getters” and “setters” is used.

    • If the function takes inputs like our set function (line 9), you must specify the parameter types and names. A common convention is to use an underscore as a prefix for the parameter name to distinguish them from state variables.
  • pure and view functions don’t modify the Blockchain’s state.

    "The following statements are considered modifying the state:

    1. Writing to state variables / Reading from state variables.
    2. Emitting events.
    3. Creating other contracts.
    4. Using selfdestruct.
    5. Sending Ether via calls.
    6. Calling any function not marked view or pure.
    7. Using low-level calls.
    8. Using inline assembly that contains certain opcodes."
    9. Accessing address(this).balance or <address>.balance.
    10. Accessing any of the members of block, tx, msg (with the exception of msg.sig and msg.data).
  • Modifiers and Constructors

    • A Constructor is called the first time the contract is deployed.
    • A Modifier is used to change the behavior of a function, in other words, it checks some parameters and executes the function. An _ (underscore) is used to symbolize the function’s code: The code you place before the underscore in the modifier will be executed before the code in the body of the modified function. The code after the underscore will be executed after the code in the body of the modified function. require keyword.
  • Function visibilty:

    • private: only inside the contract
    • internal: inside the contract and by child contract
    • public: inside contract, child contract and other contracts or transactions
    • external: only called by other contracts or transactions, state variables can not be external
  • What are the virtual and override keywords in Solidity? - Ethereum Stack Exchange

  • DataTypes

    • Arrays
    • Enums
    • Structs
    • Mappings (Used to store values related to an address)
      • mapping(address => uint) balance;
      • Accessing: balance[_addr];
      • Nested mappings are allowed.
  • DataLocations

    • When to use Storage vs. Memory vs. Calldata in Solidity
    • Storage: stores the data permanently on the Blockchain
      • Variables located inside a contract but outside functions are called State variables, and are stored in storage .
    • Memory: Values stored in memory are only stored temporarily and are not on the blockchain, variables inside functions are stored in memory, sometimes the keyword is needed to specify which type of DataLocation is needed.
    • Calldata: stores function arguments. The data is stored temporarily and cannot be mutated.
    • Assignments:
      • Memory to Memory: This creates a reference.
      • “Global” Storage to “Local” Storage: This creates a reference.
      • Storage and Memory/Calldata: This creates a copy.
    • .selector go ethereum - explanation of appending .selector in solidity smart contracts - Ethereum Stack Exchange

SPDX licenses

Cheatsheet