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

[FPS] multisig task tests #485

Open
wants to merge 78 commits into
base: main
Choose a base branch
from

Conversation

prateek105
Copy link
Contributor

@prateek105 prateek105 commented Jan 27, 2025

Description
Add tests for Single and Nested Multisig Tasks.

Tests

Additional context
Using GasConfigTemplate for Single multisig tests and DisputeGameUpgradeTemplate for nested multisig tests

Metadata

ElliotFriedman and others added 30 commits January 22, 2025 17:23
Signed-off-by: Elliot <[email protected]>

add example task template config files

Signed-off-by: Elliot <[email protected]>

add fps example templates

Signed-off-by: Elliot <[email protected]>

remove name and description, set task nonce to current multisig nonce

Signed-off-by: Elliot <[email protected]>

fmt and add TODO to switch to manual nonce later

Signed-off-by: Elliot <[email protected]>

templates

Signed-off-by: Elliot <[email protected]>

remove safeNonce from mock network config

Signed-off-by: Elliot <[email protected]>
Signed-off-by: Elliot <[email protected]>
Signed-off-by: Elliot <[email protected]>
Signed-off-by: Elliot <[email protected]>
@prateek105 prateek105 marked this pull request as ready for review January 28, 2025 06:06
@prateek105 prateek105 requested review from a team as code owners January 28, 2025 06:06
@prateek105 prateek105 requested a review from agusduha January 28, 2025 06:06
@prateek105 prateek105 changed the title Feat/task test [FPS] multisig task tests Jan 28, 2025
@agusduha agusduha removed their request for review January 28, 2025 12:47
Copy link
Contributor

@blmalone blmalone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need test/registry/.gitkeep in this PR.

Made a first pass through this. Still need to go through SingleMultisig.t.sol.

test/task/NestedMultisigTask.t.sol Show resolved Hide resolved
test/task/NestedMultisigTask.t.sol Show resolved Hide resolved
test/task/NestedMultisigTask.t.sol Outdated Show resolved Hide resolved
test/task/NestedMultisigTask.t.sol Show resolved Hide resolved
@blmalone blmalone self-requested a review January 29, 2025 16:06
Copy link
Contributor

@blmalone blmalone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few more comments

/// execute the child multisig approval of hashToApproveByChildMultisig
bytes memory dataToSign = getNestedDataToSign(childOwnerMultisigs[i]);
/// nonce is not decremented by 1 because in task simulation approveHash is called by
/// the child multisig which does not increment the nonce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct right?

Suggested change
/// the child multisig which does not increment the nonce
/// the child multisig owners which does not increment the nonce

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we call as the child multisig owners, we just prank as the child multisigs currently

import {MULTICALL3_ADDRESS} from "src/fps/utils/Constants.sol";

contract SingleMultisigTaskTest is Test {
struct Call3Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we import this from IMultiCall3.sol in. import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol";?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/// @notice This test is used to test the nested multisig task.
contract NestedMultisigTaskTest is Test {
struct Call3Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment below can we take this from import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol";?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


MultisigTask private multisigTask;
Addresses private addresses;
string taskConfigFilePath = "src/fps/example/task-00/mainnetConfig.toml";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string taskConfigFilePath = "src/fps/example/task-00/mainnetConfig.toml";
/// ProxyAdminOwner safe for task-00 is a single multisig.
string taskConfigFilePath = "src/fps/example/task-00/mainnetConfig.toml";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


MultisigTask private multisigTask;
Addresses private addresses;
string taskConfigFilePath = "src/fps/example/task-00/mainnetConfig.toml";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe src/fps/example/task-00/testnetConfig.toml is used anywhere, can we delete this as part of this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

bytes memory callData = multisigTask.getCalldata();
bytes memory dataToSign = multisigTask.getDataToSign(multisigTask.multisig(), callData);

bytes memory expectedDataToSign = IGnosisSafe(multisigTask.multisig()).encodeTransactionData({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bytes memory expectedDataToSign = IGnosisSafe(multisigTask.multisig()).encodeTransactionData({
/// The nonce is decremented by 1 because we want to recreate the data to sign with the same nonce
/// that was used in the simulation. The nonce was incremented as part of running the simulation.
bytes memory expectedDataToSign = IGnosisSafe(multisigTask.multisig()).encodeTransactionData({


/// @title IncorrectGasConfigTemplate1
/// @notice allowed storage write to incorrect address
contract IncorrectGasConfigTemplate1 is MultisigTask {
Copy link
Contributor

@blmalone blmalone Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that we can cut a lot of code down in these IncorrectGasConfigTemplate*files by making the relevant functions inside GasConfigTemplate vitrual. e.g.

contract A {
    function foo() internal pure virtual returns (string[] memory);
}

contract B is A {
    function foo() internal pure virtual override returns (string[] memory) {
        // Using virtual twice like this, what do people think?
    }
}

contract C is B {
    function foo() internal pure override returns (string[] memory) {
        // Further override
    }
}

IncorrectGasConfigTemplate*.sol would become:

pragma solidity 0.8.15;

import {SystemConfig} from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";

import {GasConfigTemplate} from "src/fps/example/template/GasConfigTemplate.sol";
import {AddressRegistry as Addresses} from "src/fps/AddressRegistry.sol";

/// @title IncorrectGasConfigTemplate2
/// @notice not all allowed storages writes are written to
contract IncorrectGasConfigTemplate2 is GasConfigTemplate {
    function _taskStorageWrites() internal pure override returns (string[] memory) {
        string[] memory storageWrites = new string[](2);
        /// expected to be written to
        storageWrites[0] = "SystemConfigOwner";
        storageWrites[1] = "SystemConfigProxy";
        return storageWrites;
    }
}
pragma solidity 0.8.15;

import {SystemConfig} from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";

import {GasConfigTemplate} from "src/fps/example/template/GasConfigTemplate.sol";
import {AddressRegistry as Addresses} from "src/fps/AddressRegistry.sol";

/// @title IncorrectGasConfigTemplate1
/// @notice allowed storage write to incorrect address
contract IncorrectGasConfigTemplate1 is GasConfigTemplate {
    function _taskStorageWrites() internal pure override returns (string[] memory) {
        string[] memory storageWrites = new string[](1);
        /// wrong address
        storageWrites[0] = "SystemConfigOwner";
        return storageWrites;
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is resolved now

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.

3 participants