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

feat(contracts): add new forwarder contracts #108

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

gianchandania
Copy link
Contributor

@gianchandania gianchandania commented Sep 27, 2023

This PR adds 3 contracts ForwarderV4.sol, ForwarderFactoryV4.sol and IForwarderV4.sol

Change in contracts (as compared to Forwarder.sol and ForwarderFactory.sol) is that we have added feeAddress as an address that will be one of the allowed addresses to call the methods of the contract along with parentAddress. This means the methods to flush the tokens, etc can be called using the gas tank address. Apart from this batchFlushERC20Tokens method to batch flush erc20 tokens has been added to the ForwarderV4 contract

WIN-506

@gianchandania gianchandania temporarily deployed to dev September 27, 2023 16:45 — with GitHub Actions Inactive
Copy link
Contributor

@sachushaji sachushaji left a comment

Choose a reason for hiding this comment

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

Nice Work !!! :heart , Small comments

// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
address public feeAddress;
mapping(address => bool) public whiteListedAddresses;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are not adding a function to update whiteListedAddresses with additional addresses, Do we need to add this mapping?, Just need to have a comparison in the modifier to check the address is parentAddress or feeAddress, But if using mapping uses lesser gas, Its okay

Copy link
Contributor Author

@gianchandania gianchandania Oct 9, 2023

Choose a reason for hiding this comment

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

Modified this and removed mapping

Comment on lines 34 to 35
parentAddress = _parentAddress;
feeAddress = _feeAddress;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add null address checks here in constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@gianchandania gianchandania force-pushed the WIN-506-update-forwarder-contracts branch from 937e1d6 to a486408 Compare October 4, 2023 13:49
@gianchandania gianchandania force-pushed the WIN-506-update-forwarder-contracts branch from 8da20d3 to 26c90ef Compare October 8, 2023 11:23
@gianchandania gianchandania force-pushed the WIN-506-update-forwarder-contracts branch from 26c90ef to 0923ba1 Compare October 8, 2023 11:25
@gianchandania gianchandania temporarily deployed to dev October 8, 2023 11:34 — with GitHub Actions Inactive
@gianchandania gianchandania temporarily deployed to dev October 8, 2023 11:34 — with GitHub Actions Inactive
@gianchandania gianchandania force-pushed the WIN-506-update-forwarder-contracts branch from 93dd8fa to 320df67 Compare October 8, 2023 11:35
@gianchandania gianchandania temporarily deployed to dev October 8, 2023 11:35 — with GitHub Actions Inactive
@gianchandania gianchandania temporarily deployed to dev October 8, 2023 16:50 — with GitHub Actions Inactive
@gianchandania
Copy link
Contributor Author

I think we shall move to eth-multisig-v6. Mixing with v4 seems confusing. We also need to add a README on how the new forwarder works with a non-contract base

@barathcj Can you please share your thoughts on moving these updated contracts to a new eth-multisig-v6 repo

Copy link
Contributor

@mullapudipruthvik mullapudipruthvik left a comment

Choose a reason for hiding this comment

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

My Questions can be little vague, just thinking of all possible negative cases

onlyAllowedAddress
{
address forwarderAddress = address(this);
uint256 length = tokenContractAddresses.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a max length check here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its okay not to have that, if it exceeds beyond a single transaction could handle, we should be getting a gaslimit error, Also the implementation of the token also matters when it comes to number of transactions we can do too.

address forwarderAddress = address(this);
uint256 length = tokenContractAddresses.length;
for (uint256 i; i < length; i++) {
ERC20Interface instance = ERC20Interface(tokenContractAddresses[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if tokenContractAddresses[i] is not an erc20 contract address
also incase we pass the same erc20 contract address twice, I think forwarderBalance check will go through for both cases
In this case, do we see partial failures or the whole tx fails?

Copy link
Contributor Author

@gianchandania gianchandania Dec 27, 2023

Choose a reason for hiding this comment

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

If we pass the same token address multiple times, then it doesn't seem to be causing any failures or something, it just seem to be performing the tx once. https://sepolia.arbiscan.io/tx/0x82a819eed6b4ee0b87d40893bd92faf99db2f731074d1f65c548966e1a62face

Also if the token address passed is not an erc20 contract address, then it seems to be erroring during the gas estimate itself, so shouldn't be an issue of partial or whole tx failure

/**
* @inheritdoc IForwarderV4
*/
function batchFlushERC20Tokens(address[] calldata tokenContractAddresses)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you set some context on how are we doing to use this function from application side

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to batch token flushes together, should help in better gas savings.

address target,
uint256 value,
bytes calldata data
) external onlyAllowedAddress returns (bytes memory) {
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering do we have to allow feeAddress here as well ?
cause using feeAddr we can move funds to any address

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a valid point. Bitgo on its own shouldn't be able to move any funds. This function should only be used in exceptional cases any ways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this, now only parent address will be able to call this method

) external onlyUninitialized {
require(_parentAddress != address(0x0), 'Invalid parent address');
parentAddress = _parentAddress;
require(_feeAddress != address(0x0), 'Invalid fee address');
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add feeAddr != parentAddr?
maybe we would be over doing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think probably no need for this

/// @notice Address which is allowed to call methods on this contract alongwith the parentAddress
address public feeAddress;
bool public autoFlush721 = true;
bool public autoFlush1155 = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

ok thanks for the comparison. It is weird that arbitrum gas is twice than of optimism. Anyway, not a blocker but something to keep in mind in the future

@gianchandania
Copy link
Contributor Author

For this comment, #108 (comment) actually arbitrum gas vary drastically probably because there is this L1 part of the gas which depend on the base fees of the Eth network

Copy link
Contributor

@sachushaji sachushaji left a comment

Choose a reason for hiding this comment

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

Nice Work!!!

@grsind19 grsind19 merged commit 9c9c541 into master Dec 28, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants