TokenERC20標準 可能漏洞型別

2021-08-20 21:33:04 字數 3208 閱讀 9233

以下是tokenerc20的0.4.16的標準pragma solidity ^0.4.16;

inte***ce

tokenrecipient

contract tokenerc20

/*** internal transfer, only can be called by this contract

*/function

_transfer

(address _from, address _to, uint _value)

internal

/*** transfer tokens

** send `_value` tokens to `_to` from your account

** @param _to the address of the recipient

* @param _value the amount to send

*/function

transfer

(address _to, uint256 _value)

public

/*** transfer tokens from other address

** send `_value` tokens to `_to` on behalf of `_from`

** @param _from the address of the sender

* @param _to the address of the recipient

* @param _value the amount to send

*/function

transferfrom

(address _from, address _to, uint256 _value)

public

returns

(bool success)

/*** set allowance for other address

** allows `_spender` to spend no more than `_value` tokens on your behalf

** @param _spender the address authorized to spend

* @param _value the max amount they can spend

*/function

(address _spender, uint256 _value)

public

returns

(bool success)

/*** set allowance for other address and notify

** allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it

** @param _spender the address authorized to spend

* @param _value the max amount they can spend

*/function

(address _spender, uint256 _value, bytes _extradata)

public

returns

(bool success)

}/**

* destroy tokens

** remove `_value` tokens from the system irreversibly

** @param _value the amount of money to burn

*/function

burn

(uint256 _value)

public

returns

(bool success)

/*** destroy tokens from other account

** remove `_value` tokens from the system irreversibly on behalf of `_from`.

** @param _from the address of the sender

* @param _value the amount of money to burn

*/function

burnfrom

(address _from, uint256 _value)

public

returns

(bool success)

}在審計過程中 發現1、轉帳時判斷

require

(_to !=

0x0);的寫法換成 require

(_to !=

address(0)

);也可以

避免轉帳將幣轉丟如上圖的 _transfer 或下圖:

function 

transfer(address _to, uint256 _value) 

public 

returns (bool)

2、在0.4.20以上,為了避免重名的事件和函式引起混用,增加dao風險等事件使用 event 函式使用emit如:event burn(address indexed from, uint256 value);emit burn(_from, _value);3、建議對

newowner 進行判斷 避免空位址 將所有權更換丟//如require(newowner!= address(0));

contract owned modifier onlyowner 

function

transferownership

(address newowner)

onlyowner

public  

}中 4、事務順序依賴

5、時間依賴順序

TokenERC20合約理解

pragma solidity 0.4.19 contract tokenerc20 代幣交易轉移的內部實現 function transfer address from,address to,uint value internal 代幣交易轉移 從自己 建立交易者 賬號傳送 value 個代幣到 ...

C 20 標準簡介

早在 2020年9 月份,c 標準委會歷史上規模最大的一次會議 180人參會 在美國san diego召開,這次的會議上討論確定哪些特性要加入到c 20中,哪些特性可能加入到c 20中。c 20 國際標準草案獲得一致通過,c 之父 bjarne stroustrup 就表示 c 20是自c 11以來...

WEB2 0標準教程 CSS布局入門

css布局與傳統 table 布局最大的區別在於 原來的定位都是採用 通過 的間距或者用無色透明的gif來控制文布局版塊的間距 而現在則採用層 div 來定位,通過層的margin,padding,border等屬性來控制版塊的間距。1.定義div 分析乙個典型的定義div例子 sample 說明如...