From 363b65be474d015751ed41862ca561e7f29a3a45 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 23 Dec 2024 10:13:33 +0100 Subject: [PATCH 01/12] fix token decimal & add comment for Halborn audit --- contracts/NonTransferableERC20Upgradeable.sol | 18 ++++++++++++++++++ contracts/VoucherHub.sol | 5 +++++ docs/VoucherHub.md | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/contracts/NonTransferableERC20Upgradeable.sol b/contracts/NonTransferableERC20Upgradeable.sol index 83fa1225..fe2db388 100644 --- a/contracts/NonTransferableERC20Upgradeable.sol +++ b/contracts/NonTransferableERC20Upgradeable.sol @@ -32,4 +32,22 @@ contract NonTransferableERC20Upgradeable is ERC20Upgradeable { function transferFrom(address, address, uint256) public pure override returns (bool) { revert("NonTransferableERC20Upgradeable: Unsupported transferFrom"); } + + /** + * @dev Returns the number of decimal places used for user representation. + * + * This function defines how token balances are displayed to users. For example, + * if `decimals` is set to `2`, a balance of `505` tokens will be displayed as + * `5.05` (`505 / 10 ** 2`). + * + * By default, the standard ERC-20 `decimals` value is `18`. However, this value + * is overridden here to `9` to align with the number of decimal places used by + * the RLC token. This ensures consistency in how input values are handled + * when a voucher is minted. + * + * @return The number of decimal places (9) used for token representation. + */ + function decimals() public pure override returns (uint8) { + return 9; + } } diff --git a/contracts/VoucherHub.sol b/contracts/VoucherHub.sol index e7827847..5a4dfa24 100644 --- a/contracts/VoucherHub.sol +++ b/contracts/VoucherHub.sol @@ -103,6 +103,11 @@ contract VoucherHub is emit VoucherTypeCreated($._voucherTypes.length - 1, description, duration); } + /** + * This function updates only the duration setting for the next minted voucher and not the active one. + * The manager of vouchers wants to provide guarantees regarding the expiration of a voucher. + * When a voucher is delivered, the credits inside the voucher should not expire before the original expiration date. + */ function updateVoucherTypeDescription( uint256 id, string memory description diff --git a/docs/VoucherHub.md b/docs/VoucherHub.md index a9ccb51a..0c73dd56 100644 --- a/docs/VoucherHub.md +++ b/docs/VoucherHub.md @@ -57,6 +57,10 @@ function createVoucherType(string description, uint256 duration) external function updateVoucherTypeDescription(uint256 id, string description) external ``` +This function updates only the duration setting for the next minted voucher and not the active one. +The manager of vouchers wants to provide guarantees regarding the expiration of a voucher. +When a voucher is delivered, the credits inside the voucher should not expire before the original expiration date. + ### updateVoucherTypeDuration ```solidity From 61bf8de640a1e53c3f9c37ecd6dafa92c61d5411 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 23 Dec 2024 10:17:03 +0100 Subject: [PATCH 02/12] add one line into changelog --- CHANGELOG.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3c65c97..86fa0aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,22 @@ # Changelog ## vNEXT + - Remove references to blockscout v5. (#49) +- Overrode the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. ## v1.0.0 ### What's new? + - Allow users to access resources of the iExec network via a sponsorship voucher. ### More details + - Upgrade Solidity Compiler to `v0.8.27`. (#45) - Bump dependencies: (#44) - - `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump] - - `prettier-plugin-organize-imports@4` + - `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump] + - `prettier-plugin-organize-imports@4` - Add `getVoucherProxyCodeHash(..)` & `isRefundedTask(..)` view functions. (#43) - Add `predictVoucher(..)` & `isVoucher(..)` functions. (#42) - Generate UML class diagram for contracts. (#41) @@ -43,12 +47,12 @@ - Match orders through voucher. (#12) - Add external-hardhat network configuration. (#11) - Add voucher credit and SRLC manipulation. (#10) - - SRLC and iExec poco is mocked. - - set voucher credit as VoucherHub is ERC20. + - SRLC and iExec poco is mocked. + - set voucher credit as VoucherHub is ERC20. - Upgrade configuration: (#9) - - Upgrade dependencies: hardhat, husky, iExec Poco. - - Ignore mocks in coverage. - - Add solidity optimizer and use Bellecour network config. + - Upgrade dependencies: hardhat, husky, iExec Poco. + - Ignore mocks in coverage. + - Add solidity optimizer and use Bellecour network config. - Add role-based access control to VoucherHub. (#8) - Create voucher from VoucherHub with : type, expiration, authorize list. (#6) - Create vouchers with create2. (#5) From 18c2224fda53529fe77f885f00ebf1a9bf620b64 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Mon, 30 Dec 2024 16:46:27 +0100 Subject: [PATCH 03/12] add one new test for the `decimals` function --- test/VoucherHub.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/VoucherHub.test.ts b/test/VoucherHub.test.ts index a3b0002f..4108d4e6 100644 --- a/test/VoucherHub.test.ts +++ b/test/VoucherHub.test.ts @@ -78,6 +78,18 @@ describe('VoucherHub', function () { }; } + describe('Decimals', function () { + it('Should return 9 as the number of decimals', async function () { + const { voucherHub } = await loadFixture(deployFixture); + + // Call the decimals function and check the returned value + const decimals = await voucherHub.decimals(); + + // Assertion to check if the returned decimals value is 9 + expect(decimals).to.equal(9); + }); + }); + describe('Initialize', function () { it('Should initialize', async function () { const { beacon, voucherHub, admin, manager, minter } = await loadFixture(deployFixture); From f8c6408457ac8fe56570a290a882ff09bf311587 Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:14:49 +0700 Subject: [PATCH 04/12] Update CHANGELOG.md Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f52c022..58352661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## vNEXT - Remove references to blockscout v5. (#49) -- Overrode the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. +- Override the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. - Verify VoucherProxy contracts. (#51) ## v1.0.0 From c04dadd05b29bd62d7c653c8096496a2546642cb Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:15:03 +0700 Subject: [PATCH 05/12] Update contracts/VoucherHub.sol Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- contracts/VoucherHub.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/VoucherHub.sol b/contracts/VoucherHub.sol index 5a4dfa24..7235483f 100644 --- a/contracts/VoucherHub.sol +++ b/contracts/VoucherHub.sol @@ -104,9 +104,9 @@ contract VoucherHub is } /** - * This function updates only the duration setting for the next minted voucher and not the active one. - * The manager of vouchers wants to provide guarantees regarding the expiration of a voucher. - * When a voucher is delivered, the credits inside the voucher should not expire before the original expiration date. + * This function only updates the duration for newly minted vouchers and not the existing ones to provide + * guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire + * before the original expiration date. */ function updateVoucherTypeDescription( uint256 id, From eb679397af6b3c02fae0b62b6318fe7df1e5958d Mon Sep 17 00:00:00 2001 From: Robin Le Caignec <72495599+Le-Caignec@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:15:24 +0700 Subject: [PATCH 06/12] Update test/VoucherHub.test.ts Co-authored-by: Zied Guesmi <26070035+zguesmi@users.noreply.github.com> --- test/VoucherHub.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/VoucherHub.test.ts b/test/VoucherHub.test.ts index 4108d4e6..923a8156 100644 --- a/test/VoucherHub.test.ts +++ b/test/VoucherHub.test.ts @@ -83,10 +83,7 @@ describe('VoucherHub', function () { const { voucherHub } = await loadFixture(deployFixture); // Call the decimals function and check the returned value - const decimals = await voucherHub.decimals(); - - // Assertion to check if the returned decimals value is 9 - expect(decimals).to.equal(9); + expect(await voucherHub.decimals()).to.equal(9); }); }); From ce516625619a716adcf492f7cb1767eb216658e7 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 11:18:30 +0100 Subject: [PATCH 07/12] move test into `NonTransferableERC20Upgradeable` describe section --- docs/VoucherHub.md | 6 +++--- test/VoucherHub.test.ts | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/VoucherHub.md b/docs/VoucherHub.md index 0c73dd56..317850a7 100644 --- a/docs/VoucherHub.md +++ b/docs/VoucherHub.md @@ -57,9 +57,9 @@ function createVoucherType(string description, uint256 duration) external function updateVoucherTypeDescription(uint256 id, string description) external ``` -This function updates only the duration setting for the next minted voucher and not the active one. -The manager of vouchers wants to provide guarantees regarding the expiration of a voucher. -When a voucher is delivered, the credits inside the voucher should not expire before the original expiration date. +This function only updates the duration for newly minted vouchers and not the existing ones to provide +guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire +before the original expiration date. ### updateVoucherTypeDuration diff --git a/test/VoucherHub.test.ts b/test/VoucherHub.test.ts index 923a8156..c890a733 100644 --- a/test/VoucherHub.test.ts +++ b/test/VoucherHub.test.ts @@ -78,15 +78,6 @@ describe('VoucherHub', function () { }; } - describe('Decimals', function () { - it('Should return 9 as the number of decimals', async function () { - const { voucherHub } = await loadFixture(deployFixture); - - // Call the decimals function and check the returned value - expect(await voucherHub.decimals()).to.equal(9); - }); - }); - describe('Initialize', function () { it('Should initialize', async function () { const { beacon, voucherHub, admin, manager, minter } = await loadFixture(deployFixture); @@ -1073,6 +1064,13 @@ describe('VoucherHub', function () { 'NonTransferableERC20Upgradeable: Unsupported transferFrom', ); }); + + it('Should return 9 as the number of decimals', async function () { + const { voucherHub } = await loadFixture(deployFixture); + + // Call the decimals function and check the returned value + expect(await voucherHub.decimals()).to.equal(9); + }); }); }); From 699149a011df31f292bd9669835f460cdf8dd301 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 11:29:21 +0100 Subject: [PATCH 08/12] Refactor decimals function documentation for clarity and consistency --- contracts/NonTransferableERC20Upgradeable.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/NonTransferableERC20Upgradeable.sol b/contracts/NonTransferableERC20Upgradeable.sol index fe2db388..7d9ad934 100644 --- a/contracts/NonTransferableERC20Upgradeable.sol +++ b/contracts/NonTransferableERC20Upgradeable.sol @@ -34,17 +34,13 @@ contract NonTransferableERC20Upgradeable is ERC20Upgradeable { } /** - * @dev Returns the number of decimal places used for user representation. - * - * This function defines how token balances are displayed to users. For example, - * if `decimals` is set to `2`, a balance of `505` tokens will be displayed as - * `5.05` (`505 / 10 ** 2`). - * - * By default, the standard ERC-20 `decimals` value is `18`. However, this value + * @dev By default, the standard ERC-20 `decimals` value is `18`. However, this value * is overridden here to `9` to align with the number of decimal places used by * the RLC token. This ensures consistency in how input values are handled * when a voucher is minted. * + * See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L78 + * * @return The number of decimal places (9) used for token representation. */ function decimals() public pure override returns (uint8) { From 86751762f27f469bf99a8d42b4f4befc7a4f3501 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 17:06:43 +0100 Subject: [PATCH 09/12] Update CHANGELOG.md to include reference of the PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58352661..e0f31e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## vNEXT - Remove references to blockscout v5. (#49) -- Override the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. +- Override the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. (#50) - Verify VoucherProxy contracts. (#51) ## v1.0.0 From 52180cbefd6114580c610dd0284cbcb05961e4a8 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 17:12:07 +0100 Subject: [PATCH 10/12] Clarify documentation for updateVoucherTypeDescription to indicate intended feature per Halborn audit --- contracts/VoucherHub.sol | 1 + docs/VoucherHub.md | 1 + 2 files changed, 2 insertions(+) diff --git a/contracts/VoucherHub.sol b/contracts/VoucherHub.sol index 7235483f..1b8a88a4 100644 --- a/contracts/VoucherHub.sol +++ b/contracts/VoucherHub.sol @@ -107,6 +107,7 @@ contract VoucherHub is * This function only updates the duration for newly minted vouchers and not the existing ones to provide * guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire * before the original expiration date. + * This is not a bug as mentioned in audit of Halborn (HAL-01) but an intended feature. */ function updateVoucherTypeDescription( uint256 id, diff --git a/docs/VoucherHub.md b/docs/VoucherHub.md index 317850a7..d17fc70a 100644 --- a/docs/VoucherHub.md +++ b/docs/VoucherHub.md @@ -60,6 +60,7 @@ function updateVoucherTypeDescription(uint256 id, string description) external This function only updates the duration for newly minted vouchers and not the existing ones to provide guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire before the original expiration date. +This is not a bug as mentioned in audit of Halborn (HAL-01) but an intended feature. ### updateVoucherTypeDuration From 06e7115f1854cea8d282b2bcbe9ada8b5ba292b0 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 17:14:38 +0100 Subject: [PATCH 11/12] reorder functions into the NonTransferableERC20Upgradeable contract to stay consistent with the standard ERC20 order --- contracts/NonTransferableERC20Upgradeable.sol | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/contracts/NonTransferableERC20Upgradeable.sol b/contracts/NonTransferableERC20Upgradeable.sol index 7d9ad934..9addb3e6 100644 --- a/contracts/NonTransferableERC20Upgradeable.sol +++ b/contracts/NonTransferableERC20Upgradeable.sol @@ -10,6 +10,20 @@ import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ * @notice This contracts follows the standard ERC-20 Upgradeable model, but it cannot be transferred. */ contract NonTransferableERC20Upgradeable is ERC20Upgradeable { + /** + * @dev By default, the standard ERC-20 `decimals` value is `18`. However, this value + * is overridden here to `9` to align with the number of decimal places used by + * the RLC token. This ensures consistency in how input values are handled + * when a voucher is minted. + * + * See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L78 + * + * @return The number of decimal places (9) used for token representation. + */ + function decimals() public pure override returns (uint8) { + return 9; + } + /** * @notice NonTransferableERC20Upgradeable is not transferable. */ @@ -32,18 +46,4 @@ contract NonTransferableERC20Upgradeable is ERC20Upgradeable { function transferFrom(address, address, uint256) public pure override returns (bool) { revert("NonTransferableERC20Upgradeable: Unsupported transferFrom"); } - - /** - * @dev By default, the standard ERC-20 `decimals` value is `18`. However, this value - * is overridden here to `9` to align with the number of decimal places used by - * the RLC token. This ensures consistency in how input values are handled - * when a voucher is minted. - * - * See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L78 - * - * @return The number of decimal places (9) used for token representation. - */ - function decimals() public pure override returns (uint8) { - return 9; - } } From c9ee780ec969ab2de70618ad0ea6021b97bc2062 Mon Sep 17 00:00:00 2001 From: Le-Caignec Date: Fri, 3 Jan 2025 17:16:53 +0100 Subject: [PATCH 12/12] Improve the documentation of updateVoucherTypeDescription function --- contracts/VoucherHub.sol | 2 +- docs/VoucherHub.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/VoucherHub.sol b/contracts/VoucherHub.sol index 1b8a88a4..58a747e0 100644 --- a/contracts/VoucherHub.sol +++ b/contracts/VoucherHub.sol @@ -107,7 +107,7 @@ contract VoucherHub is * This function only updates the duration for newly minted vouchers and not the existing ones to provide * guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire * before the original expiration date. - * This is not a bug as mentioned in audit of Halborn (HAL-01) but an intended feature. + * As mentioned in Halborn audit report (HAL-01), this is not a bug, but rather, an intended feature. */ function updateVoucherTypeDescription( uint256 id, diff --git a/docs/VoucherHub.md b/docs/VoucherHub.md index d17fc70a..7243624b 100644 --- a/docs/VoucherHub.md +++ b/docs/VoucherHub.md @@ -60,7 +60,7 @@ function updateVoucherTypeDescription(uint256 id, string description) external This function only updates the duration for newly minted vouchers and not the existing ones to provide guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire before the original expiration date. -This is not a bug as mentioned in audit of Halborn (HAL-01) but an intended feature. +As mentioned in Halborn audit report (HAL-01), this is not a bug, but rather, an intended feature. ### updateVoucherTypeDuration