-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from dodger213/experimental/v1.4.1-yul-test
Safe yul compatibility with test suite
- Loading branch information
Showing
17 changed files
with
256 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
JQ ?= jq | ||
|
||
SAFEYULROOT ?= | ||
SAFEYULBASE := build/yul/Safe.json | ||
SAFEYUL := $(SAFEYULROOT)/$(SAFEYULBASE) | ||
|
||
contracts/SafeBytecode.sol: $(SAFEYUL) | ||
@echo '// SPDX-License-Identifier: LGPL-3.0-only' >$@ | ||
@echo 'pragma solidity >=0.7.0 <0.9.0;' >>$@ | ||
@echo '' >>$@ | ||
@echo 'contract SafeBytecode {' >>$@ | ||
@echo ' bytes public constant DEPLOYED_BYTECODE =' >>$@ | ||
@echo ' hex$(shell $(JQ) '.evm.deployedBytecode.object' $<);' >>$@ | ||
@echo '}' >>$@ | ||
|
||
.PHONY: $(SAFEYUL) | ||
$(SAFEYUL): | ||
@test -n "$(SAFEYULROOT)" || ( echo 'SAFEYULROOT not specified'; exit 1 ) | ||
@$(MAKE) -C $(SAFEYULROOT) $(SAFEYULBASE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract SafeFallbackAccessor { | ||
address private constant _SENTINEL = address(1); | ||
|
||
address private _singleton; | ||
mapping(address => address) private _modules; | ||
mapping(address => address) private _owners; | ||
uint256 private _ownerCount; | ||
uint256 private _threshold; | ||
uint256 private _nonce; | ||
bytes32 private _deprecatedDomainSeparator; | ||
mapping(bytes32 => uint256) private _signedMessages; | ||
mapping(address => mapping(bytes32 => uint256)) private _approvedHashes; | ||
|
||
function signedMessages(bytes32 hash) external view returns (bool signed) { | ||
return _signedMessages[hash] != 0; | ||
} | ||
|
||
function getModulesPaginated(address start, uint256 pageSize) | ||
public | ||
view | ||
returns (address[] memory modules, address next) | ||
{ | ||
require(start == _SENTINEL || _modules[start] != address(0), "GS105"); | ||
require(pageSize > 0, "GS106"); | ||
modules = new address[](pageSize); | ||
|
||
uint256 moduleCount = 0; | ||
next = _modules[start]; | ||
while (next != address(0) && next != _SENTINEL && moduleCount < pageSize) { | ||
modules[moduleCount] = next; | ||
next = _modules[next]; | ||
moduleCount++; | ||
} | ||
|
||
if (next != _SENTINEL) { | ||
next = modules[moduleCount - 1]; | ||
} | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
mstore(modules, moduleCount) | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} | ||
|
||
function getModules() external view returns (address[] memory modules) { | ||
address next; | ||
(modules, next) = getModulesPaginated(_SENTINEL, 10); | ||
require(next == address(0) || next == _SENTINEL, "GS107"); | ||
return modules; | ||
} | ||
|
||
function getOwners() external view returns (address[] memory array) { | ||
array = new address[](_ownerCount); | ||
|
||
uint256 index = 0; | ||
address currentOwner = _owners[_SENTINEL]; | ||
while (currentOwner != _SENTINEL) { | ||
array[index] = currentOwner; | ||
currentOwner = _owners[currentOwner]; | ||
index++; | ||
} | ||
} | ||
|
||
function getStorageAt(uint256 offset, uint256 length) external view returns (bytes memory result) { | ||
result = new bytes(length * 32); | ||
for (uint256 index = 0; index < length; index++) { | ||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
let word := sload(add(offset, index)) | ||
mstore(add(add(result, 0x20), mul(index, 0x20)), word) | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
import {SafeFallbackAccessor} from "../accessors/SafeFallbackAccessor.sol"; | ||
|
||
contract SafeFallbackHandler { | ||
SafeFallbackAccessor private immutable _ACCESSOR; | ||
|
||
constructor() { | ||
_ACCESSOR = new SafeFallbackAccessor(); | ||
} | ||
|
||
function signedMessages(bytes32) external view returns (bool) { | ||
_fallbackToAccessor(); | ||
} | ||
|
||
function getChainId() external view returns (uint256 chainId) { | ||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
chainId := chainid() | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} | ||
|
||
function getModulesPaginated(address, uint256) external view returns (address[] memory, address) { | ||
_fallbackToAccessor(); | ||
} | ||
|
||
function getModules() external view returns (address[] memory) { | ||
_fallbackToAccessor(); | ||
} | ||
|
||
function getOwners() external view returns (address[] memory) { | ||
_fallbackToAccessor(); | ||
} | ||
|
||
function getStorageAt(uint256, uint256) external view returns (bytes memory) { | ||
_fallbackToAccessor(); | ||
} | ||
|
||
function simulate(address target, bytes calldata data) public returns (bytes memory result) { | ||
bytes memory simulationCallData = abi.encodeWithSelector(0xb4faba09, target, data); | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
pop(call(gas(), caller(), 0, add(simulationCallData, 0x20), mload(simulationCallData), 0x00, 0x20)) | ||
|
||
let responseSize := sub(returndatasize(), 0x20) | ||
result := mload(0x40) | ||
mstore(0x40, add(result, responseSize)) | ||
returndatacopy(result, 0x20, responseSize) | ||
|
||
if iszero(mload(0x00)) { revert(add(result, 0x20), mload(result)) } | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} | ||
|
||
function _simulateAccessor(bytes calldata data) internal view returns (bytes memory result) { | ||
function(address, bytes calldata) internal returns (bytes memory) _simulate = simulate; | ||
function(address, bytes calldata) internal view returns (bytes memory) _simulateView; | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
_simulateView := _simulate | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
|
||
return _simulateView(address(_ACCESSOR), data); | ||
} | ||
|
||
function _fallbackToAccessor() internal view { | ||
bytes memory result = _simulateAccessor(msg.data); | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
return(add(result, 0x20), mload(result)) | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.