From 076908a771ccabd9af245b9ab30f2bb94c11fd63 Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:35:48 +0100 Subject: [PATCH 1/8] locking of the pragma version and update version --- README.md | 2 +- contracts/FigmentEth2Depositor.sol | 2 +- truffle-config.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96cf528..c3b1d75 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Installation 1. Clone the repository `git clone git@github.com:figment-networks/figment-eth2-depositor.git` 2. Install the npm dependencies `npm install` -3. Set a working version of the compiler `npx truffle obtain --solc v0.8.1+commit.df193b15` +3. Set a working version of the compiler `npx truffle obtain --solc v0.8.10+commit.fc410830` Deployment (Goerli) ------------ diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..df7d64e 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity 0.8.10; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; diff --git a/truffle-config.js b/truffle-config.js index cfca973..4315ea3 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -60,7 +60,7 @@ // Configure your compilers compilers: { solc: { - version: "v0.8.1+commit.df193b15", // Fetch exact version from solc-bin (default: truffle's version) + version: "v0.8.10+commit.fc410830", // Fetch exact version from solc-bin (default: truffle's version) settings: { "remappings": [], "optimizer": { From 218185bc86deb5485f4a608695ad08f3aa41bf25 Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:36:57 +0100 Subject: [PATCH 2/8] remove ReentrancyGuard.sol as it's unused --- contracts/FigmentEth2Depositor.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..c6aa7e8 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -4,10 +4,9 @@ pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; -import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "../contracts/interfaces/IDepositContract.sol"; -contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { +contract FigmentEth2Depositor is Pausable, Ownable { /** * @dev Eth2 Deposit Contract address. From ff99af26e576c46b98831db8e0fa0b31d270cc5d Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:41:02 +0100 Subject: [PATCH 3/8] declare the state variable depositContract as immutable to save some gas --- contracts/FigmentEth2Depositor.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..faae33c 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -12,7 +12,7 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { /** * @dev Eth2 Deposit Contract address. */ - IDepositContract public depositContract; + IDepositContract public immutable depositContract; /** * @dev Minimal and maximum amount of nodes per transaction. From 2affc82a83209254d8e0bccb8f676fbe50aede6e Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:43:02 +0100 Subject: [PATCH 4/8] replace public by external to save some gaz cost --- contracts/FigmentEth2Depositor.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..422b1d3 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -99,7 +99,7 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { * * - The contract must not be paused. */ - function pause() public onlyOwner { + function pause() external onlyOwner { _pause(); } @@ -110,7 +110,7 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { * * - The contract must be paused. */ - function unpause() public onlyOwner { + function unpause() external onlyOwner { _unpause(); } From 1288ad5d19b3496659664425b363d7cd07f6c1db Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:44:59 +0100 Subject: [PATCH 5/8] no need to initialize uint256 to 0 as it's default to 0 --- contracts/FigmentEth2Depositor.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..0e4cad6 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -75,7 +75,7 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { deposit_data_roots.length == nodesAmount, "FigmentEth2Depositor: amount of parameters do no match"); - for (uint256 i = 0; i < nodesAmount; ++i) { + for (uint256 i; i < nodesAmount; ++i) { require(pubkeys[i].length == pubkeyLength, "FigmentEth2Depositor: wrong pubkey"); require(withdrawal_credentials[i].length == credentialsLength, "FigmentEth2Depositor: wrong withdrawal credentials"); require(signatures[i].length == signatureLength, "FigmentEth2Depositor: wrong signatures"); From 733f7b8b85f4950cae52f3580d4723928bb78cff Mon Sep 17 00:00:00 2001 From: zurgl Date: Tue, 23 Nov 2021 16:49:07 +0100 Subject: [PATCH 6/8] shorten harcoded string to reduce gas cost --- contracts/FigmentEth2Depositor.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index 11dd36c..5207b1a 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -45,7 +45,7 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { * @dev This contract will not accept direct ETH transactions. */ receive() external payable { - revert("FigmentEth2Depositor: do not send ETH directly here"); + revert("Do not send ETH here"); } /** @@ -65,20 +65,20 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { uint256 nodesAmount = pubkeys.length; - require(nodesAmount > 0 && nodesAmount <= 100, "FigmentEth2Depositor: you can deposit only 1 to 100 nodes per transaction"); - require(msg.value == collateral * nodesAmount, "FigmentEth2Depositor: the amount of ETH does not match the amount of nodes"); + require(nodesAmount > 0 && nodesAmount <= 100, "100 nodes max / tx"); + require(msg.value == collateral * nodesAmount, "ETH amount missmatch"); require( withdrawal_credentials.length == nodesAmount && signatures.length == nodesAmount && deposit_data_roots.length == nodesAmount, - "FigmentEth2Depositor: amount of parameters do no match"); + "Paramters missmatch"); for (uint256 i = 0; i < nodesAmount; ++i) { - require(pubkeys[i].length == pubkeyLength, "FigmentEth2Depositor: wrong pubkey"); - require(withdrawal_credentials[i].length == credentialsLength, "FigmentEth2Depositor: wrong withdrawal credentials"); - require(signatures[i].length == signatureLength, "FigmentEth2Depositor: wrong signatures"); + require(pubkeys[i].length == pubkeyLength, "Wrong pubkey"); + require(withdrawal_credentials[i].length == credentialsLength, "Wrong withdrawal cred"); + require(signatures[i].length == signatureLength, "Wrong signatures"); IDepositContract(address(depositContract)).deposit{value: collateral}( pubkeys[i], From ffef199d665738a30d5db844737f6514f7d2b877 Mon Sep 17 00:00:00 2001 From: zurgl Date: Wed, 24 Nov 2021 10:14:42 +0100 Subject: [PATCH 7/8] Update FigmentEth2Depositor.sol Adapt the constructor: Remove `if`, `else` statement as they are not supported for immutable variable --- contracts/FigmentEth2Depositor.sol | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/contracts/FigmentEth2Depositor.sol b/contracts/FigmentEth2Depositor.sol index faae33c..7b9f222 100644 --- a/contracts/FigmentEth2Depositor.sol +++ b/contracts/FigmentEth2Depositor.sol @@ -31,14 +31,9 @@ contract FigmentEth2Depositor is ReentrancyGuard, Pausable, Ownable { /** * @dev Setting Eth2 Smart Contract address during construction. */ - constructor(bool mainnet, address depositContract_) { - if (mainnet == true) { - depositContract = IDepositContract(0x00000000219ab540356cBB839Cbe05303d7705Fa); - } else if (depositContract_ == 0x0000000000000000000000000000000000000000) { - depositContract = IDepositContract(0x8c5fecdC472E27Bc447696F431E425D02dd46a8c); - } else { - depositContract = IDepositContract(depositContract_); - } + constructor(address depositContract_) { + require(depositContract_ != address(0), "Zero address"); + depositContract = IDepositContract(depositContract_); } /** From 4aa112c370f7120c2f10fe60e7fb2a7ecc5f9c5b Mon Sep 17 00:00:00 2001 From: zurgl Date: Wed, 24 Nov 2021 10:36:32 +0100 Subject: [PATCH 8/8] merge all branch, compile, deploy and verify --- migrations/2_contract_migration.js | 4 +++- package.json | 2 +- truffle-config.js | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/migrations/2_contract_migration.js b/migrations/2_contract_migration.js index 775bb63..4f4b22d 100644 --- a/migrations/2_contract_migration.js +++ b/migrations/2_contract_migration.js @@ -1,5 +1,7 @@ const FigmentEth2Depositor = artifacts.require("FigmentEth2Depositor"); module.exports = function (deployer) { - deployer.deploy(FigmentEth2Depositor, false, "0x0000000000000000000000000000000000000000"); + // Contract address on mainnet: 0x00000000219ab540356cBB839Cbe05303d7705Fa + // Contract address on testnet: 0x8c5fecdC472E27Bc447696F431E425D02dd46a8c + deployer.deploy(FigmentEth2Depositor, "0x8c5fecdC472E27Bc447696F431E425D02dd46a8c"); }; \ No newline at end of file diff --git a/package.json b/package.json index fe842e0..5c0e656 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "keywords": [], "author": "", - "license": "ISC", + "license": "MIT", "dependencies": { "@openzeppelin/contracts": "^4.3.1", "chai": "^4.3.4", diff --git a/truffle-config.js b/truffle-config.js index 4315ea3..71ac092 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -68,9 +68,7 @@ "runs": 200 }, "evmVersion": "istanbul", - "libraries": { - "": {} - }, + "libraries": {}, "outputSelection": { "*": { "*": [