📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有1部Youtube影片,追蹤數超過12萬的網紅prasertcbs,也在其Youtube影片中提到,ดาวน์โหลดโค้ดได้ที่ ► http://bit.ly/2Nc3gq6 เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่ ► https://www.youtube.com/subscription_center?add_user=prasertcbs สอนภ...
「c++ function argument」的推薦目錄:
c++ function argument 在 prasertcbs Youtube 的精選貼文
ดาวน์โหลดโค้ดได้ที่ ► http://bit.ly/2Nc3gq6
เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่ ► https://www.youtube.com/subscription_center?add_user=prasertcbs
สอนภาษา Python ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH4YQs9t4tf2RIYolHt_YwW
สอนภาษาไพธอน Python OOP ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEIZzlTKPUiOqkewkWmwadW
สอน Python 3 GUI ► https://www.youtube.com/playlist?list=PLoTScYm9O0GFB1Y3cCmb9aPD5xRB1T11y
สอนภาษา C เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GHHgz0S1tSyIl7vkG0y105z
สอนภาษา C++ ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEfZwqM2KyCBcPTVsc6cU_i
สอนภาษา C# ► https://www.youtube.com/playlist?list=PLoTScYm9O0GE4trr-XPozJRwaY7V9hx8K
สอนภาษา Java ► https://www.youtube.com/playlist?list=PLoTScYm9O0GF26yW0zVc2rzjkygafsILN
สอนภาษา PHP เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH_6LARFxozL_viEsXV2wgO
สอนภาษา R เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GF6qjrRuZFSHdnBXD2KVICp
#prasertcbs #prasertcbs_python
