seen-haus / seen-contracts

Seen Haus contract suite
GNU General Public License v3.0
8 stars 2 forks source link

SCS-01C: Inefficient Hash Constants #29

Open JayWelsh opened 2 years ago

JayWelsh commented 2 years ago

SCS-01C: Inefficient Hash Constants

Type Severity Location
Gas Optimization Informational SeenConstants.sol:L17-L22

Description:

The linked constant declarations are meant to be assigned to the result of a keccak256 instruction. Contrary to the expected, constant variables are evaluated as expressions and as such the gas optimization of caching the result of the keccak256 instruction is actually not achieved here.

Example:

bytes32 internal constant ADMIN = keccak256("ADMIN");                   // Deployer and any other admins as needed
bytes32 internal constant SELLER = keccak256("SELLER");                 // Approved sellers amd Seen.Haus reps
bytes32 internal constant MINTER = keccak256("MINTER");                 // Approved artists and Seen.Haus reps
bytes32 internal constant ESCROW_AGENT = keccak256("ESCROW_AGENT");     // Seen.Haus Physical Item Escrow Agent
bytes32 internal constant MARKET_HANDLER = keccak256("MARKET_HANDLER"); // Market Handler contracts
bytes32 internal constant UPGRADER = keccak256("UPGRADER");             // Performs contract upgrades

Recommendation:

We advise the immutable keyword to be utilized instead to actually take advantage of the gas benefit of pre-calculating the keccak256 hash. For more information, consult this issue in the Solidity compiler.

JayWelsh commented 2 years ago

Resolved by https://github.com/seen-haus/seen-contracts/pull/36

JayWelsh commented 2 years ago

Reverted by #39

Appeal:

Change reverted due to immutable values not being able to be read in contract constructors

147928503-59d859bf-cae3-48e1-8c30-5d3c18de1d89