Skip to content

Commit

Permalink
Report for issue #140 updated by RaymondFam
Browse files Browse the repository at this point in the history
  • Loading branch information
code423n4 committed Oct 24, 2022
1 parent 2ba6a8b commit ed61284
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion data/RaymondFam-G.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/enforcer/Hol
```
if (!(msg.sender == _holograph().getBridge() || msg.sender == _holograph().getOperator())) {
```
## `uint256` Can be Cheaper Than `uint8`
## `uint256` Can be Cheaper Than `uint8` and Other Unsigned Integer Type of Smaller Bit Size
When dealing with function arguments or memory values, there is no inherent benefit because the compiler does not pack these values. Your contract’s gas usage may be higher because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size. The EVM needs to properly enforce the limits of this smaller type.

It is only more efficient when you can pack variables of uint8 into the same storage slot with other neighboring variables smaller than 32 bytes. Here are some of the instances entailed:

https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographFactory.sol#L323
https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographBridge.sol#L192

## += and -= Costs More Gas
`+=` generally costs 22 more gas than writing out the assigned equation explicitly. The amount of gas wasted can be quite sizable when repeatedly operated in a loop. As an example, the following line of code could be rewritten as:
Expand Down

0 comments on commit ed61284

Please sign in to comment.