Skip to content

Instantly share code, notes, and snippets.

MiniMeToken

MiniMeToken does not use Truffle framework.

Directory structure

project
│───build
│───contracts
│───js
└───test

Truffle docs

Creating Project

> mkdir MetaCoin
> cd MetaCoin
> truffle unbox metacoin
  • library를 사용하면 modular, reusable elegant한 contract를 짤 수 있다.

Solidity is a limited language

  • standard library가 아직 개발되지 않았다.
  • deployed contract는 업그레이드할 수 없다.
  • EVM 외부에서 data를 가져올 수 없다. 이는 Oracle을 포함하는 트랜잭션을 날려야만 가능하다.

What is a Library

  • library는 contract와는 다른 type이다.

Onward with Ethereum Smart Contract Security

before starting

smart contract security를 improve해주는 전략과 이 전략을 따르지 않았을 때 문제가 발생할 수 있는 코드를 함께 제시한다. 또한 smart contract를 protect할 수 있는 방법에 대한 코드도 함께 제시한다.

Fail as early and loudly as possible

  • code가 silently하게 fail하는 것을 피해야 한다. 또한 unstable하거나 inconsistent한 state로 실행이 계속되는 것을 피해야 한다.

참고

sending a transaction costs 21000 gas

A recipient contract's fallback function only gets a 2300 gas stipend if it was invoked with recipient.transfer or recipient.send

fallback 함수가 호출되는 여러 경우가 있는데 그 중 receiver.send 함수 또는 receiver.transfer 함수로 인해 receiver의 fallback 함수가 호출된다. 이 때 fallback 함수 호출과 함께 2300gas를 봉급으로 주어지게 된다.

This is the same as an external account paying recipient with web3.eth.sendTransaction({to:recipient, gas:21000, ...}).

Solidity Types

Value Types

  • bool
  • int / uint
    • int8 to int256 in steps of 8
    • uint8 to uint256 in steps of 8
  • fixed / ufixed
    • fixedMxN / ufixedMxN : M must be divisible by 8 and goes from 8 to 256 bits. N must be between 0 and 80.

Parity Multisig Hacked

address of sender

contract A {
    B b;

    function A(address _b) public {
        b = B(_b);
    }

Hex Prefix encoding

What are the differences between RLP and HP encoding? How does HP encoding work?

Root: {1: 'Dog', 2: B, 3: A}
A: {1: C, 2: D, 3: 'Cat'}
B: {1: 'Goat', 2: 'Bear', 3: 'Rat'}
C: {1: 'Eagle', 2: 'Parrot', 3: E}
D: {1: 'Shark', 2: 'Dolphin', 3: 'Whale'}
E: {1: 'Duck', 2: 'Chicken', 3: 'Pig'}