Stanford CS251: Lecture 13

Lecture 13: Etherum

Code: ROM (Read-only memory) calldata: arguments

There are two types of instructions: Arithmatic including SHA3 and sys operations like create [contract], call [contract], and delegate call etc.

CALL – called code is executed in the context of called contract
CALLLOAD – called code is executed in the context of the current contract, msg.sender is calling contract
DELEGATECALL – similar to callload except msg.sender remains unchanged

Exceptions: leads to execution halting

Applications

  1. DB: NameCoin
  2. Auctions: decentralized eBay but since everything is public, requires commitments to have sealed bid auctions.

How to safely transfer funds?

check-effects-interaction paradigm

if (amount > 0) {  // check
    pendingReturns[msg.sender] = 0;  // effects
    if (!msg.sender.send(amount)) {  // interaction
        pendingReturns[msg.sender] = amount;
        return false; 
    }
}

Events can be used for getting callbacks and execute a task in response to a change on the chain.

Use selfdestruct(beneficiary) to kill a contract and send the leftover money to beneficiary.

One Reply to “Stanford CS251: Lecture 13”

Leave a Reply

Your email address will not be published. Required fields are marked *