Table of Contents
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
- EIP712 is here: What to expect and how to use it | by Koh Wei Jie | MetaMask | Medium
- Gas calculation → What is EIP-1559? | Coinbase Help
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
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.
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
- ethereum - How does the opcode JUMP work in the EVM Stack? - Stack Overflow
- creationcode - What is the difference between bytecode, init code, deployed bytecode, creation bytecode, and runtime bytecode? - Ethereum Stack Exchang
- Merkle Patricia Trie | ethereum.org
- Verkle trees | ethereum.org
- Opcodes:
- Logs
- Gas
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
- Following the REMIX IDE tutorial
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 themain
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 calledState 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.
- If the function takes inputs like our
-
pure
andview
functions don’t modify the Blockchain’s state."The following statements are considered modifying the state:
- Writing to state variables / Reading from state variables.
- Emitting events.
- Creating other contracts.
- Using selfdestruct.
- Sending Ether via calls.
- Calling any function not marked view or pure.
- Using low-level calls.
- Using inline assembly that contains certain opcodes."
- Accessing
address(this).balance
or<address>.balance
. - Accessing any of the members of block, tx, msg (with the exception of
msg.sig
andmsg.data
).
-
Modifiers
andConstructors
- 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.
- A
-
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 outsidefunctions
are called State variables, and are stored instorage
.
- Variables located inside a
- Memory: Values stored in
memory
are only stored temporarily and are not on the blockchain, variables insidefunctions
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