-
Notifications
You must be signed in to change notification settings - Fork 50
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 #674 from lukso-network/DEV-5243_C4-139--related-t…
…o-58-Refactor-function-_fallbackLSP17Extendable-to-enable-to-run-code-after-this-function-is-called_Jean fix: (C4 #139) refactor `_fallbackLSP17Extendable` function to enable to run code after it is called + prevent potential solc bug "storage write removal"
- Loading branch information
Showing
9 changed files
with
330 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ jobs: | |
"lsp9init", | ||
"lsp11", | ||
"lsp11init", | ||
"lsp17", | ||
"lsp20", | ||
"lsp20init", | ||
"lsp23", | ||
|
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
31 changes: 31 additions & 0 deletions
31
contracts/Mocks/FallbackExtensions/RevertErrorsTestExtension.sol
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,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev This contract is used only for testing purposes | ||
*/ | ||
contract RevertErrorsTestExtension { | ||
error SomeCustomError(address someAddress); | ||
|
||
function revertWithCustomError() public view { | ||
revert SomeCustomError(msg.sender); | ||
} | ||
|
||
function revertWithErrorString() public pure { | ||
revert("some error message"); | ||
} | ||
|
||
function revertWithPanicError() public pure { | ||
uint256 number = 2; | ||
|
||
// trigger an arithmetic underflow. | ||
// this should trigger a error of type `Panic(uint256)` | ||
// with error code 17 (0x11) --> Panic(0x11) | ||
number -= 10; | ||
} | ||
|
||
function revertWithNoErrorData() public pure { | ||
// solhint-disable reason-string | ||
revert(); | ||
} | ||
} |
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,68 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.4; | ||
|
||
import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol"; | ||
|
||
/** | ||
* @dev This contract is used only for testing purposes | ||
*/ | ||
contract LSP17ExtendableTester is LSP17Extendable { | ||
mapping(bytes4 => address) internal _extensions; | ||
|
||
string internal _someStorageData; | ||
string internal _anotherStorageData; | ||
|
||
// This `receive()` function is just put there to disable the following solc compiler warning: | ||
// | ||
// "This contract has a payable fallback function, but no receive ether function. | ||
// Consider adding a receive ether function." | ||
receive() external payable {} | ||
|
||
// solhint-disable no-complex-fallback | ||
fallback() external payable { | ||
// CHECK we can update the contract's storage BEFORE calling an extension | ||
setStorageData("updated BEFORE calling `_fallbackLSP17Extendable`"); | ||
|
||
_fallbackLSP17Extendable(msg.data); | ||
|
||
// CHECK we can update the contract's storage AFTER calling an extension | ||
setAnotherStorageData( | ||
"updated AFTER calling `_fallbackLSP17Extendable`" | ||
); | ||
} | ||
|
||
function getExtension( | ||
bytes4 functionSelector | ||
) public view returns (address) { | ||
return _getExtension(functionSelector); | ||
} | ||
|
||
function setExtension( | ||
bytes4 functionSelector, | ||
address extensionContract | ||
) public { | ||
_extensions[functionSelector] = extensionContract; | ||
} | ||
|
||
function getStorageData() public view returns (string memory) { | ||
return _someStorageData; | ||
} | ||
|
||
function setStorageData(string memory newData) public { | ||
_someStorageData = newData; | ||
} | ||
|
||
function getAnotherStorageData() public view returns (string memory) { | ||
return _anotherStorageData; | ||
} | ||
|
||
function setAnotherStorageData(string memory newData) public { | ||
_anotherStorageData = newData; | ||
} | ||
|
||
function _getExtension( | ||
bytes4 functionSelector | ||
) internal view override returns (address) { | ||
return _extensions[functionSelector]; | ||
} | ||
} |
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.