Solidity

Solidity keccak256(‘contract.storage.initialized’)

  • January 13, 2018

嗨,我正在搜尋可升級/可升級的契約,然後我找到了 David Rugendyke 的這個 Rocket Pool https://gist.github.com/darcius/6e8fa4faa6d9139f3950b6f1d9e96038

/// @dev Only allow access from the latest version of a contract in the Rocket Pool network after deployment

modifier onlyLatestRocketNetworkContract() {

   /* The owner is only allowed to set the storage upon deployment 
   to register the initial contracts, afterwards their direct access is disabled
   only allow the owner of the storage contract to access these methods directly to set 
   some initial contract addresses during deployment, 
   after deployment their access is removed to ensure only visible contract methods 
   can write to storage. From then on, only registered contracts within the Rocket Pool network 
   can write to storage.
    */

   if (msg.sender == owner) {
       require(boolStorage[keccak256("contract.storage.initialised")] == false);
   } else {
       // Make sure the access is permitted to only contracts in our Dapp
       require(addressStorage[keccak256("contract.address", msg.sender)] != 0x0);
   }
   _;
}

有人可以幫我理解這兩行:

keccak256(“contract.storage.initialised”)

keccak256(“contract.address”, msg.sender)

http://solidity.readthedocs.io/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions

我知道 keccak256(…) 或 sha3(…) 計算乙太坊- (緊密打包的)參數的 SHA-3 (Keccak-256) 雜湊,然後返回 (bytes32)

但我找不到關於“.initialized”的任何參考資料謝謝

正如@smarx 提到的,在這種情況下,字元串完全是任意的。Keccak256 的用途是能夠以程式方式比較字元串。

如何比較牢固的字元串?

function compareStrings (string a, string b) view returns (bool){
      return keccak256(a) == keccak256(b);
  }

引用自:https://ethereum.stackexchange.com/questions/36138