L2 Smart Contracts

Smart Contracts

 

Function(s) within a System that arbitrarily move digital assets according to pre-specified rules or parameters.1

 

  1. Contracts
  2. ETH Token
  3. Deployment
  4. Use-Cases
  5. OP Codes

 

 

Essentially it is a set of: if, else, or else conditionals

Application State Data

Account State Data

 

 

Contracts

 

An Immutable Program

 

Containing a specific set of code functions and app data that reside on the chain

This can include logical, conditional, comparison, arithmetic or bit operations

 

 

ETH Token

 

Ether is the network cost unit, the currency of the Ethereum blockchain.

In essence, it is the fuel for running programs on the chain. Think of it as the “Gas”.

 

  • Gas represents the fee paid to miners in exchange for their computational costs
  • Gas mitigates spam and abuse with the high costs of computation

 

 

Wei is the name for the smallest unit of Ether

 

1 ether = 1,000,000,000,000,000,000 wei

1 ETH = 1e18 wei

 

 

ERC20

A Common Token Contract2 deployed on the Ethereum platform for crowdfunding ICOs.

 

Being a contract, the use of those Tokens incurs the computational costs of using Ethereum.

In order to use those Tokens, you still have to pay the transaction fee(s) in Ether.

Deployment

 

A Smart Contract is Deployed to The Blockchain by Sending a Transaction Containing the Contract’s Code for its Data to an Unused Address.

 

 

Deployable Contract Highlights:

 

  • Ownership

 

  • Transaction Format

 

  • State Transition Functions [STF]

 

 

[STF] Order of Operations:

 

  1. Check if all the values are in the correct format, if the necessary stuff is filled in, that the signature is valid, and if the nonce value (the random number value) matches the nonce value in the sender’s account

 

  1. Calculate the fee, who the sender is, then subtract that fee from the sender account, and increment the nonce value of the sender (the reason this number is incremented or adjusted is for security purposes -> this guarantees that each function will always compute a different result)

 

  1. Assign the STARTGAS value to the GAS variable, GAS = STARTGAS. This starts up the computation that pays for the transaction and then it removes the total gas/byte to pay for the transaction

 

  1. Transfers the value from the sending account to the receiving account

 

  1. If the receiver doesn’t exist, then it creates one
  2. If the receiver is a contract then execute the code in the contract. The contract will then run until it is complete or it runs out of GAS, (GAS= 0)

 

  1. If the transfer fails then everything is reverted except the fees still get paid to the miner who tried to execute it for you

 

  1. If the transfer is successful then it will pay the fees (GAS) incurred to the miner, and if there’s any extra leftover it will also return that to the sender

 

 

Standard OP Functions:

 

CALL _> produces a Message Object and Executes its conditions (i.e. send ether from a to b)

CREATE _> produces a new Smart Contract

Sender Pays:

The Sender always pays _> Contracts cannot pay for their own Deployment and Execution

Contracts can be Senders _> Contracts can pay to deploy and execute their own Contracts

 

 

When a Contract creates its own Contract all the same rules apply;

 

  • It’s formed correctly
  • The parent Contract’s random nonce is incremented
  • It must have enough GAS to execute it
  • The fees are deducted regardless if it’s successful.

 

 

Use-Cases

 

Custom Tokens

Create a new Cryptocurrency

 

Crowd Sales

Create a Decentralized Fundraising Campaign

 

Decentralized Autonomous Organizations (DAOs)

Long term smart contract

Contains the assets and/or the encoded bylaws of an organization

 

 

OP Codes

 

Operation Code for the Machine Language Executable Instructions

 

Environmental Information

CALLVALUE

CODESIZE

BALANCE

 

Block Information

TIMESTAMP

COINBASE

BLANCE

 

System

CALL

CALLCODE

SELFDESTRUCT