-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid validation error when function parameter has internal function …
…pointer (#1038)
- Loading branch information
Showing
6 changed files
with
189 additions
and
90 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
116 changes: 116 additions & 0 deletions
116
packages/core/contracts/test/ValidationsFunctionPointers.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,116 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
contract NamespacedExternalFunctionPointer { | ||
/// @custom:storage-location erc7201:example.main | ||
struct S { | ||
function(bool) external foo; | ||
} | ||
} | ||
|
||
contract NamespacedInternalFunctionPointer { | ||
/// @custom:storage-location erc7201:example.main | ||
struct S { | ||
function(bool) internal foo; | ||
} | ||
} | ||
|
||
contract NamespacedInternalFunctionPointerUsed { | ||
/// @custom:storage-location erc7201:example.main | ||
struct S { | ||
function(bool) internal foo; | ||
} | ||
S s; // NOTE: This is unsafe usage of a namespace! | ||
} | ||
|
||
contract StructInternalFunctionPointerUsed { | ||
// not a namespace, but it is referenced | ||
struct S { | ||
function(bool) internal foo; | ||
} | ||
S s; | ||
} | ||
|
||
contract NonNamespacedInternalFunctionPointer { | ||
// not a namespace, and not referenced | ||
struct S { | ||
function(bool) internal foo; | ||
} | ||
} | ||
|
||
contract NamespacedImpliedInternalFunctionPointer { | ||
/// @custom:storage-location erc7201:example.main | ||
struct S { | ||
function(bool) foo; | ||
} | ||
} | ||
|
||
struct StandaloneStructInternalFn { | ||
function(bool) internal foo; | ||
} | ||
|
||
contract UsesStandaloneStructInternalFn { | ||
StandaloneStructInternalFn bad; | ||
} | ||
|
||
struct StructUsesStandaloneStructInternalFn { | ||
StandaloneStructInternalFn bad; | ||
} | ||
|
||
contract NamespacedUsesStandaloneStructInternalFn { | ||
/// @custom:storage-location erc7201:example.main | ||
struct Bad { | ||
StandaloneStructInternalFn bad; | ||
} | ||
} | ||
|
||
contract RecursiveStructInternalFn { | ||
StructUsesStandaloneStructInternalFn bad; | ||
} | ||
|
||
contract MappingRecursiveStructInternalFn { | ||
mapping(address => mapping(address => StructUsesStandaloneStructInternalFn)) bad; | ||
} | ||
|
||
contract ArrayRecursiveStructInternalFn { | ||
StructUsesStandaloneStructInternalFn[][] bad; | ||
} | ||
|
||
contract SelfRecursiveMappingStructInternalFn { | ||
/// @custom:storage-location erc7201:example.main | ||
struct SelfRecursive { | ||
mapping(address => SelfRecursive) selfReference; | ||
mapping(address => StructUsesStandaloneStructInternalFn) bad; | ||
} | ||
} | ||
|
||
contract SelfRecursiveArrayStructInternalFn { | ||
/// @custom:storage-location erc7201:example.main | ||
struct SelfRecursiveArray { | ||
SelfRecursiveArray[] selfReference; | ||
StructUsesStandaloneStructInternalFn[] bad; | ||
} | ||
} | ||
|
||
contract ExternalFunctionPointer { | ||
function(bool) external foo; | ||
} | ||
|
||
contract InternalFunctionPointer { | ||
function(bool) internal foo; | ||
} | ||
|
||
contract ImpliedInternalFunctionPointer { | ||
function(bool) foo; | ||
} | ||
|
||
contract FunctionWithInternalFunctionPointer { | ||
uint208 x; | ||
|
||
function doOp( | ||
function(uint208, uint208) view returns (uint208) op, | ||
uint208 y | ||
) internal view returns (uint208) { | ||
return op(x, y); | ||
} | ||
} |
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