-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: Extract TxAuthManager/TxManager logic via delegatecall to resolve contract size limit #26
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
783732c
feat: split contracts
YukiTsuchida 4814cc4
fix: solhint
YukiTsuchida e64ef59
fix: update TxRunner import and adjust TxManager contract implementation
YukiTsuchida c72ecd1
feat: add reentrancy guard to Initiator contract
YukiTsuchida b60a14b
fix: correct condition in _runTxIfCompleted to verify transaction status
YukiTsuchida 2a52e64
fix: remove unused TxRunnerBase import from TxManager and update cont…
YukiTsuchida 41459e0
feat: add InitiateTx e2e
YukiTsuchida 14ed477
refactor: change function visibility from view to non-view for auth a…
YukiTsuchida 411101b
chore: update solc_version to 0.8.30 and enable via_ir in foundry.toml
YukiTsuchida 6e84296
refactor: streamline delegatecall error handling and consolidate erro…
YukiTsuchida 8878dce
refactor: introduce ICrossError interface and replace error handling …
YukiTsuchida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // solhint-disable avoid-low-level-calls | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import {TxAuthManagerBase} from "./TxAuthManagerBase.sol"; | ||
| import {TxManagerBase} from "./TxManagerBase.sol"; | ||
| import {ITxAuthManager} from "./ITxAuthManager.sol"; | ||
| import {ITxManager} from "./ITxManager.sol"; | ||
|
|
||
| import {MsgInitiateTx} from "../proto/cross/core/initiator/Initiator.sol"; | ||
| import {Account, TxAuthState} from "../proto/cross/core/auth/Auth.sol"; | ||
|
|
||
| abstract contract DelegatedLogicHandler is TxAuthManagerBase, TxManagerBase { | ||
| address public immutable TX_AUTH_MANAGER; | ||
| address public immutable TX_MANAGER; | ||
|
|
||
| error DelegateCallAuthFailed(); | ||
| error DelegateCallTxFailed(); | ||
| error StaticCallAuthFailed(); | ||
| error StaticCallTxFailed(); | ||
mattsu6666 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| constructor(address txAuthManager_, address txManager_) { | ||
| TX_AUTH_MANAGER = txAuthManager_; | ||
| TX_MANAGER = txManager_; | ||
| } | ||
|
|
||
| function _initAuthState(bytes32 txID, Account.Data[] memory signers) internal virtual override { | ||
mattsu6666 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (bool success,) = | ||
| TX_AUTH_MANAGER.delegatecall(abi.encodeWithSelector(ITxAuthManager.initAuthState.selector, txID, signers)); | ||
| if (!success) revert DelegateCallAuthFailed(); | ||
mattsu6666 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| function _sign(bytes32 txID, Account.Data[] memory signers) internal virtual override returns (bool) { | ||
| (bool success, bytes memory ret) = | ||
| TX_AUTH_MANAGER.delegatecall(abi.encodeWithSelector(ITxAuthManager.sign.selector, txID, signers)); | ||
| if (!success) revert DelegateCallAuthFailed(); | ||
| return abi.decode(ret, (bool)); | ||
| } | ||
|
|
||
| function _isCompletedAuth(bytes32 txID) internal virtual override returns (bool) { | ||
| (bool success, bytes memory ret) = | ||
| TX_AUTH_MANAGER.delegatecall(abi.encodeWithSelector(ITxAuthManager.isCompletedAuth.selector, txID)); | ||
| if (!success) revert DelegateCallAuthFailed(); | ||
| return abi.decode(ret, (bool)); | ||
| } | ||
|
|
||
| function _getAuthState(bytes32 txID) internal virtual override returns (TxAuthState.Data memory) { | ||
| (bool success, bytes memory ret) = | ||
| TX_AUTH_MANAGER.delegatecall(abi.encodeWithSelector(ITxAuthManager.getAuthState.selector, txID)); | ||
| if (!success) revert DelegateCallAuthFailed(); | ||
| return abi.decode(ret, (TxAuthState.Data)); | ||
| } | ||
|
|
||
| function _createTx(bytes32 txID, MsgInitiateTx.Data calldata src) internal virtual override { | ||
| (bool success,) = TX_MANAGER.delegatecall(abi.encodeWithSelector(ITxManager.createTx.selector, txID, src)); | ||
| if (!success) revert DelegateCallTxFailed(); | ||
| } | ||
|
|
||
| function _runTxIfCompleted(bytes32 txID) internal virtual override { | ||
| (bool success,) = TX_MANAGER.delegatecall(abi.encodeWithSelector(ITxManager.runTxIfCompleted.selector, txID)); | ||
| if (!success) revert DelegateCallTxFailed(); | ||
| } | ||
|
|
||
| function _isTxRecorded(bytes32 txID) internal virtual override returns (bool) { | ||
| (bool success, bytes memory ret) = | ||
| TX_MANAGER.delegatecall(abi.encodeWithSelector(ITxManager.isTxRecorded.selector, txID)); | ||
| if (!success) revert DelegateCallTxFailed(); | ||
| return abi.decode(ret, (bool)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import {Account, TxAuthState} from "../proto/cross/core/auth/Auth.sol"; | ||
|
|
||
| interface ITxAuthManager { | ||
| function initAuthState(bytes32 txID, Account.Data[] calldata signers) external; | ||
| function isCompletedAuth(bytes32 txID) external returns (bool); | ||
| function sign(bytes32 txID, Account.Data[] calldata signers) external returns (bool); | ||
| function getAuthState(bytes32 txID) external returns (TxAuthState.Data memory); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import {MsgInitiateTx} from "../proto/cross/core/initiator/Initiator.sol"; | ||
|
|
||
| interface ITxManager { | ||
| function createTx(bytes32 txID, MsgInitiateTx.Data calldata src) external; | ||
| function runTxIfCompleted(bytes32 txID) external; | ||
| function isTxRecorded(bytes32 txID) external returns (bool); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy sample