Skip to content

Commit

Permalink
fix(eth-multisig-v4): add chain id of the coin in the network identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
gianchandania committed Dec 18, 2023
1 parent 953f3d2 commit 812f80c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
17 changes: 9 additions & 8 deletions contracts/WalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './IForwarder.sol';
/** ERC721, ERC1155 imports */
import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol';
import '@openzeppelin/contracts/utils/Strings.sol';

/**
*
Expand All @@ -29,8 +30,8 @@ import '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol';
* Unlike eth_sign, the message is not prefixed.
*
* The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime).
* For ether transactions, `prefix` is "ETHER".
* For token transaction, `prefix` is "ERC20" and `data` is the tokenContractAddress.
* For ether transactions, `prefix` is chain id of the coin i.e. for eth mainnet it is "1".
* For token transaction, `prefix` is chain id + "-ERC20" i.e. for mainnet it is "1-ERC20" and `data` is the tokenContractAddress.
*
*
*/
Expand Down Expand Up @@ -93,8 +94,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getNetworkId() internal pure virtual returns (string memory) {
return 'ETHER';
function getNetworkId() internal view virtual returns (string memory) {
return Strings.toString(block.chainid);
}

/**
Expand All @@ -105,8 +106,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getTokenNetworkId() internal pure virtual returns (string memory) {
return 'ERC20';
function getTokenNetworkId() internal view virtual returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-ERC20');
}

/**
Expand All @@ -117,8 +118,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getBatchNetworkId() internal pure virtual returns (string memory) {
return 'ETHER-Batch';
function getBatchNetworkId() internal view virtual returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-Batch');
}

/**
Expand Down
16 changes: 8 additions & 8 deletions contracts/coins/ArbethWalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import '../WalletSimple.sol';
* Unlike eth_sign, the message is not prefixed.
*
* The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime).
* For ether transactions, `prefix` is "ARBETH".
* For token transaction, `prefix` is "ARBETH-ERC20" and `data` is the tokenContractAddress.
* For ether transactions, `prefix` is chain id of the coin i.e. for arbitrum mainnet it is "42161"
* For token transaction, `prefix` is "42161-ERC20" and `data` is the tokenContractAddress.
*
*
*/
Expand All @@ -35,23 +35,23 @@ contract ArbethWalletSimple is WalletSimple {
* Get the network identifier that signers must sign over
* This provides protection signatures being replayed on other chains
*/
function getNetworkId() internal override pure returns (string memory) {
return 'ARBETH';
function getNetworkId() internal override view returns (string memory) {
return Strings.toString(block.chainid);
}

/**
* Get the network identifier that signers must sign over for token transfers
* This provides protection signatures being replayed on other chains
*/
function getTokenNetworkId() internal override pure returns (string memory) {
return 'ARBETH-ERC20';
function getTokenNetworkId() internal override view returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-ERC20');
}

/**
* Get the network identifier that signers must sign over for batch transfers
* This provides protection signatures being replayed on other chains
*/
function getBatchNetworkId() internal override pure returns (string memory) {
return 'ARBETH-Batch';
function getBatchNetworkId() internal override view returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-Batch');
}
}
16 changes: 8 additions & 8 deletions contracts/coins/OpethWalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import '../WalletSimple.sol';
* Unlike eth_sign, the message is not prefixed.
*
* The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime).
* For ether transactions, `prefix` is "OPETH".
* For token transaction, `prefix` is "OPETH-ERC20" and `data` is the tokenContractAddress.
* For ether transactions, `prefix` is chain id of the coin i.e. for optimism mainnet it is "10"
* For token transaction, `prefix` is "10-ERC20" and `data` is the tokenContractAddress.
*
*
*/
Expand All @@ -35,23 +35,23 @@ contract OpethWalletSimple is WalletSimple {
* Get the network identifier that signers must sign over
* This provides protection signatures being replayed on other chains
*/
function getNetworkId() internal override pure returns (string memory) {
return 'OPETH';
function getNetworkId() internal override view returns (string memory) {
return Strings.toString(block.chainid);
}

/**
* Get the network identifier that signers must sign over for token transfers
* This provides protection signatures being replayed on other chains
*/
function getTokenNetworkId() internal override pure returns (string memory) {
return 'OPETH-ERC20';
function getTokenNetworkId() internal override view returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-ERC20');
}

/**
* Get the network identifier that signers must sign over for batch transfers
* This provides protection signatures being replayed on other chains
*/
function getBatchNetworkId() internal override pure returns (string memory) {
return 'OPETH-Batch';
function getBatchNetworkId() internal override view returns (string memory) {
return string.concat(Strings.toString(block.chainid), '-Batch');
}
}

0 comments on commit 812f80c

Please sign in to comment.