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

Extract GMP specific logic out of bridge contracts #51

Merged
merged 8 commits into from
Nov 23, 2023

Conversation

ermyas
Copy link
Collaborator

@ermyas ermyas commented Nov 22, 2023

At present, the RootERC20Bridge and ChildERC20Bridge implementations are implicitly linked to Axelar-specific details, such as chain names for chain IDs and string contract addresses. This PR moves these details from the bridge contract to the respective bridge adaptors. A crucial part of this refactor is that the validation of a message's source (i.e., source chain and source address) is now carried out at the bridge adaptor, not at the bridge.

This PR addresses SMR-2023, SMR-2024, SMR-2026

@platform-sa
Copy link

platform-sa commented Nov 22, 2023

📃CI Report

Compiling 146 files with 0.8.19
Solc 0.8.19 finished in 15.75s
Compiler run �[32msuccessful!�[0m
Analysing contracts...
Running tests...

File % Lines % Statements % Branches % Funcs
script/DeployChildContracts.s.sol 0.00% (0/22) 0.00% (0/32) 100.00% (0/0) 0.00% (0/1)
script/DeployRootContracts.s.sol 0.00% (0/23) 0.00% (0/33) 0.00% (0/2) 0.00% (0/1)
script/InitializeChildContracts.s.sol 0.00% (0/11) 0.00% (0/17) 100.00% (0/0) 0.00% (0/1)
script/InitializeRootContracts.s.sol 0.00% (0/11) 0.00% (0/17) 100.00% (0/0) 0.00% (0/1)
script/Utils.sol 0.00% (0/12) 0.00% (0/16) 0.00% (0/2) 0.00% (0/2)
src/child/ChildAxelarBridgeAdaptor.sol 100.00% (48/48) 100.00% (65/65) 100.00% (22/22) 100.00% (7/7)
src/child/ChildERC20.sol 100.00% (14/14) 100.00% (15/15) 50.00% (1/2) 100.00% (7/7)
src/child/ChildERC20Bridge.sol 96.92% (126/130) 97.73% (172/176) 94.29% (66/70) 100.00% (21/21)
src/child/WIMX.sol 0.00% (0/19) 0.00% (0/22) 0.00% (0/8) 0.00% (0/6)
src/common/AdaptorRoles.sol 100.00% (6/6) 100.00% (6/6) 100.00% (0/0) 100.00% (6/6)
src/common/BridgeRoles.sol 100.00% (8/8) 100.00% (8/8) 100.00% (0/0) 100.00% (8/8)
src/lib/EIP712MetaTransaction.sol 8.00% (2/25) 9.68% (3/31) 8.33% (1/12) 14.29% (1/7)
src/lib/EIP712Upgradeable.sol 73.33% (11/15) 60.87% (14/23) 0.00% (0/2) 50.00% (2/4)
src/lib/WETH.sol 100.00% (19/19) 100.00% (22/22) 100.00% (8/8) 100.00% (6/6)
src/root/RootAxelarBridgeAdaptor.sol 100.00% (48/48) 100.00% (65/65) 100.00% (22/22) 100.00% (7/7)
src/root/RootERC20Bridge.sol 93.60% (117/125) 95.56% (172/180) 87.50% (49/56) 90.91% (20/22)
src/root/flowrate/FlowRateDetection.sol 90.00% (27/30) 90.91% (30/33) 78.57% (11/14) 100.00% (4/4)
src/root/flowrate/FlowRateWithdrawalQueue.sol 67.39% (31/46) 61.67% (37/60) 50.00% (7/14) 85.71% (6/7)
src/root/flowrate/RootERC20BridgeFlowRate.sol 100.00% (43/43) 98.00% (49/50) 100.00% (10/10) 100.00% (9/9)

For a full HTML report run: forge coverage --report lcov && genhtml --ignore-errors category --branch-coverage --output-dir coverage lcov.info

@@ -43,7 +43,7 @@ contract InitializeChildContracts is Script {
childERC20Bridge: ChildERC20Bridge(payable(vm.envAddress("CHILD_ERC20_BRIDGE"))),
childAxelarBridgeAdaptor: ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")),
childTokenTemplate: vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE"),
rootERC20BridgeAdaptor: vm.envAddress("ROOT_BRIDGE_ADAPTOR"),
rootBridgeAdaptor: vm.envAddress("ROOT_BRIDGE_ADAPTOR"),
Copy link
Contributor

Choose a reason for hiding this comment

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

QQ, with the introduction of @wcgcyx's scripts, what purpose do these forge scripts hold?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question. I believe @wcgcyx PR will remove these scripts once it is merged.

src/child/ChildERC20Bridge.sol Show resolved Hide resolved
*/
interface IChildERC20BridgeAdaptor {
interface IChildBridgeAdaptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, I see this being generalizable across other asset types

rootBridgeAdaptor = IRootERC20BridgeAdaptor(newRootBridgeAdaptor);
childBridgeAdaptor = newChildBridgeAdaptor;
childChain = newChildChain;
rootBridgeAdaptor = IRootBridgeAdaptor(newRootBridgeAdaptor);
Copy link
Contributor

Choose a reason for hiding this comment

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

not for this PR perhaps, but is it worth integrating ERC165 into the adaptor? That is we can check interface IDs on adaptor updating?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I agree! I'll capture this on Jira for a future PR.

Copy link
Contributor

@proletesseract proletesseract left a comment

Choose a reason for hiding this comment

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

LGTM

@ermyas ermyas merged commit b4dfa44 into main Nov 23, 2023
4 checks passed
@ermyas ermyas deleted the SMR-2021/refactor/bridge-and-adaptors branch April 12, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants