Oko contract explorer
Contract

Code for 0xc3c2…6ba6

Since block 18112218

Verified contract

  1. /**
  2. *Submitted for verification at Etherscan.io on 2019-04-25
  3. */
  4. // guard.sol -- simple whitelist implementation of DSAuthority
  5. // Copyright (C) 2017 DappHub, LLC
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. pragma solidity ^0.4.13;
  17. contract DSAuthority {
  18. function canCall(
  19. address src, address dst, bytes4 sig
  20. ) public view returns (bool);
  21. }
  22. contract DSAuthEvents {
  23. event LogSetAuthority (address indexed authority);
  24. event LogSetOwner (address indexed owner);
  25. }
  26. contract DSGuardEvents {
  27. event LogPermit(
  28. bytes32 indexed src,
  29. bytes32 indexed dst,
  30. bytes32 indexed sig
  31. );
  32. event LogForbid(
  33. bytes32 indexed src,
  34. bytes32 indexed dst,
  35. bytes32 indexed sig
  36. );
  37. }
  38. contract DSAuth is DSAuthEvents {
  39. DSAuthority public authority;
  40. address public owner;
  41. function DSAuth() public {
  42. owner = msg.sender;
  43. LogSetOwner(msg.sender);
  44. }
  45. function setOwner(address owner_)
  46. public
  47. auth
  48. {
  49. owner = owner_;
  50. LogSetOwner(owner);
  51. }
  52. function setAuthority(DSAuthority authority_)
  53. public
  54. auth
  55. {
  56. authority = authority_;
  57. LogSetAuthority(authority);
  58. }
  59. modifier auth {
  60. require(isAuthorized(msg.sender, msg.sig));
  61. _;
  62. }
  63. function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
  64. if (src == address(this)) {
  65. return true;
  66. } else if (src == owner) {
  67. return true;
  68. } else if (authority == DSAuthority(0)) {
  69. return false;
  70. } else {
  71. return authority.canCall(src, this, sig);
  72. }
  73. }
  74. }
  75. contract DSGuard is DSAuth, DSAuthority, DSGuardEvents {
  76. bytes32 constant public ANY = bytes32(uint(-1));
  77. mapping (bytes32 => mapping (bytes32 => mapping (bytes32 => bool))) acl;
  78. function canCall(
  79. address src_, address dst_, bytes4 sig
  80. ) public view returns (bool) {
  81. var src = bytes32(src_);
  82. var dst = bytes32(dst_);
  83. return acl[src][dst][sig]
  84. || acl[src][dst][ANY]
  85. || acl[src][ANY][sig]
  86. || acl[src][ANY][ANY]
  87. || acl[ANY][dst][sig]
  88. || acl[ANY][dst][ANY]
  89. || acl[ANY][ANY][sig]
  90. || acl[ANY][ANY][ANY];
  91. }
  92. function permit(bytes32 src, bytes32 dst, bytes32 sig) public auth {
  93. acl[src][dst][sig] = true;
  94. LogPermit(src, dst, sig);
  95. }
  96. function forbid(bytes32 src, bytes32 dst, bytes32 sig) public auth {
  97. acl[src][dst][sig] = false;
  98. LogForbid(src, dst, sig);
  99. }
  100. function permit(address src, address dst, bytes32 sig) public {
  101. permit(bytes32(src), bytes32(dst), sig);
  102. }
  103. function forbid(address src, address dst, bytes32 sig) public {
  104. forbid(bytes32(src), bytes32(dst), sig);
  105. }
  106. }
  107. contract DSGuardFactory {
  108. mapping (address => bool) public isGuard;
  109. function newGuard() public returns (DSGuard guard) {
  110. guard = new DSGuard();
  111. guard.setOwner(msg.sender);
  112. isGuard[guard] = true;
  113. }
  114. }

Contract sourced from Etherscan. Solidity version v0.4.25+commit.59dbf8f1.

Panoramix decompilation

# Palkeoramix decompiler. 

const ANY = -1

def storage:
  authorityAddress is address at storage 0
  owner is address at storage 1
  stor2 is mapping of uint8 at storage 2

def owner(): # not payable
  return owner

def authority(): # not payable
  return authorityAddress

#
#  Regular functions
#

def _fallback(?) payable: # default function
  revert

def setOwner(address _newOwner): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  owner = _newOwner
  log LogSetOwner(address owner=owner)

def setAuthority(address authority_): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  authorityAddress = authority_
  log LogSetAuthority(address authority=authorityAddress)

def forbid(bytes32 src, bytes32 dst, bytes32 sig): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  stor2[src][dst][sig] = 0
  log LogForbid(
        bytes32 src=src,
        bytes32 dst=dst,
        bytes32 sig=sig)

def permit(bytes32 src, bytes32 dst, bytes32 sig): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  stor2[src][dst][sig] = 1
  log LogPermit(
        bytes32 src=src,
        bytes32 dst=dst,
        bytes32 sig=sig)

def forbid(address src, address dst, bytes32 sig): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  stor2[address(src)][address(dst)][sig] = 0
  log LogForbid(
        bytes32 src=src,
        bytes32 dst=dst,
        bytes32 sig=sig)

def permit(address src, address dst, bytes32 sig): # not payable
  if this.address != caller:
      if owner != caller:
          require authorityAddress
          require ext_code.size(authorityAddress)
          call authorityAddress.canCall(address _src, address _dst, bytes4 _sig) with:
               gas gas_remaining wei
              args caller, address(this.address), call.func_hash
          if not ext_call.success:
              revert with ext_call.return_data[0 len return_data.size]
          require return_data.size >= 32
          require ext_call.return_data[0]
  stor2[address(src)][address(dst)][sig] = 1
  log LogPermit(
        bytes32 src=src,
        bytes32 dst=dst,
        bytes32 sig=sig)

def canCall(address _src, address _dst, bytes4 _sig): # not payable
  if stor2[address(_src)][address(_dst)][Mask(32, 224, _sig)]:
      return bool(stor2[address(_src)][address(_dst)][Mask(32, 224, _sig)])
  if stor2[address(_src)][address(_dst)][-1]:
      return bool(stor2[address(_src)][address(_dst)][-1])
  if stor2[address(_src)][-1][Mask(32, 224, _sig)]:
      return bool(stor2[address(_src)][-1][Mask(32, 224, _sig)])
  if stor2[address(_src)][-1][-1]:
      return bool(stor2[address(_src)][-1][-1])
  if stor2[-1][address(_dst)][Mask(32, 224, _sig)]:
      return bool(stor2[-1][address(_dst)][Mask(32, 224, _sig)])
  if stor2[-1][address(_dst)][-1]:
      return bool(stor2[-1][address(_dst)][-1])
  if stor2[-1][-1][Mask(32, 224, _sig)]:
      return bool(stor2[-1][-1][Mask(32, 224, _sig)])
  return bool(stor2[-1][-1][-1])

Decompilation generated by Panoramix.

Raw bytecode

0x6080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806313af4035146100a95780632bc3217d146100ec57806379d88d871461015d5780637a9e5e4b146101aa5780638da5cb5b146101ed578063a8542f6614610244578063b700961314610277578063bf7e214f1461031b578063cbeea68c14610372578063f0217ce5146103e3575b600080fd5b3480156100b557600080fd5b506100ea600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610430565b005b3480156100f857600080fd5b5061015b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035600019169060200190929190505050610512565b005b34801561016957600080fd5b506101a8600480360381019080803560001916906020019092919080356000191690602001909291908035600019169060200190929190505050610554565b005b3480156101b657600080fd5b506101eb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610633565b005b3480156101f957600080fd5b50610202610713565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561025057600080fd5b50610259610739565b60405180826000191660001916815260200191505060405180910390f35b34801561028357600080fd5b50610301600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19169060200190929190505050610760565b604051808215151515815260200191505060405180910390f35b34801561032757600080fd5b50610330610cc1565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561037e57600080fd5b506103e1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035600019169060200190929190505050610ce6565b005b3480156103ef57600080fd5b5061042e600480360381019080803560001916906020019092919080356000191690602001909291908035600019169060200190929190505050610d28565b005b61045e336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e07565b151561046957600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fce241d7ca1f669fee44b6fc00b8eba2df3bb514eed0f6f668f8f89096e81ed9460405160405180910390a250565b61054f8373ffffffffffffffffffffffffffffffffffffffff166001028373ffffffffffffffffffffffffffffffffffffffff1660010283610554565b505050565b610582336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e07565b151561058d57600080fd5b6000600260008560001916600019168152602001908152602001600020600084600019166000191681526020019081526020016000206000836000191660001916815260200190815260200160002060006101000a81548160ff0219169083151502179055508060001916826000191684600019167f95ba64c95d85e67ac83a0476c4a62ac2cf8ab2d0407545b8c9d79c3eefa6282960405160405180910390a4505050565b610661336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e07565b151561066c57600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f1abebea81bfa2637f28358c371278fb15ede7ea8dd28d2e03b112ff6d936ada460405160405180910390a250565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60010281565b60008060008573ffffffffffffffffffffffffffffffffffffffff1660010291508473ffffffffffffffffffffffffffffffffffffffff166001029050600260008360001916600019168152602001908152602001600020600082600019166000191681526020019081526020016000206000857bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191660001916815260200190815260200160002060009054906101000a900460ff168061089857506002600083600019166000191681526020019081526020016000206000826000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060009054906101000a900460ff165b80610938575060026000836000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600102600019166000191681526020019081526020016000206000857bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191660001916815260200190815260200160002060009054906101000a900460ff165b806109e0575060026000836000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060009054906101000a900460ff165b80610a805750600260007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60010260001916600019168152602001908152602001600020600082600019166000191681526020019081526020016000206000857bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191660001916815260200190815260200160002060009054906101000a900460ff165b80610b285750600260007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600102600019166000191681526020019081526020016000206000826000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060009054906101000a900460ff165b80610beb5750600260007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600102600019166000191681526020019081526020016000206000857bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191660001916815260200190815260200160002060009054906101000a900460ff165b80610cb65750600260007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001026000191660001916815260200190815260200160002060009054906101000a900460ff165b925050509392505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610d238373ffffffffffffffffffffffffffffffffffffffff166001028373ffffffffffffffffffffffffffffffffffffffff1660010283610d28565b505050565b610d56336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e07565b1515610d6157600080fd5b6001600260008560001916600019168152602001908152602001600020600084600019166000191681526020019081526020016000206000836000191660001916815260200190815260200160002060006101000a81548160ff0219169083151502179055508060001916826000191684600019167f6f50375045128971c5469d343039ba7b8e30a5b190453737b28bda6f7a30677160405160405180910390a4505050565b60003073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610e465760019050611078565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610ea55760019050611078565b600073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610f045760009050611078565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b70096138430856040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681526020019350505050602060405180830381600087803b15801561103a57600080fd5b505af115801561104e573d6000803e3d6000fd5b505050506040513d602081101561106457600080fd5b810190808051906020019092919050505090505b929150505600a165627a7a7230582046fda457ecfe17c7abb4819d79cdddb596634e1bdacfbcb2178c795c9fa363ad0029