Component
Other (please describe)
Describe the feature you would like
Current Workflow:
Currently, to retrieve function selectors from a contract name, I use the following helper function:
function getSelectors(string memory _contractName) internal returns (bytes4[] memory selectors_) {
string[] memory cmd = new string[](5);
cmd[0] = "forge";
cmd[1] = "inspect";
cmd[2] = _contractName;
cmd[3] = "methodIdentifiers";
cmd[4] = "--json";
bytes memory res = vm.ffi(cmd);
string memory output = string(res);
string[] memory keys = vm.parseJsonKeys(output, "");
uint256 keysLength = keys.length;
// Initialize the selectors array with the selectorCount
selectors_ = new bytes4[](keysLength);
for (uint256 i; i < keysLength; ++i) {
selectors_[i] = bytes4(bytes32(keccak256(bytes(keys[i]))));
}
}
The issue:
- This approach requires enabling ffi, which many developers may not be comfortable with for security reasons.
- It introduces external command execution, which could slow down tests and create unnecessary complexity.
- ffi usage reduces portability and reproducibility in some environments.
Proposed Solution
- Add a native utility function to Vm.sol (or another appropriate cheatcode interface) for retrieving selectors directly from compiled contract data:
function getSelectors(string memory contractName) external returns (bytes4[] memory);
This function would:
- Accept the contract name (or optionally, its bytecode).
- Return an array of all function selectors derived from the contract’s ABI.
- Eliminate the need for ffi and forge inspect calls during tests.
Additional Notes
- I also noticed that no current Vm.sol function accepts string in memory, which may require adjustments or documentation.
- This feature would be extremely useful for developers working with Diamond Standard (EIP-2535) or similar patterns where function selector management is critical.
Additional context
No response
Component
Other (please describe)
Describe the feature you would like
Current Workflow:
Currently, to retrieve function selectors from a contract name, I use the following helper function:
The issue:
Proposed Solution
This function would:
Additional Notes
Additional context
No response