Add double update whitelist and test (#18)

nambrot/optics-ts-interface
Asa Oines 3 years ago committed by GitHub
parent c0feec3770
commit eff640f880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      solidity/optics-core/contracts/Common.sol
  2. 25
      typescript/optics-tests/test/common.test.ts
  3. 2
      typescript/typechain/optics-core/factories/GovernanceRouter__factory.ts
  4. 2
      typescript/typechain/optics-core/factories/Home__factory.ts
  5. 2
      typescript/typechain/optics-core/factories/Replica__factory.ts
  6. 2
      typescript/typechain/optics-core/factories/TestCommon__factory.ts
  7. 2
      typescript/typechain/optics-core/factories/TestGovernanceRouter__factory.ts
  8. 2
      typescript/typechain/optics-core/factories/TestHome__factory.ts
  9. 2
      typescript/typechain/optics-core/factories/TestMessage__factory.ts
  10. 2
      typescript/typechain/optics-core/factories/TestReplica__factory.ts
  11. 2
      typescript/typechain/optics-core/factories/TestXAppConnectionManager__factory.ts
  12. 2
      typescript/typechain/optics-core/factories/UpdaterManager__factory.ts
  13. 2
      typescript/typechain/optics-core/factories/XAppConnectionManager__factory.ts
  14. 2
      typescript/typechain/optics-xapps/factories/BridgeRouter__factory.ts
  15. 2
      typescript/typechain/optics-xapps/factories/BridgeToken__factory.ts
  16. 2
      typescript/typechain/optics-xapps/factories/ETHHelper__factory.ts
  17. 2
      typescript/typechain/optics-xapps/factories/Home__factory.ts
  18. 2
      typescript/typechain/optics-xapps/factories/MockWeth__factory.ts
  19. 2
      typescript/typechain/optics-xapps/factories/Replica__factory.ts
  20. 2
      typescript/typechain/optics-xapps/factories/RouterTemplate__factory.ts
  21. 2
      typescript/typechain/optics-xapps/factories/XAppConnectionManager__factory.ts

@ -123,7 +123,8 @@ abstract contract Common is Initializable {
if (
Common._isUpdaterSignature(_oldRoot, _newRoot[0], _signature) &&
Common._isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) &&
_newRoot[0] != _newRoot[1]
_newRoot[0] != _newRoot[1] &&
!Common._isBenignDoubleUpdate(_oldRoot)
) {
_fail();
emit DoubleUpdate(_oldRoot, _newRoot, _signature, _signature2);
@ -185,4 +186,30 @@ abstract contract Common is Initializable {
_digest = ECDSA.toEthSignedMessageHash(_digest);
return (ECDSA.recover(_digest, _signature) == updater);
}
/**
* @notice Checks that a root is in a whitelist for which double updates
* are not enforced.
* @param _oldRoot Old merkle root
* @return TRUE iff the provided root is in the whitelist
**/
function _isBenignDoubleUpdate(bytes32 _oldRoot)
internal
view
returns (bool)
{
// The Polygon home temporarily forked from its replicas at this
// root due to a chain reorg.
// Polygon update txHash:
// 0x9cbe36b8d5365df013f138421b99283c014bbeee08f9c3b1f19ae428511e94ba
// Ethereum update txHash:
// 0xe8df2fc845356c1c75206982f8b707e8e5354c72a2ed250fcf839cbbf11101f9
// The fork was benign, as all roots were commitments to the same set
// of messages. The fork was resolved and therefore the system should
// not halt when presented with any double update that builds off of
// this root.
return
_oldRoot ==
0xde6e3d4540f861d08dfe4ac16334792de2fb44aa7bcd5b657238410791c67a81;
}
}

@ -94,6 +94,31 @@ describe('Common', async () => {
expect(state).to.equal(OpticsState.ACTIVE);
});
it('Does not fail contract on whitelisted double update proof', async () => {
const oldRoot = ethers.utils.hexlify(
'0xde6e3d4540f861d08dfe4ac16334792de2fb44aa7bcd5b657238410791c67a81');
const newRoot = ethers.utils.formatBytes32String('new root 1');
const newRoot2 = ethers.utils.formatBytes32String('new root 2');
const { signature } = await updater.signUpdate(oldRoot, newRoot);
const { signature: signature2 } = await updater.signUpdate(
oldRoot,
newRoot2,
);
await common.doubleUpdate(
oldRoot,
[newRoot, newRoot2],
signature,
signature2
);
// State should not be failed because double update proof is whitelisted
const state = await common.state();
expect(state).not.to.equal(OpticsState.FAILED);
expect(state).to.equal(OpticsState.ACTIVE);
});
it('Checks Rust-produced SignedUpdate', async () => {
// Compare Rust output in json file to solidity output
for (let testCase of signedUpdateTestCases) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -160,7 +160,7 @@ const _abi = [
];
const _bytecode =
"0x60806040526040516109663803806109668339818101604052602081101561002657600080fd5b505160006100326100a1565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350600280546001600160a01b0319166001600160a01b03929092169190911790556100a5565b3390565b6108b2806100b46000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638da5cb5b1161005b5780638da5cb5b146100f25780639d54f41914610123578063df034cd014610156578063f2fde38b1461015e5761007d565b80635b3c2cbf146100825780636ef0f37f146100b7578063715018a6146100ea575b600080fd5b6100b56004803603602081101561009857600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610191565b005b6100b5600480360360208110156100cd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610263565b6100b56103f8565b6100fa61050f565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6100b56004803603602081101561013957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661052b565b6100fa61068f565b6100b56004803603602081101561017457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106ab565b60015473ffffffffffffffffffffffffffffffffffffffff16331461021757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f21686f6d65000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8316815290517f4180932f5f5f11458bcd408e42c54626987799e7c4c89f40f484fefdfdfff14f9181900360200190a150565b61026b61084c565b73ffffffffffffffffffffffffffffffffffffffff1661028961050f565b73ffffffffffffffffffffffffffffffffffffffff161461030b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61031481610850565b61037f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f21636f6e747261637420686f6d65000000000000000000000000000000000000604482015290519081900360640190fd5b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517fa6c230e5615262e310dcb42eaf014e813e5d8580abf5b00d2186ca8e9833de219181900360200190a150565b61040061084c565b73ffffffffffffffffffffffffffffffffffffffff1661041e61050f565b73ffffffffffffffffffffffffffffffffffffffff16146104a057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b61053361084c565b73ffffffffffffffffffffffffffffffffffffffff1661055161050f565b73ffffffffffffffffffffffffffffffffffffffff16146105d357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff838116918217909255600154604080517f9d54f419000000000000000000000000000000000000000000000000000000008152600481019390935251921691639d54f4199160248082019260009290919082900301818387803b15801561067457600080fd5b505af1158015610688573d6000803e3d6000fd5b5050505050565b60025473ffffffffffffffffffffffffffffffffffffffff1690565b6106b361084c565b73ffffffffffffffffffffffffffffffffffffffff166106d161050f565b73ffffffffffffffffffffffffffffffffffffffff161461075357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166107bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806108576026913960400191505060405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b3390565b3b15159056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a2646970667358221220db9c5aaeb936dc32795f223791fd3369365d34bae42fd53bf501ca6880f8614564736f6c63430007060033";
"0x60806040526040516109663803806109668339818101604052602081101561002657600080fd5b505160006100326100a1565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350600280546001600160a01b0319166001600160a01b03929092169190911790556100a5565b3390565b6108b2806100b46000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638da5cb5b1161005b5780638da5cb5b146100f25780639d54f41914610123578063df034cd014610156578063f2fde38b1461015e5761007d565b80635b3c2cbf146100825780636ef0f37f146100b7578063715018a6146100ea575b600080fd5b6100b56004803603602081101561009857600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610191565b005b6100b5600480360360208110156100cd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610263565b6100b56103f8565b6100fa61050f565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6100b56004803603602081101561013957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661052b565b6100fa61068f565b6100b56004803603602081101561017457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106ab565b60015473ffffffffffffffffffffffffffffffffffffffff16331461021757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f21686f6d65000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8316815290517f4180932f5f5f11458bcd408e42c54626987799e7c4c89f40f484fefdfdfff14f9181900360200190a150565b61026b61084c565b73ffffffffffffffffffffffffffffffffffffffff1661028961050f565b73ffffffffffffffffffffffffffffffffffffffff161461030b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61031481610850565b61037f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f21636f6e747261637420686f6d65000000000000000000000000000000000000604482015290519081900360640190fd5b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff0000000000000000000000000000000000000000909116811790915560408051918252517fa6c230e5615262e310dcb42eaf014e813e5d8580abf5b00d2186ca8e9833de219181900360200190a150565b61040061084c565b73ffffffffffffffffffffffffffffffffffffffff1661041e61050f565b73ffffffffffffffffffffffffffffffffffffffff16146104a057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b61053361084c565b73ffffffffffffffffffffffffffffffffffffffff1661055161050f565b73ffffffffffffffffffffffffffffffffffffffff16146105d357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff838116918217909255600154604080517f9d54f419000000000000000000000000000000000000000000000000000000008152600481019390935251921691639d54f4199160248082019260009290919082900301818387803b15801561067457600080fd5b505af1158015610688573d6000803e3d6000fd5b5050505050565b60025473ffffffffffffffffffffffffffffffffffffffff1690565b6106b361084c565b73ffffffffffffffffffffffffffffffffffffffff166106d161050f565b73ffffffffffffffffffffffffffffffffffffffff161461075357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166107bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806108576026913960400191505060405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b3390565b3b15159056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373a2646970667358221220661866642545e6124a0b9a034735a166576624c9394469f8cfef14ec8c840da864736f6c63430007060033";
export class UpdaterManager__factory extends ContractFactory {
constructor(signer?: Signer) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -101,7 +101,7 @@ const _abi = [
];
const _bytecode =
"0x60c060405234801561001057600080fd5b5060405161045d38038061045d8339818101604052604081101561003357600080fd5b5080516020909101516001600160601b0319606083811b821660805282901b1660a0526040805163095ea7b360e01b81526001600160a01b038084166004830152600019602483015291519184169163095ea7b39160448082019260009290919082900301818387803b1580156100a957600080fd5b505af11580156100bd573d6000803e3d6000fd5b50505050505060805160601c60a05160601c6103626100fb6000398061023e52806102e052508061014152806101fb52806102bc52506103626000f3fe60806040526004361061005a5760003560e01c80633fc8cef3116100435780633fc8cef3146100ad578063e78cea92146100eb578063ec93e5f0146101005761005a565b806303c1d2831461005f5780632e96d5a31461008a575b600080fd5b6100886004803603604081101561007557600080fd5b5063ffffffff813516906020013561013f565b005b610088600480360360208110156100a057600080fd5b503563ffffffff166102a5565b3480156100b957600080fd5b506100c26102ba565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100f757600080fd5b506100c26102de565b6100886004803603604081101561011657600080fd5b50803563ffffffff16906020013573ffffffffffffffffffffffffffffffffffffffff16610302565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156101a757600080fd5b505af11580156101bb573d6000803e3d6000fd5b5050604080517f1cabf08f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000008116600483015234602483015263ffffffff881660448301526064820187905291517f00000000000000000000000000000000000000000000000000000000000000009092169450631cabf08f9350608480820193506000929182900301818387803b15801561028957600080fd5b505af115801561029d573d6000803e3d6000fd5b505050505050565b6102b7816102b233610313565b61013f565b50565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61030f826102b283610313565b5050565b73ffffffffffffffffffffffffffffffffffffffff169056fea2646970667358221220a155e8a014a65961277ee1f1f9d43d494403f67b6c1e5e4b08c78cc7cb5e87e564736f6c63430007060033";
"0x60c060405234801561001057600080fd5b5060405161045d38038061045d8339818101604052604081101561003357600080fd5b5080516020909101516001600160601b0319606083811b821660805282901b1660a0526040805163095ea7b360e01b81526001600160a01b038084166004830152600019602483015291519184169163095ea7b39160448082019260009290919082900301818387803b1580156100a957600080fd5b505af11580156100bd573d6000803e3d6000fd5b50505050505060805160601c60a05160601c6103626100fb6000398061023e52806102e052508061014152806101fb52806102bc52506103626000f3fe60806040526004361061005a5760003560e01c80633fc8cef3116100435780633fc8cef3146100ad578063e78cea92146100eb578063ec93e5f0146101005761005a565b806303c1d2831461005f5780632e96d5a31461008a575b600080fd5b6100886004803603604081101561007557600080fd5b5063ffffffff813516906020013561013f565b005b610088600480360360208110156100a057600080fd5b503563ffffffff166102a5565b3480156100b957600080fd5b506100c26102ba565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100f757600080fd5b506100c26102de565b6100886004803603604081101561011657600080fd5b50803563ffffffff16906020013573ffffffffffffffffffffffffffffffffffffffff16610302565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156101a757600080fd5b505af11580156101bb573d6000803e3d6000fd5b5050604080517f1cabf08f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000008116600483015234602483015263ffffffff881660448301526064820187905291517f00000000000000000000000000000000000000000000000000000000000000009092169450631cabf08f9350608480820193506000929182900301818387803b15801561028957600080fd5b505af115801561029d573d6000803e3d6000fd5b505050505050565b6102b7816102b233610313565b61013f565b50565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61030f826102b283610313565b5050565b73ffffffffffffffffffffffffffffffffffffffff169056fea2646970667358221220d4d04f05da89756c553be37e6bc15b8949ae48f4046303462de7b16cdd88c15564736f6c63430007060033";
export class ETHHelper__factory extends ContractFactory {
constructor(signer?: Signer) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save