Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn blockchain

Scale Ethereum Blockchain technology

 1. Goal of scalability Reduce the cost of using the network (blockchain has reached certain capacity limitations). Increase transaction speed (faster finality), and transaction throughput (high transactions per second), without sacrificing decentralization or security. 2. Two main solution to scale Ethereum blockchain 👉 ON-CHAIN SCALING (Sharding):  Requires changes to the Ethereum protocol (Mainnet - layer 1). Splitting the blockchain into discrete pieces (shards) to be verified by subsets of validators. 👉 OFF-CHAIN SCALING: Layer 2 scaling : derives its security and handling transactions off from Mainnet Ethereum, centered around a server or cluster of servers (referred to as a node, validator...) Transactions are rolled up into a single transaction to Mainnet Ethereum. it's two types of rollups with different security models:  Optimistic rollups and Zero-knowledge rollups. State channels : use multisig contracts to enable participants to transact quickly...

Solidity Libraries Restrictions

  Solidity have certain restrictions on use of a Library: Library functions can be called directly if they do not modify the state. That means pure or view functions only can be called from outside the library . Library can not be destroyed as it is assumed to be stateless. A Library cannot have state variables . A Library cannot inherit from any element. A Library cannot be inherited.

Fallback function

  Fallback function is a special function available to a contract. It has following features − It is called when a non-existent function is called on the contract. It is required to be marked external. It has no name. It has no arguments It can not return any thing. It can be defined one per contract. If not marked payable, it will throw exception if contract receives plain ether without data.

Pure and View Function DEV by Solidity

View functions ensure that they will not modify the state ,  compiler will throw warning in such cases: Modifying state variables. Emitting events. Creating other contracts. Using selfdestruct. Sending Ether via calls. Calling any function which is not marked view or pure. Using low-level calls. Using inline assembly containing certain opcodes Pure functions ensure that they not read or modify the state ,  compiler will throw warning in such cases. Reading state variables. Accessing address(this).balance or <address>.balance. Accessing any of the special variable of block, tx, msg (msg.sig and msg.data can be read). Calling any function not marked pure. Using inline assembly that contains certain opcodes.

[Blockchain] Globally variables

Special variables are globally available variables and provides information about the blockchain. Following is the list of special variables: Sr.No. Special Variable & Description 1 blockhash(uint blockNumber) returns (bytes32) Hash of the given block - only works for 256 most recent, excluding current, blocks. 2 block.coinbase (address payable) Current block miner's address. 3 block.difficulty (uint) current block difficulty. 4 block.gaslimit (uint) Current block gaslimit. 5 block.number (uint) Current block number. 6 block.timestamp Current block timestamp as seconds since unix epoch. 7 gasleft() returns (uint256) Remaining gas. 8 msg.data (bytes calldata) Complete calldata. 9 msg.sender (address payable) Sender of the message (current call). 10 msg.sig (bytes4) First four bytes of the calldata (i.e. function identifier) 11 msg.value (uint) Number of wei sent with the message. 12 now (uint) Current block timestamp (alias for block.timestamp). 13 tx.gasprice (uint) Gas price o...

Compare Assert and Require

  Require Assert to check input arguments from users. to check internal states that should never happen to check invariants and it evaluates to false: all remaining gas is returned. to check invariants and it evaluates to false: all gas is consumed.

Ethereum: The Difference between function transfer fund in Solidity.

Address.transfer() Address.send() Address.call.value() Address.delegatecall() Stipend of  2300  gas along. Stipend of  2300  gas along. All gas will be sent along.   Used to  transfer funds  out of a smart contract to “someAddress”. Used to  transfer funds  out of a smart contract to “someAddress”. Interact and send ether  to the “Address”. Which uses the scope of the  current calling contract  and is mostly  used for libraries . Which is a  high-level function , there is an exception happening during the transfer, it  cascading exceptions . Low-level function , there is an exception happening during the transfer, it  returns “false”. Low-level function , there is an exception happening during the transfer, it  returns “false”. Low-level function , there is an exception happening during the transfer, it  returns “false”. Safe against re-entrancy  because they ...

Difference between Ganache and Truffle

  Ganache Truffle allows you to create a private Ethereum block chain for you to run tests, execute commands, and inspect state while controlling how the chain operates. It gives you the ability to perform all actions you would on the main chain without the cost. Many developers use this to test their smart contracts during development. It provides convenient tools such as advanced mining controls and a built-in block explorer. a developer environment, testing framework and asset pipeline for block chains. It allows developers to spin up a smart contract project at the click of a button and provides you with a project structure, files, and directories that make deployment and testing much easier (or else you would have to configure these yourself). Ganache is a little different, in that it is attempting to mimic the main network. There are a few problems here: There are no miners on Ganache. Because of this...

Ethereum: Smart contract

6 Characteristic of Smart contract: 👉 A program that runs on the Ethereum blockchain (mainly developed by friendly languages: Solidity or Vyper).  Cannot be deleted, irreversible.  Deploying into main net need pay gas (must be compiled before). 👉 Have a Balance + can send transactions over the network (as a type of Ethereum account). 👉 Define rules (like a regular contract) and automatically enforce them via the code. 👉 Can call other smart contracts in your own smart contract. Can't send HTTP requests to get information about "real-world". 👉Maximum of 24KB ( refer diamond pattern: https://eips.ethereum.org/EIPS/eip-2535 Standard for creating modular smart contract systems ). 👉 Could be require multiple valid signatures to execute a transaction (Avoiding single points of failure for contracts holding substantial amounts of ether or other token). It r equires N signatures out of M possible acceptable signatures (where N ≤ M, and M > 1). Example: With N = 3, M =...

Ethereum: Proof of stake (PoS)

Proof-of-stake is a type of consensus mechanism used by blockchains to achieve distributed consensus. Within that, v alidator is then responsible for checking that new blocks propagated over the network are valid and occasionally creating and propagating new blocks themselves. 👉 VALIDATORS Must deposit 32 ETH into the deposit contract  Run three separate pieces of software: an execution client, a consensus client, and a validator. Validators receive new blocks from peers on the Ethereum network --> The transactions delivered in the block are re-executed, and the block signature is checked to ensure the block is valid --->  sends a vote (called an attestation) in favor of that block across the network. Time in proof-of-stake Ethereum is divided into slots (12 seconds) and epochs (32 slots).  Randomly selected to be a block proposer in every slot. 👉   FINALITY Using "checkpoint" blocks which first block in each epoch. 👉   CRYPTO-ECONOMIC SECURITY ...

Ethereum: proof-of-work (POW)

Proof-of-work (POW) : is the mechanism that allows the decentralized Ethereum network to come to consensus and ensure Ethereum difficult to attack.  Example about Consensus: Account balances. O rder of transactions. 💧 The work in proof-of-work 👉   Step 1:  miner will repeatedly put a dataset which get from downloading and running the full chain through a mathematical  (--> what in fact behavior to get dataset??) 👉   Step 2: dataset gets used to generate a mixHash below a target nonce, as dictated by the block difficulty. (--> How to generate mixhash and nonce from dataset) 👉   Step 3: other miners and clients to verify  (--> how to verify that nonce and mixhash are correct?) Note : explain detail how POW works: https://youtu.be/9V1bipPkCTU 💧   Proof-of-work and security Because a malicious miner can not solve the block nonce faster than everyone else, so it's nearly impossible to: Create new blocks that erase transactions,...

Ethereum: Account

2 Ethereum account type 1. External account Controlled by anyone with the private key which use to sign transactions. An account is made up of a cryptographic pair of keys: public and private .   Public key is generated from the private key using the Elliptic Curve Digital Signature Algorithm .  Public key prove that she originally initiated the transaction request.  It is possible to derive new public keys from your private key but you cannot derive a private key from public keys.  Costs nothing. Can initiate transactions. Transactions between externally-owned accounts can only be ETH/token transfers. 2. Contract account Controlled by code.  H as a cost because you're using network storage. Can only send transactions in response to receiving a transaction. Transactions from an external account to a contract account can trigger code which can execute many different actions . 👉  Both account can : Receive, hold and send ETH and tokens. Interact wi...

Ethereum: Token standard

  4 Main Ethereum token standards.

Ethereum: Denominations

Unit Wei Value Wei wei 1 wei 1 Kwei (babbage) 1e3 wei 1,000 Mwei (lovelace) 1e6 wei 1,000,000 Gwei (shannon) 1e9 wei 1,000,000,000 microether (szabo) 1e12 wei 1,000,000,000,000 milliether (finney) 1e15 wei 1,000,000,000,000,000 ether 1e18 wei 1,000,000,000,000,000,000

Ethereum: Blocks

 Blocks are batches of transactions with a hash of the previous block in the chain. 1. HOW BLOCKS WORK Strictly ordered: every new block created contains a reference to its parent block) and transactions within blocks are strictly ordered too. Once a block is put together (mined), all nodes add this block to the end of their blockchain. 2. WHAT'S IN A BLOCK? timestamp – the time when the block was mined. blockNumber – the length of the blockchain in blocks. baseFeePerGas - the minimum fee per gas required for a transaction to be included in the block. difficulty – the effort required to mine the block. mixHash – a unique identifier for that block. parentHash – the unique identifier for the block that came before (this is how blocks are linked in a chain). transactions – the transactions included in the block. stateRoot – the entire state of the system: account balances, contract storage, contract code and account nonce are inside. nonce – a hash that, when combined with...