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

chore(ethers): change to ethers and upgrade dependencies #55

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

jurajpiar
Copy link
Member

@jurajpiar jurajpiar commented Sep 5, 2022

What

  • replaces Web3 with ethers.js
  • replaces Truffle with Hardhat
  • adapt contracts to 0.8.9 solidity version
  • replaces prettier solhint checks with hardhat solhint plugin

Why

  • to upgrade the library

@jurajpiar jurajpiar force-pushed the feature/PP-278/PP-329/upgrade_contracts branch 2 times, most recently from cde87f0 to b013360 Compare September 14, 2022 10:15
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Sep 14, 2022

This pull request fixes 1 alert when merging b013360 into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Sep 16, 2022

This pull request fixes 1 alert when merging 1f8a91a into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@jurajpiar jurajpiar changed the title chore(upgrade): change to ethers and updgrade dependencies chore(ethers): change to ethers and updgrade dependencies Sep 19, 2022
@jurajpiar jurajpiar changed the title chore(ethers): change to ethers and updgrade dependencies chore(ethers): change to ethers and upgrade dependencies Sep 19, 2022
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Sep 26, 2022

This pull request fixes 1 alert when merging b3ca582 into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Sep 28, 2022

This pull request fixes 1 alert when merging d65de2a into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 4, 2022

This pull request fixes 1 alert when merging dc471e9 into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 4, 2022

This pull request fixes 1 alert when merging 0b966f5 into aa2c585 - view on LGTM.com

fixed alerts:

  • 1 for Unused variable, import, function or class

Copy link
Contributor

@ironFe93 ironFe93 left a comment

Choose a reason for hiding this comment

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

left a comment, please review

}
};

export const writeConfiig = (config: NetworkAddresses) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const writeConfiig = (config: NetworkAddresses) => {
export const writeConfig = (config: NetworkAddresses) => {

const contractAddresses = await deployContracts();
console.table(contractAddresses);
const newConfig = generateJsonConfig(contractAddresses);
writeConfiig(newConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
writeConfiig(newConfig);
writeConfig(newConfig);

Copy link
Member Author

Choose a reason for hiding this comment

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

done

test/scripts/deploy.test.ts Outdated Show resolved Hide resolved
@jurajpiar jurajpiar force-pushed the feature/PP-278/PP-329/upgrade_contracts branch 4 times, most recently from d3ac8a4 to 2c76164 Compare October 5, 2022 10:33
@jurajpiar
Copy link
Member Author

I invite you to rebase this on master now to resolve conflicts.

@AndresQuijano AndresQuijano force-pushed the feature/PP-278/PP-329/upgrade_contracts branch from 27f6402 to 4e596d3 Compare October 14, 2022 16:55
@antomor antomor force-pushed the feature/PP-278/PP-329/upgrade_contracts branch 2 times, most recently from daed972 to 9661766 Compare October 21, 2022 13:43
contracts/smartwallet/SmartWallet.sol Fixed Show fixed Hide fixed
contracts/smartwallet/CustomSmartWallet.sol Fixed Show fixed Hide fixed
validShares(_partners)
{
RevenuePartner[] memory partners,
address remainderAddress

Check notice

Code scanning / Slither

Missing zero address validation

Collector.constructor(address,IERC20,ICollector.RevenuePartner[],address).remainderAddress (contracts/Collector.sol#44) lacks a zero-check on : - _remainderAddress = remainderAddress (contracts/Collector.sol#48)
contracts/Collector.sol Fixed Show fixed Hide fixed
hex"a9059cbb",
tokenRecipient,
tokenAmount));
(bool success, bytes memory ret) = tokenAddr.call{gas: tokenGas}(

Check notice

Code scanning / Slither

Pre-declaration usage of local variables

Variable 'CustomSmartWallet.initialize(address,address,address,address,uint256,uint256,bytes).success (contracts/smartwallet/CustomSmartWallet.sol#318)' in CustomSmartWallet.initialize(address,address,address,address,uint256,uint256,bytes) (contracts/smartwallet/CustomSmartWallet.sol#303-353) potentially used before declaration: (success) = logic.delegatecall(abi.encodeWithSelector(0x439fab91,initParams)) (contracts/smartwallet/CustomSmartWallet.sol#336-338)
Comment on lines 159 to +186
);
}


//Why this require is not needed: in the case that the EVM implementation
//sends gasleft() as req.gas if gasleft() < req.gas (see EIP-1930), which would end in the call reverting
//If the relayer made this on purpose in order to collect the payment, since all gasLeft()
//was sent to this call, then the next line would give an out of gas, and, as a consequence, will
//revert the whole transaction, and the payment will not happen
//But it could happen that the destination call makes a gasleft() check and decides to revert if it is
//not enough, in that case there might be enough gas to complete the relay and the token payment would be collected
//For that reason, the next require line must be left uncommented, to avoid malicious relayer attacks to destination contract
//methods that revert if the gasleft() is not enough to execute whatever logic they have.

require(gasleft() > req.gas,"Not enough gas left");
(success, ret) = req.to.call{gas: req.gas, value: req.value}(req.data);

//If any balance has been added then trasfer it to the owner EOA
uint256 balanceToTransfer = address(this).balance;
if ( balanceToTransfer > 0) {
//can't fail: req.from signed (off-chain) the request, so it must be an EOA...
payable(req.from).transfer(balanceToTransfer);
}

}

function getChainID() private pure returns (uint256 id) {
//Why this require is not needed: in the case that the EVM implementation
//sends gasleft() as req.gas if gasleft() < req.gas (see EIP-1930), which would end in the call reverting
//If the relayer made this on purpose in order to collect the payment, since all gasLeft()
//was sent to this call, then the next line would give an out of gas, and, as a consequence, will
//revert the whole transaction, and the payment will not happen
//But it could happen that the destination call makes a gasleft() check and decides to revert if it is
//not enough, in that case there might be enough gas to complete the relay and the token payment would be collected
//For that reason, the next require line must be left uncommented, to avoid malicious relayer attacks to destination contract
//methods that revert if the gasleft() is not enough to execute whatever logic they have.

require(gasleft() > req.gas, "Not enough gas left");
(success, ret) = req.to.call{gas: req.gas, value: req.value}(req.data);

//If any balance has been added then trasfer it to the owner EOA
uint256 balanceToTransfer = address(this).balance;
if (balanceToTransfer > 0) {
//can't fail: req.from signed (off-chain) the request, so it must be an EOA...
payable(req.from).transfer(balanceToTransfer);
}
}

Check warning

Code scanning / Slither

Low-level calls

Low level call in SmartWallet.execute(bytes32,IForwarder.ForwardRequest,address,bytes) (contracts/smartwallet/SmartWallet.sol#135-181): - (success,ret) = req.tokenContract.call{gas: req.tokenGas}(abi.encodeWithSelector(0xa9059cbb,feesReceiver,req.tokenAmount)) (contracts/smartwallet/SmartWallet.sol#148-154) - (success,ret) = req.to.call{gas: req.gas,value: req.value}(req.data) (contracts/smartwallet/SmartWallet.sol#173)
override
onlyOwner
{
function transferOwnership(address _owner) external override onlyOwner {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Parameter Collector.transferOwnership(address)._owner (contracts/Collector.sol#97) is not in mixedCase
@@ -4,17 +4,17 @@
contract Migrations {
address public owner;
// solhint-disable-next-line var-name-mixedcase
uint public last_completed_migration;
uint256 public last_completed_migration;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Variable Migrations.last_completed_migration (contracts/Migrations.sol#7) is not in mixedCase
Comment on lines +82 to +85
bytes memory dataToCheck1 = abi.encodePacked(
decodedTx1.data,
decodedTx1.gasLimit,
decodedTx1.to,
decodedTx1.value
);

Check warning

Code scanning / Slither

Variable names too similar

Variable Penalizer.penalizeRepeatedNonce(bytes,bytes,bytes,bytes,IRelayHub).dataToCheck1 (contracts/Penalizer.sol#82-87) is too similar to Penalizer.penalizeRepeatedNonce(bytes,bytes,bytes,bytes,IRelayHub).dataToCheck2 (contracts/Penalizer.sol#89-94)
Comment on lines +13 to +14
string public override versionPenalizer =
"2.0.1+enveloping.penalizer.ipenalizer";

Check warning

Code scanning / Slither

State variables that could be declared constant

Penalizer.versionPenalizer (contracts/Penalizer.sol#13-14) should be constant
Comment on lines +18 to +25
function removeToken(address token, uint256 index) external onlyOwner {
require(token != address(0), "Token cannot be zero address");
require(tokens[token] == true, "Token is not accepted");
require(token == acceptedTokens[index], "Wrong token index");
delete tokens[token];
acceptedTokens[index] = acceptedTokens[acceptedTokens.length - 1];
acceptedTokens.pop();
}

Check warning

Code scanning / Slither

Boolean equality

TokenHandler.removeToken(address,uint256) (contracts/TokenHandler.sol#18-25) compares to a boolean constant: -require(bool,string)(tokens[token] == true,Token is not accepted) (contracts/TokenHandler.sol#20)
Comment on lines +11 to +16
function acceptToken(address token) external onlyOwner {
require(token != address(0), "Token cannot be zero address");
require(tokens[token] == false, "Token is already accepted");
tokens[token] = true;
acceptedTokens.push(token);
}

Check warning

Code scanning / Slither

Boolean equality

TokenHandler.acceptToken(address) (contracts/TokenHandler.sol#11-16) compares to a boolean constant: -require(bool,string)(tokens[token] == false,Token is already accepted) (contracts/TokenHandler.sol#13)
@antomor antomor force-pushed the feature/PP-278/PP-329/upgrade_contracts branch from 8a5f55c to 9c2696d Compare November 16, 2022 11:30
{
function penalize(
address relayWorker,
address payable beneficiary

Check notice

Code scanning / Slither

Missing zero address validation

RelayHub.penalize(address,address).beneficiary (contracts/RelayHub.sol#248) lacks a zero-check on : - beneficiary.transfer(reward) (contracts/RelayHub.sol#273)
{

function directExecute(
address to,

Check notice

Code scanning / Slither

Missing zero address validation

CustomSmartWallet.directExecute(address,bytes).to (contracts/smartwallet/CustomSmartWallet.sol#123) lacks a zero-check on : - (success,ret) = to.call{value: msg.value}(data) (contracts/smartwallet/CustomSmartWallet.sol#141)
{

function directExecute(
address to,

Check notice

Code scanning / Slither

Missing zero address validation

SmartWallet.directExecute(address,bytes).to (contracts/smartwallet/SmartWallet.sol#115) lacks a zero-check on : - (success,ret) = to.call{value: msg.value}(data) (contracts/smartwallet/SmartWallet.sol#124)
noBalanceToShare
{
function updateRemainderAddress(
address remainderAddress

Check notice

Code scanning / Slither

Missing zero address validation

Collector.updateRemainderAddress(address).remainderAddress (contracts/Collector.sol#69) lacks a zero-check on : - _remainderAddress = remainderAddress (contracts/Collector.sol#78)
Comment on lines 161 to +186
);
}


//Why this require is not needed: in the case that the EVM implementation
//sends gasleft() as req.gas if gasleft() < req.gas (see EIP-1930), which would end in the call reverting
//If the relayer made this on purpose in order to collect the payment, since all gasLeft()
//was sent to this call, then the next line would give an out of gas, and, as a consequence, will
//revert the whole transaction, and the payment will not happen
//But it could happen that the destination call makes a gasleft() check and decides to revert if it is
//not enough, in that case there might be enough gas to complete the relay and the token payment would be collected
//For that reason, the next require line must be left uncommented, to avoid malicious relayer attacks to destination contract
//methods that revert if the gasleft() is not enough to execute whatever logic they have.

require(gasleft() > req.gas,"Not enough gas left");
(success, ret) = req.to.call{gas: req.gas, value: req.value}(req.data);

//If any balance has been added then trasfer it to the owner EOA
uint256 balanceToTransfer = address(this).balance;
if ( balanceToTransfer > 0) {
//can't fail: req.from signed (off-chain) the request, so it must be an EOA...
payable(req.from).transfer(balanceToTransfer);
}

}

function getChainID() private pure returns (uint256 id) {
//Why this require is not needed: in the case that the EVM implementation
//sends gasleft() as req.gas if gasleft() < req.gas (see EIP-1930), which would end in the call reverting
//If the relayer made this on purpose in order to collect the payment, since all gasLeft()
//was sent to this call, then the next line would give an out of gas, and, as a consequence, will
//revert the whole transaction, and the payment will not happen
//But it could happen that the destination call makes a gasleft() check and decides to revert if it is
//not enough, in that case there might be enough gas to complete the relay and the token payment would be collected
//For that reason, the next require line must be left uncommented, to avoid malicious relayer attacks to destination contract
//methods that revert if the gasleft() is not enough to execute whatever logic they have.

require(gasleft() > req.gas, "Not enough gas left");
(success, ret) = req.to.call{gas: req.gas, value: req.value}(req.data);

//If any balance has been added then trasfer it to the owner EOA
uint256 balanceToTransfer = address(this).balance;
if (balanceToTransfer > 0) {
//can't fail: req.from signed (off-chain) the request, so it must be an EOA...
payable(req.from).transfer(balanceToTransfer);
}
}

Check notice

Code scanning / Slither

Block timestamp

SmartWallet.execute(bytes32,IForwarder.ForwardRequest,address,bytes) (contracts/smartwallet/SmartWallet.sol#133-183) uses timestamp for comparisons Dangerous comparisons: - require(bool,string)(req.validUntilTime == 0 || req.validUntilTime > block.timestamp,SW: request expired) (contracts/smartwallet/SmartWallet.sol#143-146)
@antomor antomor changed the base branch from main to develop January 25, 2023 13:28
@antomor antomor changed the base branch from develop to main January 25, 2023 13:28
@antomor antomor changed the base branch from main to develop January 25, 2023 13:29
@antomor antomor force-pushed the feature/PP-278/PP-329/upgrade_contracts branch from 8fac133 to 4e2a5bd Compare January 26, 2023 13:03
feat(upgrade): re-create project with hardhat & ethers
removing truffle and web3

chore: re-adds contracts

chore: adds dev rules

chore(contracts): fixes solidity lint errors

chore(test): re-adds tests

chore(upgrade): adds deployment tools

chore(upgrade): add smock for contract mocking

chore(upgrade): removes sol tests

chore(upgrade): fixe pre-commit and update readme

chore(upgrade): add more eslint rules

chore(deps): move typechain to deps

chore(upgrade): unignore dist from npm i

chore(ethers): return util token for manual testing 👿

PP-565: migrate the removeTokens script to use Hardhat and Ethers.js (#92)

* refactor: migrate the removeTokens script to use Hardhat and Ethers.js

* fix: fix the task in hardhat.config, update Readme and apply format

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-566: migrate script deploy collector (#95)

* feat: dummy commit, create empty deployCollector.ts file

* refactor: add script and task to deploy a Collector using Hardhat and Ethers.js

* style: apply format rules

* test: add the tests, remove the positional arguments and simplify the output file

* fix: apply PR suggestions

Remove some scripts from the package.json
Use console.table to print the collector output
Rename the input config file parameter

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-569: migrate change partners (#97)

* chore: change package.json version

* feat: migrate the change-partners script to use ether.js

* fix: change the parseJsonFile function to return undefined

* fix: apply PR suggestions

* Revert "style: include automatically formatted solidity files"

This reverts commit 76ee863.

* fix: remove the script from package.json and update Readme.md

* style: apply formatting rules

PP-567 Migrate Withdraw Task (#93)

* feat: new hardhat task

* feat: create withdraw task

* chore: update readme

* feat: complete withdrawal task and tests

* chore: linted

* fix: no from parameter on withdraw

* chore: change readme, description of task

* feat: reorganize tasks and tests

* fix: restore .prepare script

* fix: typo on script

* fix: restore file permissions

* fix: prettier issues, no waffle json file

* fix: no prepare task

* chore: remove unneeded rules

* fix: change Readme.md to fix the command instruction

* fix: restore the collector:deploy sample config file

Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>
Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-355/update-rif-relay-server (#96)

* refactor(index): expose typing for relay-server

* refactor: prettier

fix: fix the collector and add the missing tests

Fix the collector updateRemainderAddress
Include the missing test for the stakeForAddress method

fix: add config to use custom signers to run scripts (#106)

feat: expiration mechanism (#105)

* feat: expiration mechanism

* fix: FWD to SW

* feat: validate time on deploy

Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>

PP-602/RelayClient: _validateSmartWallet (#109)

* refactor(SmartWallet): expose getOwner
* refactor(index): expose PromiseOrValue
* chore: github workflow

PP-358: include the contracts in dist (#112)

* fix: remove contracts from npmignore

* chore: rename .prettierrc to prettier.json5 to be consistent among all the repos

PP-357: Add a task to mint utility tokens (#113)

* feat: add a task to mint utility tokens

* fix: apply linting and format to tasks

* refactor: expose RelayHubInterface

* docs: readme

Co-authored-by: Francisco Tobar <francisco.tobar@iovlabs.org>
@antomor antomor force-pushed the feature/PP-278/PP-329/upgrade_contracts branch from 4e2a5bd to 7ed4b21 Compare January 26, 2023 15:08
@antomor antomor marked this pull request as ready for review January 26, 2023 15:20
@antomor antomor merged commit a805476 into develop Jan 27, 2023
antomor added a commit that referenced this pull request Feb 3, 2023
* chore(ethers): change to ethers and updgrade dependencies

feat(upgrade): re-create project with hardhat & ethers
removing truffle and web3

chore: re-adds contracts

chore: adds dev rules

chore(contracts): fixes solidity lint errors

chore(test): re-adds tests

chore(upgrade): adds deployment tools

chore(upgrade): add smock for contract mocking

chore(upgrade): removes sol tests

chore(upgrade): fixe pre-commit and update readme

chore(upgrade): add more eslint rules

chore(deps): move typechain to deps

chore(upgrade): unignore dist from npm i

chore(ethers): return util token for manual testing 👿

PP-565: migrate the removeTokens script to use Hardhat and Ethers.js (#92)

* refactor: migrate the removeTokens script to use Hardhat and Ethers.js

* fix: fix the task in hardhat.config, update Readme and apply format

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-566: migrate script deploy collector (#95)

* feat: dummy commit, create empty deployCollector.ts file

* refactor: add script and task to deploy a Collector using Hardhat and Ethers.js

* style: apply format rules

* test: add the tests, remove the positional arguments and simplify the output file

* fix: apply PR suggestions

Remove some scripts from the package.json
Use console.table to print the collector output
Rename the input config file parameter

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-569: migrate change partners (#97)

* chore: change package.json version

* feat: migrate the change-partners script to use ether.js

* fix: change the parseJsonFile function to return undefined

* fix: apply PR suggestions

* Revert "style: include automatically formatted solidity files"

This reverts commit 76ee863.

* fix: remove the script from package.json and update Readme.md

* style: apply formatting rules

PP-567 Migrate Withdraw Task (#93)

* feat: new hardhat task

* feat: create withdraw task

* chore: update readme

* feat: complete withdrawal task and tests

* chore: linted

* fix: no from parameter on withdraw

* chore: change readme, description of task

* feat: reorganize tasks and tests

* fix: restore .prepare script

* fix: typo on script

* fix: restore file permissions

* fix: prettier issues, no waffle json file

* fix: no prepare task

* chore: remove unneeded rules

* fix: change Readme.md to fix the command instruction

* fix: restore the collector:deploy sample config file

Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>
Co-authored-by: Antonio Morrone <antonio@iovlabs.org>

PP-355/update-rif-relay-server (#96)

* refactor(index): expose typing for relay-server

* refactor: prettier

fix: fix the collector and add the missing tests

Fix the collector updateRemainderAddress
Include the missing test for the stakeForAddress method

fix: add config to use custom signers to run scripts (#106)

feat: expiration mechanism (#105)

* feat: expiration mechanism

* fix: FWD to SW

* feat: validate time on deploy

Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>

PP-602/RelayClient: _validateSmartWallet (#109)

* refactor(SmartWallet): expose getOwner
* refactor(index): expose PromiseOrValue
* chore: github workflow

PP-358: include the contracts in dist (#112)

* fix: remove contracts from npmignore

* chore: rename .prettierrc to prettier.json5 to be consistent among all the repos

PP-357: Add a task to mint utility tokens (#113)

* feat: add a task to mint utility tokens

* fix: apply linting and format to tasks

* refactor: expose RelayHubInterface

* docs: readme

Co-authored-by: Francisco Tobar <francisco.tobar@iovlabs.org>

* fix: apply format and lint rules

---------

Co-authored-by: Francisco Tobar <francisco.tobar@iovlabs.org>
Co-authored-by: Antonio Morrone <antonio@iovlabs.org>
@antomor antomor deleted the feature/PP-278/PP-329/upgrade_contracts branch February 6, 2023 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants