Number | Issue | Instances |
---|---|---|
[G-01] | Reduce gas usage by moving to Solidity 0.8.19 or later | 4 |
[G-02] | Use hardcode address instead of address(this) |
2 |
[G-03] | Use != 0 instead of > 0 for uints to save gas |
3 |
[G-04] | Use assembly to check for address(0) |
4 |
See "References" below.
References
https://blog.soliditylang.org/2023/02/22/solidity-0.8.19-release-announcement/#preventing-dead-code-in-runtime-bytecode
There are 4 instances of this issue:
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L2
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrowFactory.sol#L2
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcIEscrow.sol#L2
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcIEscrowFactory.sol#L2
address(this)
Instead of address(this), it is more gas-efficient to pre-calculate and use the address with a hardcode. Foundry's script.sol and solmate LibRlp.sol
contracts can do this.
References:
https://book.getfoundry.sh/reference/forge-std/compute-create-address
https://twitter.com/transmissions11/status/1518507047943245824
There are 2 instances of this issue:
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L44
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L98
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L110
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L125
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrowFactory.sol#L30
!= 0
instead of > 0
for uints
to save gasUsing !=
to check if a uint
is greater than 0
is more gas efficient than using >
.
There are 3 instances of this issue:
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L119
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L122
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L126
address(0)
Assembly can be used to more efficiently check for a zero address.
References:
https://medium.com/@kalexotsu/solidity-assembly-checking-if-an-address-is-0-efficiently-d2bfe071331
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L40
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L41
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L42
https://github.com/Cyfrin/2023-07-escrow/tree/main/srcEscrow.sol#L103
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.