Skip to content

Commit

Permalink
fix: e2e tests not deploying to anvil node
Browse files Browse the repository at this point in the history
  • Loading branch information
excaliborr committed Nov 23, 2023
1 parent baa3096 commit c3453bc
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 20 deletions.
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ out = 'out'
libs = ['lib']
fuzz_runs = 1000
optimizer_runs = 10_000
fs_permissions = [{ access = "read-write", path = "./"}]

[profile.optimized]
via_ir = true
out = 'out-via-ir'
fuzz_runs = 5000
fs_permissions = [{ access = "read-write", path = "./"}]

[profile.test]
via_ir = true
out = 'out-via-ir'
fuzz_runs = 5000
src = 'solidity/test'
fs_permissions = [{ access = "read-write", path = "./"}]

[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"coverage": "forge coverage --match-contract Unit",
"deploy:goerli": "bash -c 'source .env && forge script -vv --rpc-url $GOERLI_RPC --slow --broadcast --private-key $DEPLOYER_GOERLI_PRIVATE_KEY solidity/scripts/DeployGoerli.s.sol:DeployGoerli'",
"deploy:mainnet": "bash -c 'source .env && forge script -vv --rpc-url $MAINNET_RPC --slow --broadcast --private-key $DEPLOYER_MAINNNET_PRIVATE_KEY solidity/scripts/DeployMainnet.s.sol:DeployMainnet'",
"deploy:optimism": "bash -c 'source .env && forge script -vv --rpc-url $OPTIMISM_RPC --slow --broadcast --private-key $DEPLOYER_OPTIMISM_PRIVATE_KEY solidity/scripts/DeployOptimism.s.sol:DeployOptimism'",
"deploy:mainnet": "bash -c 'source .env && forge script -vv --rpc-url $MAINNET_E2E_RPC --slow --broadcast --private-key $DEPLOYER_MAINNNET_PRIVATE_KEY solidity/scripts/DeployMainnet.s.sol:DeployMainnet'",
"deploy:optimism": "bash -c 'source .env && forge script -vv --rpc-url $OPTIMISM_E2E_RPC --slow --broadcast --private-key $DEPLOYER_OPTIMISM_PRIVATE_KEY solidity/scripts/DeployOptimism.s.sol:DeployOptimism'",
"deploy:optimismGoerli": "bash -c 'source .env && forge script -vv --rpc-url $OPTIMISM_GOERLI_RPC --slow --broadcast --private-key $DEPLOYER_OPTIMISM_GOERLI_PRIVATE_KEY solidity/scripts/DeployOptimismGoerli.s.sol:DeployOptimismGoerli'",
"lint:check": "yarn lint:sol-tests && yarn lint:sol-logic && forge fmt check",
"lint:fix": "sort-package-json && forge fmt && yarn lint:sol-tests --fix && yarn lint:sol-logic --fix",
Expand Down
7 changes: 4 additions & 3 deletions proofs/generate_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import rlp

from proof_utils import request_block_header, request_account_proof
from proof_utils import request_block_header, request_account_proof, mine_anvil_block

def main():
# Parse command line arguments
Expand Down Expand Up @@ -31,12 +31,13 @@ def main():
args = parser.parse_args()

rpc_endpoint = args.rpc
block_number = args.block_number
block_number = args.block_number + 1
storage_mirror_contract_address = args.contract
storage_slot = args.slot
clean_storage_slot = bytes.fromhex(storage_slot[2:])

# Generate proof data
(block_number, block_header, acct_proof, storage_proofs) = generate_proof_data(rpc_endpoint, block_number, storage_mirror_contract_address, [storage_slot])
(block_number, block_header, acct_proof, storage_proofs) = generate_proof_data(rpc_endpoint, block_number, storage_mirror_contract_address, [clean_storage_slot])

# Encode the proof data
account_proof = rlp.encode(acct_proof)
Expand Down
11 changes: 11 additions & 0 deletions proofs/proof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def request_block_header(rpc_endpoint, block_number):

return (block_number, block_header_fields)

def mine_anvil_block(rpc_endpoint):
r = requests.post(rpc_endpoint, json={
"jsonrpc": "2.0",
"method": "anvil_mine",
"params": [],
"id": 1,
})

result = get_json_rpc_result(r)
return result


def request_account_proof(rpc_endpoint, block_number, address, slots):
hex_slots = [to_0x_string(s) for s in slots]
Expand Down
144 changes: 144 additions & 0 deletions solidity/scripts/DeployE2E.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {Script} from 'forge-std/Script.sol';
import {console} from 'forge-std/console.sol';
import {stdJson} from 'forge-std/StdJson.sol';
import {Enum} from 'safe-contracts/common/Enum.sol';

import {DeployHomeChain, DeployVars} from 'scripts/DeployHomeChain.s.sol';
import {DeployNonHomeChain, DeployVarsNonHomeChain} from 'scripts/DeployNonHomeChain.s.sol';
import {TestConstants} from 'test/utils/TestConstants.sol';
import {ISafe} from 'interfaces/ISafe.sol';
import {IGuardCallbackModule} from 'interfaces/IGuardCallbackModule.sol';
import {IVerifierModule} from 'interfaces/IVerifierModule.sol';
import {IStorageMirrorRootRegistry} from 'interfaces/IStorageMirrorRootRegistry.sol';
import {IStorageMirror} from 'interfaces/IStorageMirror.sol';
import {IBlockHeaderOracle} from 'interfaces/IBlockHeaderOracle.sol';
import {IGnosisSafeProxyFactory} from 'test/e2e/IGnosisSafeProxyFactory.sol';

contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {
address internal _deployer = vm.rememberKey(vm.envUint('MAINNET_DEPLOYER_PK'));
uint256 internal _pk = vm.envUint('MAINNET_DEPLOYER_PK');
IGnosisSafeProxyFactory public gnosisSafeProxyFactory = IGnosisSafeProxyFactory(GNOSIS_SAFE_PROXY_FACTORY);
address[] internal _owners = [_deployer];

function run() external {
vm.createSelectFork(vm.rpcUrl('mainnet_e2e'));
vm.startBroadcast(_deployer);
DeployVars memory _deployVarsHomeChain = DeployVars(_deployer);

// Deploy protocol
_deployHomeChain(_deployVarsHomeChain);
ISafe _safe = ISafe(address(gnosisSafeProxyFactory.createProxy(GNOSIS_SAFE_SINGLETON, '')));
address _storageMirrorAddr =
vm.parseJsonAddress(vm.readFile('./solidity/scripts/HomeChainDeployments2.json'), '$.StorageMirror');

_setupHomeChain(_safe, _storageMirrorAddr);

vm.stopBroadcast();

DeployVarsNonHomeChain memory _deployVarsNonHomeChain = DeployVarsNonHomeChain(_deployer, _storageMirrorAddr);

vm.createSelectFork(vm.rpcUrl('optimism_e2e'));
vm.startBroadcast(_deployer);

// Deploy protocol
_deployNonHomeChain(_deployVarsNonHomeChain);

vm.stopBroadcast();
}

/**
* @notice Enables a module for the given safe
* @param _safe The safe that will enable the module
* @param _safeOwnerKey The private key to sign the tx
* @param _module The module address to enable
*/
function enableModule(ISafe _safe, uint256 _safeOwnerKey, address _module) public {
uint256 _safeNonce = _safe.nonce();
// data to sign to enable module
bytes memory _enableModuleData = abi.encodeWithSelector(ISafe.enableModule.selector, address(_module));
bytes memory _enableModuleEncodedTxData = _safe.encodeTransactionData(
address(_safe), 0, _enableModuleData, Enum.Operation.Call, 0, 0, 0, address(0), payable(0), _safeNonce
);

// signature
(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(_safeOwnerKey, keccak256(_enableModuleEncodedTxData));
bytes memory _enableModuleSignature = abi.encodePacked(_r, _s, _v);

// execute enable module
_safe.execTransaction(
address(_safe), 0, _enableModuleData, Enum.Operation.Call, 0, 0, 0, address(0), payable(0), _enableModuleSignature
);
}

function _setupHomeChain(ISafe _safe, address _storageMirrorAddr) internal {
_safe.setup(_owners, 1, address(_safe), bytes(''), address(0), address(0), 0, payable(address(0)));

address _guardCallbackModule =
vm.parseJsonAddress(vm.readFile('./solidity/scripts/HomeChainDeployments.json'), '$.GuardCallbackModule');

enableModule(_safe, _pk, _guardCallbackModule);

// data to sign and send to set the guard
bytes memory _txData = _safe.encodeTransactionData(
_guardCallbackModule,
0,
abi.encodeWithSelector(IGuardCallbackModule.setGuard.selector),
Enum.Operation.Call,
0,
0,
0,
address(0),
payable(0),
_safe.nonce()
);

// signature
(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(_pk, keccak256(_txData));

_safe.execTransaction(
_guardCallbackModule,
0,
abi.encodeWithSelector(IGuardCallbackModule.setGuard.selector),
Enum.Operation.Call,
0,
0,
0,
address(0),
payable(0),
abi.encodePacked(_r, _s, _v)
);

_txData = _safe.encodeTransactionData(
_storageMirrorAddr,
0,
abi.encodeWithSelector(IStorageMirror.update.selector, keccak256(abi.encode(_owners, 1))),
Enum.Operation.Call,
0,
0,
0,
address(0),
payable(0),
_safe.nonce()
);

// signature
(_v, _r, _s) = vm.sign(_pk, keccak256(_txData));

// execute update storage mirror
_safe.execTransaction(
_storageMirrorAddr,
0,
abi.encodeWithSelector(IStorageMirror.update.selector, keccak256(abi.encode(_owners, 1))),
Enum.Operation.Call,
0,
0,
0,
address(0),
payable(0),
abi.encodePacked(_r, _s, _v)
);
}
}
2 changes: 1 addition & 1 deletion solidity/scripts/DeployGoerli.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployGoerli is DeployHomeChain {
DeployVars memory _deployVars = DeployVars(deployer);

// Deploy protocol
_deploy(_deployVars);
_deployHomeChain(_deployVars);

vm.stopBroadcast();
}
Expand Down
12 changes: 10 additions & 2 deletions solidity/scripts/DeployHomeChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity =0.8.19;

import {Script} from 'forge-std/Script.sol';
import {console} from 'forge-std/console.sol';

import {Test} from 'forge-std/Test.sol';
import {StorageMirror} from 'contracts/StorageMirror.sol';
import {UpdateStorageMirrorGuard} from 'contracts/UpdateStorageMirrorGuard.sol';
import {GuardCallbackModule} from 'contracts/GuardCallbackModule.sol';
Expand All @@ -16,7 +16,7 @@ struct DeployVars {
}

abstract contract DeployHomeChain is Script, TestConstants {
function _deploy(DeployVars memory _deployVars)
function _deployHomeChain(DeployVars memory _deployVars)
internal
returns (
StorageMirror _storageMirror,
Expand All @@ -42,5 +42,13 @@ abstract contract DeployHomeChain is Script, TestConstants {
console.log('UPDATE_STORAGE_MIRROR_GUARD: ', address(_updateStorageMirrorGuard));

console.log('DEPLOYMENT DONE');

string memory _objectKey = 'deployments';

vm.serializeAddress(_objectKey, 'StorageMirror', address(_storageMirror));
vm.serializeAddress(_objectKey, 'UpdateStorageMirrorGuard', address(_updateStorageMirrorGuard));
string memory _output = vm.serializeAddress(_objectKey, 'GuardCallbackModule', address(_guardCallbackModule));

vm.writeJson(_output, './solidity/scripts/HomeChainDeployments.json');
}
}
2 changes: 1 addition & 1 deletion solidity/scripts/DeployMainnet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployMainnet is DeployHomeChain {
DeployVars memory _deployVars = DeployVars(deployer);

// Deploy protocol
_deploy(_deployVars);
_deployHomeChain(_deployVars);

vm.stopBroadcast();
}
Expand Down
12 changes: 10 additions & 2 deletions solidity/scripts/DeployNonHomeChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {IStorageMirrorRootRegistry} from 'interfaces/IStorageMirrorRootRegistry.
import {TestConstants} from 'test/utils/TestConstants.sol';
import {ContractDeploymentAddress} from 'test/utils/ContractDeploymentAddress.sol';

struct DeployVars {
struct DeployVarsNonHomeChain {
address deployer;
address storageMirror;
}

abstract contract DeployNonHomeChain is Script, TestConstants {
function _deploy(DeployVars memory _deployVars)
function _deployNonHomeChain(DeployVarsNonHomeChain memory _deployVars)
internal
returns (
BlockHeaderOracle _blockHeaderOracle,
Expand Down Expand Up @@ -49,5 +49,13 @@ abstract contract DeployNonHomeChain is Script, TestConstants {

_needsUpdateGuard = new NeedsUpdateGuard(_verifierModule); // deployer nonce 3
console.log('NEEDS_UPDATE_GUARD: ', address(_needsUpdateGuard));

string memory _objectKey = 'deployments';
vm.serializeAddress(_objectKey, 'BlockHeaderOracle', address(_blockHeaderOracle));
vm.serializeAddress(_objectKey, 'NeedsUpdateGuard', address(_needsUpdateGuard));
vm.serializeAddress(_objectKey, 'StorageMirrorRootRegistry', address(_storageMirrorRootRegistry));
string memory _output = vm.serializeAddress(_objectKey, 'VerifierModule', address(_verifierModule));

vm.writeJson(_output, './solidity/scripts/NonHomeChainDeployments.json');
}
}
6 changes: 3 additions & 3 deletions solidity/scripts/DeployOptimism.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {DeployNonHomeChain, DeployVars} from 'scripts/DeployNonHomeChain.s.sol';
import {DeployNonHomeChain, DeployVarsNonHomeChain} from 'scripts/DeployNonHomeChain.s.sol';

// We threat Goerli as the Home Chain in this case
contract DeployOptimism is DeployNonHomeChain {
Expand All @@ -11,10 +11,10 @@ contract DeployOptimism is DeployNonHomeChain {
function run() external {
vm.startBroadcast(deployer);

DeployVars memory _deployVars = DeployVars(deployer, storageMirrorAddress);
DeployVarsNonHomeChain memory _deployVars = DeployVarsNonHomeChain(deployer, storageMirrorAddress);

// Deploy protocol
_deploy(_deployVars);
_deployNonHomeChain(_deployVars);

vm.stopBroadcast();
}
Expand Down
6 changes: 3 additions & 3 deletions solidity/scripts/DeployOptimismGoerli.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.19;

import {DeployNonHomeChain, DeployVars} from 'scripts/DeployNonHomeChain.s.sol';
import {DeployNonHomeChain, DeployVarsNonHomeChain} from 'scripts/DeployNonHomeChain.s.sol';

// We threat Goerli as the Home Chain in this case
contract DeployOptimismGoerli is DeployNonHomeChain {
Expand All @@ -11,9 +11,9 @@ contract DeployOptimismGoerli is DeployNonHomeChain {
function run() external {
vm.startBroadcast(deployer);

DeployVars memory _deployVars = DeployVars(deployer, storageMirrorAddress);
DeployVarsNonHomeChain memory _deployVars = DeployVarsNonHomeChain(deployer, storageMirrorAddress);
// Deploy protocol
_deploy(_deployVars);
_deployNonHomeChain(_deployVars);

vm.stopBroadcast();
}
Expand Down
5 changes: 5 additions & 0 deletions solidity/scripts/Deployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"GuardCallbackModule": "0x8d375dE3D5DDde8d8caAaD6a4c31bD291756180b",
"StorageMirror": "0x4458AcB1185aD869F982D51b5b0b87e23767A3A9",
"UpdateStorageMirrorGuard": "0x721a1ecB9105f2335a8EA7505D343a5a09803A06"
}
5 changes: 5 additions & 0 deletions solidity/scripts/HomeChainDeployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"GuardCallbackModule": "0x15BB2cc3Ea43ab2658F7AaecEb78A9d3769BE3cb",
"StorageMirror": "0xCdb63c58b907e76872474A0597C5252eDC97c883",
"UpdateStorageMirrorGuard": "0xa4d0806d597146df93796A38435ABB2a3cb96677"
}
9 changes: 9 additions & 0 deletions solidity/scripts/NonHomeChainDeployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"BlockHeaderOracle": "0x3347B4d90ebe72BeFb30444C9966B2B990aE9FcB",
"GuardCallbackModule": "0x889D9A5AF83525a2275e41464FAECcCb3337fF60",
"NeedsUpdateGuard": "0xffa7CA1AEEEbBc30C874d32C7e22F052BbEa0429",
"StorageMirror": "0x9852795dbb01913439f534b4984fBf74aC8AfA12",
"StorageMirrorRootRegistry": "0x5bf5b11053e734690269C6B9D438F8C9d48F528A",
"UpdateStorageMirrorGuard": "0xf274De14171Ab928A5Ec19928cE35FaD91a42B64",
"VerifierModule": "0x3155755b79aA083bd953911C92705B7aA82a18F9"
}
Loading

0 comments on commit c3453bc

Please sign in to comment.