深入解析Solidity合約

yaohsin
yaohsin
Jan 4 · 10 min read

EtherDice v1
608060405267016345785d8a00003411151561001a57600080fd5b610332806100296000396000f3fe608060405260043610610051576000357c010000000000000000000000000000000000000000000000000000000090048063026b1d5f146100565780637365870b14610081578063cd5e3c5d146100c7575b600080fd5b34801561006257600080fd5b5061006b6100f2565b6040518082815260200191505060405180910390f35b6100ad6004803603602081101561009757600080fd5b8101908080359060200190929190505050610111565b604051808215151515815260200191505060405180910390f35b3480156100d357600080fd5b506100dc6102f2565b6040518082815260200191505060405180910390f35b60003073ffffffffffffffffffffffffffffffffffffffff1631905090565b6000808210158015610124575060058211155b1515610198576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f5f6e756d626572206973206265747765656e203020746f20350000000000000081525060200191505060405180910390fd5b60006101a26102f2565b905080831415610273573373ffffffffffffffffffffffffffffffffffffffff166108fc600234029081150290604051600060405180830381858888f193505050501580156101f5573d6000803e3d6000fd5b507f19d7eac3f3db644d690a8b91f7e31894dbc050a6dbf885c516ccb3dc99ef3241838233604051808481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001935050505060405180910390a160019150506102ed565b7f19d7eac3f3db644d690a8b91f7e31894dbc050a6dbf885c516ccb3dc99ef324183826000604051808481526020018381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001935050505060405180910390a160009150505b919050565b600060064281151561030057fe5b0690509056fea165627a7a723058207764b48131629493d8b87c2587e91375b785aefcae2d01c52340f658ab33a8600029
合約編譯後的byte code的圖示
Runtime部分

function roll() public view returns(uint) {        
return (block.timestamp % 6);
}
攻擊合約
assembly { size := extcodesize(addr) }
EtherDice v2
攻擊合約 v2

Taipei Ethereum Meetup

台北以太坊社群專欄

yaohsin

Written by

yaohsin

software engineer and dad.

Taipei Ethereum Meetup

台北以太坊社群專欄