Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowCalls cheatcode #19

Merged
merged 2 commits into from
Jan 16, 2025
Merged

Add allowCalls cheatcode #19

merged 2 commits into from
Jan 16, 2025

Conversation

palinatolmach
Copy link
Collaborator

@palinatolmach palinatolmach commented Jan 16, 2025

Related: runtimeverification/kontrol#926.

This PR adds the allowCalls cheatcode that enables whitelisting address and specific calldata:

    // Adds an address and calldata to the whitelist.
    function allowCalls(address, bytes calldata) external;

constituting a more specific version of

    // Adds an address to the whitelist.
    function allowCallsToAddress(address) external;

It can then be used as follows:

  function testExecuteOnlyCallsSubmittedProposals(uint256 proposalId) external {
      Timelock timelock = new Timelock();
      
      // Whitelist one call to the timelock
      bytes memory timelockCalldata = abi.encodeWithSelector(
	      Timelock.execute.selector,
	      proposalId
      );
      kevm.allowCalls(address(timelock), timelockCalldata);

      // Whitelist another call to the timelock
      bytes memory timelockCalldataAnother = abi.encodeWithSelector(
	      Timelock.anotherCall.selector,
	      proposalId
      );
      kevm.allowCalls(address(timelock), timelockCalldataAnother);
      
      // Perform a whitelisted call
      timelock.execute(proposalId);

      // Perform another non-whitelisted call that will cause failure
      timelock.set(proposalId);
  }

@palinatolmach palinatolmach merged commit 187b89a into master Jan 16, 2025
@palinatolmach palinatolmach deleted the allow-calls branch January 16, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants