Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Update contracts to Solidity 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
madis committed Jul 15, 2022
1 parent dd1b560 commit e7ee43c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 95 deletions.
2 changes: 1 addition & 1 deletion browser-test/all.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(def gas-limit 4500000)

(def contract-source "
pragma solidity ^0.4.6;
pragma solidity ^0.8.0;
contract test {
function multiply(uint a) returns(uint d) {
Expand Down
5 changes: 3 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pragma solidity ^0.4.23;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
constructor() {
owner = msg.sender;
}

Expand Down
7 changes: 4 additions & 3 deletions contracts/MyContract.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.18;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

contract MyContract {

Expand All @@ -9,11 +10,11 @@ contract MyContract {
event SetCounterEvent(uint previousValue, uint newValue);
/* event SpecialEvent(uint someParam); */

constructor(uint _counter) public {
constructor(uint _counter) {
counter = _counter;
}

function myPlus(uint a, uint b) public constant returns (uint) {
function myPlus(uint a, uint b) public pure returns (uint) {
return a + b;
}

Expand Down
96 changes: 42 additions & 54 deletions contracts/auth/DSAuth.sol
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// SPDX-License-Identifier: GNU-3
pragma solidity >=0.4.23;

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.4.13;

contract DSAuthority {
function canCall(
address src, address dst, bytes4 sig
) public view returns (bool);
interface DSAuthority {
function canCall(
address src, address dst, bytes4 sig
) external view returns (bool);
}

contract DSAuthEvents {
event LogSetAuthority (address indexed authority);
event LogSetOwner (address indexed owner);
event LogSetAuthority (address indexed authority);
event LogSetOwner (address indexed owner);
}

contract DSAuth is DSAuthEvents {
DSAuthority public authority;
address public owner;
DSAuthority public authority;
address public owner;

function DSAuth() public {
owner = msg.sender;
LogSetOwner(msg.sender);
}
constructor() {
owner = msg.sender;
emit LogSetOwner(msg.sender);
}

function setOwner(address owner_)
public
auth
{
owner = owner_;
LogSetOwner(owner);
}
function setOwner(address owner_)
public
auth
{
owner = owner_;
emit LogSetOwner(owner);
}

function setAuthority(DSAuthority authority_)
public
auth
{
authority = authority_;
LogSetAuthority(authority);
}
function setAuthority(DSAuthority authority_)
public
auth
{
authority = authority_;
emit LogSetAuthority(address(authority));
}

modifier auth {
require(isAuthorized(msg.sender, msg.sig));
_;
}
modifier auth {
require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized");
_;
}

function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
if (src == address(this)) {
return true;
} else if (src == owner) {
return true;
} else if (authority == DSAuthority(0)) {
return false;
} else {
return authority.canCall(src, this, sig);
function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
if (src == address(this)) {
return true;
} else if (src == owner) {
return true;
} else if (authority == DSAuthority(address(0))) {
return false;
} else {
return authority.canCall(src, address(this), sig);
}
}
}
}
37 changes: 13 additions & 24 deletions contracts/auth/DSGuard.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
// guard.sol -- simple whitelist implementation of DSAuthority

// Copyright (C) 2017 DappHub, LLC

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.4.13;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import "../auth/DSAuth.sol";

Expand All @@ -33,14 +18,18 @@ contract DSGuardEvents {
}

contract DSGuard is DSAuth, DSAuthority, DSGuardEvents {
bytes32 constant public ANY = bytes32(uint(- 1));
bytes32 constant public ANY = bytes32(uint256(0x01));
mapping(bytes32 => mapping(bytes32 => mapping(bytes32 => bool))) acl;

function toBytes(address addr) public pure returns (bytes32) {
return bytes32(uint256(uint160(addr)) << 96);
}

function canCall(
address src_, address dst_, bytes4 sig
) public view returns (bool) {
bytes32 src = bytes32(src_);
bytes32 dst = bytes32(dst_);
) public view override returns (bool) {
bytes32 src = toBytes(src_);
bytes32 dst = toBytes(dst_);

return acl[src][dst][sig]
|| acl[src][dst][ANY]
Expand All @@ -63,11 +52,11 @@ contract DSGuard is DSAuth, DSAuthority, DSGuardEvents {
}

function permit(address src, address dst, bytes32 sig) public {
permit(bytes32(src), bytes32(dst), sig);
permit(toBytes(src), toBytes(dst), sig);
}

function forbid(address src, address dst, bytes32 sig) public {
forbid(bytes32(src), bytes32(dst), sig);
forbid(toBytes(src), toBytes(dst), sig);
}
}

Expand All @@ -77,6 +66,6 @@ contract DSGuardFactory {
function newGuard() public returns (DSGuard guard) {
guard = new DSGuard();
guard.setOwner(msg.sender);
isGuard[guard] = true;
isGuard[address(guard)] = true;
}
}
11 changes: 6 additions & 5 deletions contracts/proxy/DelegateProxy.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
pragma solidity ^0.4.18;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

contract DelegateProxy {
/**
* @dev Performs a delegatecall and returns whatever the delegatecall returned (entire context execution will return!)
* @param _dst Destination address to perform the delegatecall
* @param _calldata Calldata for the delegatecall
*/
function delegatedFwd(address _dst, bytes _calldata) internal {
function delegatedFwd(address _dst, bytes memory _calldata) internal {
require(isContract(_dst));
assembly {
let result := delegatecall(sub(gas, 10000), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)
let size := returndatasize
let result := delegatecall(sub(gas(), 10000), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)
let size := returndatasize()

let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
Expand All @@ -27,4 +28,4 @@ contract DelegateProxy {
assembly {size := extcodesize(_target)}
return size > 0;
}
}
}
10 changes: 7 additions & 3 deletions contracts/proxy/Forwarder.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.18;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import "../proxy/DelegateProxy.sol";

Expand All @@ -9,7 +10,10 @@ contract Forwarder is DelegateProxy {
/*
* @dev Forwards all calls to target
*/
function() payable {
fallback() external payable {
delegatedFwd(target, msg.data);
}
}

receive() external payable {
}
}
10 changes: 7 additions & 3 deletions contracts/proxy/MutableForwarder.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.4.18;
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import "../proxy/DelegateProxy.sol";
import "../auth/DSAuth.sol";
Expand Down Expand Up @@ -27,8 +28,11 @@ contract MutableForwarder is DelegateProxy, DSAuth {
target = _target;
}

function() payable {
fallback() external payable {
delegatedFwd(target, msg.data);
}

}
receive() external payable {
}

}

0 comments on commit e7ee43c

Please sign in to comment.