[爆卦]Uint32是什麼?優點缺點精華區懶人包

雖然這篇Uint32鄉民發文沒有被收入到精華區:在Uint32這個話題中,我們另外找到其它相關的精選爆讚文章

在 uint32產品中有1篇Facebook貼文,粉絲數超過3,460的網紅Taipei Ethereum Meetup,也在其Facebook貼文中提到, 📜 [專欄新文章] Solidity Weekly #10 ✍️ mingderwang 📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium keccak256(abi.encodePac...

  • uint32 在 Taipei Ethereum Meetup Facebook 的最佳解答

    2018-09-02 06:09:35
    有 5 人按讚


    📜 [專欄新文章] Solidity Weekly #10
    ✍️ mingderwang
    📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium

    keccak256(abi.encodePacked(…))

    最近如果你使用 solidity 0.4.24 以上版本編譯; 用到一些 hash functions 例如keccak256()、sha256() 或 ripemd160(),如果你帶入多個參數 (例如 keccak256(“a”, “b”, “c”)),你會看到如下的警示:

    Warning: This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. keccak256( ^ (Relevant source part starts here and spans across multiple lines)

    原因是,以前這些 functions 可以接受多個參數,連在ㄧ起後做一個 hash,但由於不同值在預設 type 被自動 padding 會有不同的結果,再加上多個參數串起來,容易出現不同的 hash 結果, 造成 bugs。所以決定 0.5.0 以後改只接受一個參數。因此,可以利用 abi.encodePacked() 先做一次包裝,再當成一個參數進行 hash。

    補充說明,所謂的 padding 就是用 0 填滿到 bytes32 的格式,最典型的例子就是 call 一個function,裡面的參數(parameters) 就會被轉型成 bytes32 格式。

    0x0000000000000000000000000000000000000000000000000000000000000045:

    a uint32 value 69 padded to 32 bytes

    0x0000000000000000000000000000000000000000000000000000000000000001:

    boolean true, padded to 32 bytes

    0x6162630000000000000000000000000000000000000000000000000000000000:

    a bytes3 value "abc" 會被靠左對齊成 32 bytes

    links 分享;

    ERC20 API: An Attack Vector on Approve/TransferFrom Methods — (Mikhail Vladimirov, Dmitry Khovratovich)

    ERC-1155: The Crypto Item Standard — (Witek Radomski)

    *適用於 solidity ^0.4.24;

    Solidity Weekly #10 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.

    👏 歡迎轉載分享鼓掌

你可能也想看看

搜尋相關網站