From 37b215d9fefc9d5601640c9adac0a4669b9bbf7a Mon Sep 17 00:00:00 2001 From: josojo Date: Thu, 4 Jan 2024 16:35:24 +0100 Subject: [PATCH] better comments --- contracts/ChainIdManager.sol | 15 ++++++++++----- test/ChainIdManager.t.sol | 15 +++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/contracts/ChainIdManager.sol b/contracts/ChainIdManager.sol index c8e4f86a..661044ea 100644 --- a/contracts/ChainIdManager.sol +++ b/contracts/ChainIdManager.sol @@ -1,11 +1,19 @@ // SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.20; +// The ChainIdManager contract provides a list of new usable chainIds via the getNextUsableChainId function. +// If a project uses one chainId, it can be added to the deny list and then no other project will use it. +// The contract does not come with an owner, but anyone can add chainIds to the deny list. +// It costs just gasBurnAmount to deny list a chainId. +// The burnGas function introduces this cost to use up chainIds. +// There are uint64(2**63=9.223372e+18) chainIds minus the publicly used chainIds available. +// Using all of the chainIds would cost 9.223372e+18 * gasBurnAmount = 9.223372e+24 gas = 6.1489147e+17 blocks = 237226647377 years + contract ChainIdManager { // Counter for the number of Chain IDs uint64 public chainIdCounter = 0; // contains a list of denied Chain IDs that should not be used as chainIds - // they are governed by a owner of the contract + // they are anyone who is willing to pay the gas to use them. mapping(uint64 => bool) public deniedChainIds; // Fee to use up a chain ID uint256 public immutable gasBurnAmount = 1000000; @@ -27,7 +35,7 @@ contract ChainIdManager { * @dev Adds multiple Chain IDs to the deny list * @param chainIds The Chain IDs to add */ - function denyListChainIds(uint64[] memory chainIds) public { + function denyListChainIds(uint64[] memory chainIds) public { for (uint256 i = 0; i < chainIds.length; i++) { denyListChainId(chainIds[i]); } @@ -38,9 +46,6 @@ contract ChainIdManager { * @return chainId The next usable Chain ID */ function getNextUsableChainId() public returns (uint64 chainId) { - // The burnGas function introduces a cost to use up chainIds. - // There are uint64(2**63=9.223372e+18) chainIds minus the publicly used chainIds available. - // Using all of the chainIds would cost 9.223372e+18 * gasBurnAmount = 9.223372e+24 gas = 6.1489147e+17 blocks = 237226647377 years burnGas(); while (deniedChainIds[chainIdCounter]) { chainIdCounter++; diff --git a/test/ChainIdManager.t.sol b/test/ChainIdManager.t.sol index 1f49e064..6cb1261f 100644 --- a/test/ChainIdManager.t.sol +++ b/test/ChainIdManager.t.sol @@ -31,15 +31,14 @@ contract ChainIdManagerTest is Test { uint256 finalGas = gasleft(); assert(currentGas - finalGas >= chainIdManager.gasBurnAmount()); - uint256 currentGas2 = gasleft(); - uint64[] memory newChainIds = new uint64[](6); - newChainIds[0]=3; - newChainIds[1]=4; - newChainIds[2]=5; - newChainIds[3]=6; - newChainIds[4]=7; - newChainIds[5]=8; + uint64[] memory newChainIds = new uint64[](6); + newChainIds[0] = 3; + newChainIds[1] = 4; + newChainIds[2] = 5; + newChainIds[3] = 6; + newChainIds[4] = 7; + newChainIds[5] = 8; chainIdManager.denyListChainIds(newChainIds); uint256 finalGas2 = gasleft(); assert(currentGas2 - finalGas2 >= chainIdManager.gasBurnAmount() * 6);