Lecture 13: Ethereum
Code: ROM (Read-only memory) calldata: arguments
There are two types of instructions: Arithmetic 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 for msg.sender remains unchanged
Exceptions: leads to execution halting
Applications
- DB: NameCoin
- 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 executing a task in response to a change on the chain.
Use selfdestruct(beneficiary)
to kill a contract and send the leftover money to the beneficiary.