Skip to content

Commit

Permalink
chore: refactor and fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
excaliborr committed Nov 24, 2023
1 parent e39b4d0 commit a16bd0f
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 266 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
},
"author": "Wonderland",
"scripts": {
"anvil:mainnet": "anvil --port 8545 -f $MAINNET_RPC --fork-block-number 18621047 --chain-id 1",
"anvil:optimism": "anvil --port 9545 -f $OPTIMISM_RPC --fork-block-number 112491451 --chain-id 10",
"build": "forge build --via-ir",
"build": "forge build",
"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_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'",
"ganache:mainnet": "ganache --port 8545 --mnemonic 'chapter polar wool ethics pudding undo slide social second put segment chair'",
"ganache:optimism": "ganache --port 9545 --mnemonic 'chapter polar wool ethics pudding undo slide social second put segment chair'",
"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",
"lint:sol-logic": "solhint -c .solhint.json 'solidity/contracts/**/*.sol' 'solidity/interfaces/**/*.sol'",
"lint:sol-tests": "solhint 'solidity/test/**/*.sol'",
"prepare": "husky install",
"proof": "python3 proofs/generate_proof.py",
"test": "forge test -vvv",
"test:e2e": "forge test --match-contract E2E -vvv",
"test": "forge test --ffi -vvv",
"test:e2e": "forge test --ffi --match-contract E2E -vvv",
"test:unit": "forge test --match-contract Unit -vvv",
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit"
},
Expand Down
8 changes: 4 additions & 4 deletions proofs/proof.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"blockNumber": 23,
"blockHeader": "f901f5a098025019b679c7d07a94be981c4d89dfd7e181ab0a6bf552ebbbd8b79c0d5e43a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0fa44db5328a4efcd29a62fc7256bd65991b619bf92a388bdd98a0671a4d92757a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000178401c9c38000846560aaa180a0b6f10f40b56cdd7e601090ad40d430220882d56a6b4833d4c821f6faca31d7b4880000000000000000",
"accountProof": "f9025ff901f1a08612f63b7f9a11408e2f23f321e5136d332dd57790ed36735777b23957310993a016ef7dfdd5a2499becbb81956a38788bfc057f9d52dd5c576ebcb85de995040ea030235cd697b3c3a0f85fa35fad88d3fc176fa60cd74b1d3cd7add06250b40305a0153a661f74405ad9d8f5d1df1138e82bfef064d71da5eec6df62aedf25868aeba0de26cb1b4fd99c4d3ed75d4a67931e3c252605c7d68e0148d5327f341bfd5283a0409e3997e67d3963cccc4b306dbf32d9b4790db921fe414a1be1030c5327e27ca0865d7ca964ec30d14b72f9744bad3e9f4cd12f3ee0eabfa5b7bf4e3a13c0753e80a0ea85562bb917489f2aa6151418d9c34428721c7d8e3ebd8fb07404a1ef5217fba0650baffbb20b2e9ff377c5518cf910c01caeeb7bc32907c60cda835edb70dff1a07ea03eb36e3087a210f9e1fb8e56dc0ccb528b59e1637443139e5a18312c238da0b584f3ace57d374da950843baaf0c847348d627c4cd625dd66e5dcc41fffffdaa0b6e213ee6b464afba5190eef562a503a089087df5bf722f694bfcc0709413968a0a5ac64bb99d260ef6b13a4f2040ed48a4936664ec13d400238b5004841a4d888a02cced9104a6e072cfcff4bc51d16ad481678fc128ebea28446a982234c65227ba0efc69d2819d03c1d5c708bf8f59905a501ed8d23ef08fb1270cfb345221f28da80f869a034b14a79c7136d5a01f70ed75f70e07b9dbd7d85dc331e9404805af6671a9d96b846f8440180a076f4ebdb9e788380676986fe28d3997be29c3492d9f3f666c9ed91891306beb0a0fd79d9f0b0ab6ee2f4166bb9632d934d81e28cd5fdb396e3f3e06ef9580cfd32",
"storageProof": "f846f844a120de506b3ca792e2f384432fef433a68be75fe11a8028a454651f138569ff3d1e0a1a0a362927a7b493db164d1728c370827794def1c9f44b655434ab20f05d39e7478"
"blockNumber": 36,
"blockHeader": "f901f5a0f39983753ddfc18c23a4b39f747294f130da825e5dffb40a3b5f60035a4ec57ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0bb207649ed9410038954b38b4255b74cafc1f42d3009c140b65559da5fbe4d27a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000248401c9c3800084656108ab80a087319fde05bca7b338486f083acd366a7a0b5d611e30824a130dd3265599b348880000000000000000",
"accountProof": "f90344f90211a08612f63b7f9a11408e2f23f321e5136d332dd57790ed36735777b23957310993a016ef7dfdd5a2499becbb81956a38788bfc057f9d52dd5c576ebcb85de995040ea0fe6b255e122c54ba054bccdaf3852e3ec34465f640e4b73aa726874bd5469f96a02c97aa6929b910f31d98eb3d0f476cb6fe1ec36a5928fe6229e720d31e996317a0de26cb1b4fd99c4d3ed75d4a67931e3c252605c7d68e0148d5327f341bfd5283a05be23df6da58dc30280666f326ffe2195cb7dfa9ce4a84ba717037122fae8038a0f06b89db96623466bc5ea383fb27224ef44444881917a22bc0f1c62ab2eae315a0138ee0184f6efe0e45598b6464db22cb9223675716aceb3c140c1851c6ca410ca0ea85562bb917489f2aa6151418d9c34428721c7d8e3ebd8fb07404a1ef5217fba0650baffbb20b2e9ff377c5518cf910c01caeeb7bc32907c60cda835edb70dff1a07ea03eb36e3087a210f9e1fb8e56dc0ccb528b59e1637443139e5a18312c238da06edfd510f74c19fcd730f511b0299da90d8bc6728c6881b8fb85377201965d5fa0838811f973bc4b33943c91dcf89cbe3a880bc8b54546341fb5f1fa718771c27ea092ce65498a7c2b08b130753f4473761c6d90ef094119a66cc482b622f4116bb0a093b6bc9719692906bfc192f9e4b738a809a0c3ef0daabe08b4ad055c66130bfba0efc69d2819d03c1d5c708bf8f59905a501ed8d23ef08fb1270cfb345221f28da80f871808080808080a02bac582e860fd49c3f34de2a6f9fa706ea1ad70f4193a1a9823addd0d92b065b8080a0d81b357ccc2c72f765a68c399c9b05a8583067fd455a628068ed0f8b58306dfa80a08a0d76872abbc84b8b8ebad07baec7e6d30439fc2f62882638966a0f2b7307e28080808080f8518080808080808080808080a05115ad990b35e082788c4c3623594518d365075459aa656a4cc82db67d243c8da02ff07d5c68978593cd1e03533f1a14fda2e6828680ee2241e7616cec87f4f83580808080f8689f3fca9caaefa3f5b6ed8c22b6c44aa2bada0e861d7ab419ae9a05e03df85357b846f8440180a0110b0f4e2d6d23319a04333093205f8d1159ecd7a04317afcd47b41024d1ab8da0fd79d9f0b0ab6ee2f4166bb9632d934d81e28cd5fdb396e3f3e06ef9580cfd32",
"storageProof": "f846f844a120ccf9afdf934e310256e17a4e9d00f805abdf656335d78ac9a72ed7beac729e12a1a0a362927a7b493db164d1728c370827794def1c9f44b655434ab20f05d39e7478"
}
2 changes: 1 addition & 1 deletion proofs/proof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def request_account_proof(rpc_endpoint, block_number, address, slots):
storage_proofs = [
decode_rpc_proof(slot_data["proof"]) for slot_data in result["storageProof"]
]

return (account_proof, storage_proofs)


Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/VerifierModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract VerifierModule is IVerifierModule {
// Verify the account proof against the state root
bytes memory _rlpAccount = MerklePatriciaProofVerifier.extractProofValue(
_parsedBlockHeader.stateRootHash,
abi.encodePacked(keccak256(abi.encode(STORAGE_MIRROR))),
abi.encodePacked(keccak256(abi.encodePacked(STORAGE_MIRROR))),
_storageMirrorAccountProof.toRlpItem().toList()
);

Expand Down Expand Up @@ -309,11 +309,11 @@ contract VerifierModule is IVerifierModule {
// Ensure the source data is 32 bytes or less

// Sanity check the keccak256() of the security settings should always fit in 32 bytes
if (_source.length > 32) revert VerifierModule_BytesToBytes32Failed();
if (_source.length > 33) revert VerifierModule_BytesToBytes32Failed();

// Copy the data into the bytes32 variable
assembly {
_result := mload(add(_source, 32))
_result := mload(add(add(_source, 2), 32))
}
}
}
91 changes: 67 additions & 24 deletions solidity/scripts/DeployE2E.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {
uint256 internal _pk = vm.envUint('MAINNET_DEPLOYER_PK');
address[] internal _owners = [_deployer];
Safe internal _singletonSafe;
Safe internal _singletonSafeOp;
IVerifierModule.SafeTxnParams internal _vars;

function run() external {
Expand All @@ -42,7 +43,7 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {
_deployHomeChain(_deployVarsHomeChain);
ISafe _safe = ISafe(address(new SafeProxy(address(_singletonSafe))));
address _storageMirrorAddr =
vm.parseJsonAddress(vm.readFile('./solidity/scripts/HomeChainDeployments.json'), '$.StorageMirror');
vm.parseJsonAddress(vm.readFile('./solidity/scripts/deployments/HomeChainDeployments.json'), '$.StorageMirror');

_setupHomeChain(_safe, _storageMirrorAddr);

Expand All @@ -52,19 +53,25 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {

vm.createSelectFork(vm.rpcUrl('optimism_e2e'));
vm.startBroadcast(_deployer);
_singletonSafeOp = new Safe();
ISafe _nonHomeChainSafe = ISafe(address(new SafeProxy(address(_singletonSafeOp))));

// Deploy protocol
_deployNonHomeChain(_deployVarsNonHomeChain);

address _verifierModule = vm.parseJsonAddress(
vm.readFile('./solidity/scripts/deployments/NonHomeChainDeployments.json'), '$.VerifierModule'
);

_setupNonHomeChain(_nonHomeChainSafe, _verifierModule);

vm.stopBroadcast();

string memory _objectKey = 'deployments';

string memory _output = vm.serializeAddress(_objectKey, 'Safe', address(_safe));

vm.writeJson(_output, './solidity/scripts/SafeDeployments.json');

// saveProof(vm.rpcUrl('mainnet_e2e'), vm.toString(_storageMirrorAddr), vm.toString((keccak256(abi.encode(address(_safe), 0)))));
vm.writeJson(_output, './solidity/scripts/deployments/E2ESafeDeployments.json');
}

/**
Expand Down Expand Up @@ -94,8 +101,9 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {
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');
address _guardCallbackModule = vm.parseJsonAddress(
vm.readFile('./solidity/scripts/deployments/HomeChainDeployments.json'), '$.GuardCallbackModule'
);

enableModule(_safe, _pk, _guardCallbackModule);

Expand Down Expand Up @@ -179,22 +187,57 @@ contract DeployE2E is Script, DeployHomeChain, DeployNonHomeChain {
);
}

// function saveProof(
// string memory _rpc,
// string memory _contractAddress,
// string memory _storageSlot
// ) public {
// string[] memory _commands = new string[](8);
// _commands[0] = 'yarn';
// _commands[1] = 'proof';
// _commands[2] = '--rpc';
// _commands[3] = _rpc;
// _commands[4] = '--contract';
// _commands[5] = _contractAddress;
// _commands[6] = '--slot';
// _commands[7] = _storageSlot;

// bytes memory _res = vm.ffi(_commands);
// string memory _output = string(_res);
// }
function _setupNonHomeChain(ISafe _safe, address _verifierModule) internal {
_safe.setup(_owners, 1, address(_safe), bytes(''), address(0), address(0), 0, payable(address(0)));
enableModule(_safe, _pk, _verifierModule);

address _needsUpdateGuard = vm.parseJsonAddress(
vm.readFile('./solidity/scripts/deployments/NonHomeChainDeployments.json'), '$.NeedsUpdateGuard'
);

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

Signature memory _signature;

// signature
(_signature.v, _signature.r, _signature.s) = vm.sign(_pk, keccak256(_txData));

_vars = IVerifierModule.SafeTxnParams({
to: address(_safe),
value: 0,
data: abi.encodeWithSelector(ISafe.setGuard.selector, _needsUpdateGuard),
operation: Enum.Operation.Call,
safeTxGas: 0,
baseGas: 0,
gasPrice: 0,
gasToken: address(0),
refundReceiver: payable(address(0)),
signatures: abi.encodePacked(_signature.r, _signature.s, _signature.v)
});

_safe.execTransaction(
_vars.to,
_vars.value,
_vars.data,
_vars.operation,
_vars.safeTxGas,
_vars.baseGas,
_vars.gasPrice,
_vars.gasToken,
_vars.refundReceiver,
_vars.signatures
);
}
}
2 changes: 1 addition & 1 deletion solidity/scripts/DeployHomeChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ abstract contract DeployHomeChain is Script, TestConstants {
vm.serializeAddress(_objectKey, 'UpdateStorageMirrorGuard', address(_updateStorageMirrorGuard));
string memory _output = vm.serializeAddress(_objectKey, 'GuardCallbackModule', address(_guardCallbackModule));

vm.writeJson(_output, './solidity/scripts/HomeChainDeployments.json');
vm.writeJson(_output, './solidity/scripts/deployments/HomeChainDeployments.json');
}
}
2 changes: 1 addition & 1 deletion solidity/scripts/DeployNonHomeChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ abstract contract DeployNonHomeChain is Script, TestConstants {
vm.serializeAddress(_objectKey, 'StorageMirrorRootRegistry', address(_storageMirrorRootRegistry));
string memory _output = vm.serializeAddress(_objectKey, 'VerifierModule', address(_verifierModule));

vm.writeJson(_output, './solidity/scripts/NonHomeChainDeployments.json');
vm.writeJson(_output, './solidity/scripts/deployments/NonHomeChainDeployments.json');
}
}
5 changes: 0 additions & 5 deletions solidity/scripts/Deployments.json

This file was deleted.

5 changes: 0 additions & 5 deletions solidity/scripts/HomeChainDeployments.json

This file was deleted.

9 changes: 0 additions & 9 deletions solidity/scripts/NonHomeChainDeployments.json

This file was deleted.

10 changes: 0 additions & 10 deletions solidity/scripts/SafeDeployments.json

This file was deleted.

10 changes: 10 additions & 0 deletions solidity/scripts/deployments/E2ESafeDeployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"BlockHeaderOracle": "0x818d7aA843fb975fE4cd1024DCc3ad3f0F3F3052",
"GuardCallbackModule": "0xdd272bf1C9bC8ac7E1a2F66608758552924486D5",
"NeedsUpdateGuard": "0x2A636e72883279AD118c9031341Ea8d0ea1C2e69",
"Safe": "0x55289098C49303EF9bC83fC3093B8CcE8be084d2",
"StorageMirror": "0x2A636e72883279AD118c9031341Ea8d0ea1C2e69",
"StorageMirrorRootRegistry": "0x6333aD39eE291441034d278920821092A6E609b3",
"UpdateStorageMirrorGuard": "0xBb5C18Aa963B677B3DCC6e93F63B3AAe7eCb854F",
"VerifierModule": "0x2c1fd361958e736546fE0AF3EC6A27FE1830C644"
}
5 changes: 5 additions & 0 deletions solidity/scripts/deployments/HomeChainDeployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"GuardCallbackModule": "0xdd272bf1C9bC8ac7E1a2F66608758552924486D5",
"StorageMirror": "0x2A636e72883279AD118c9031341Ea8d0ea1C2e69",
"UpdateStorageMirrorGuard": "0xBb5C18Aa963B677B3DCC6e93F63B3AAe7eCb854F"
}
9 changes: 9 additions & 0 deletions solidity/scripts/deployments/NonHomeChainDeployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"BlockHeaderOracle": "0x818d7aA843fb975fE4cd1024DCc3ad3f0F3F3052",
"GuardCallbackModule": "0xdd272bf1C9bC8ac7E1a2F66608758552924486D5",
"NeedsUpdateGuard": "0x2A636e72883279AD118c9031341Ea8d0ea1C2e69",
"StorageMirror": "0x2A636e72883279AD118c9031341Ea8d0ea1C2e69",
"StorageMirrorRootRegistry": "0x6333aD39eE291441034d278920821092A6E609b3",
"UpdateStorageMirrorGuard": "0xBb5C18Aa963B677B3DCC6e93F63B3AAe7eCb854F",
"VerifierModule": "0x2c1fd361958e736546fE0AF3EC6A27FE1830C644"
}
Loading

0 comments on commit a16bd0f

Please sign in to comment.