2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Solidity] バージョン0.7.0のProxy contract

Last updated at Posted at 2020-09-28

はじめに

備忘録です。

詳しい説明などは以下記事か「アップグレード可能なsolidityコード」で検索。

Solidityのダイヤモンドスタンダードの提案にもっと詳しい説明もあります。

コード

Proxy.sol
pragma solidity ^0.7.0;

contract Proxy {
  address public implementation;

  function upgradeTo(address _address) public {
    implementation = _address;
  }

  // fallback function
  fallback () payable external {
    address _impl = implementation;
    require(_impl != address(0));

    assembly {
      let ptr := mload(0x40)
      calldatacopy(ptr, 0, calldatasize())
      let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
      let size := returndatasize()
      returndatacopy(ptr, 0, size)

      switch result
      case 0 { revert(ptr, size) }
      default { return(ptr, size) }
    }
  }
}

変わったところ

  • fallback関数の表記方法が無名関数からfallback()になった
  • assembly内のYulコードの以下が関数となり()が必要になった。
    • gas -> gas()
    • calldatasize -> calldatasize()
    • returndatasize -> returndatasize()

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?