https://github.com/RareSkills/gas-puzzles
A sequence of smart contracts to practice gas optimization. These are used as practice assignments for RareSkills.io and the Udemy Gas Optimization Course
https://github.com/RareSkills/gas-puzzles
Last synced: 5 months ago
JSON representation
A sequence of smart contracts to practice gas optimization. These are used as practice assignments for RareSkills.io and the Udemy Gas Optimization Course
- Host: GitHub
- URL: https://github.com/RareSkills/gas-puzzles
- Owner: RareSkills
- License: agpl-3.0
- Created: 2022-09-27T03:57:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-07T10:23:34.000Z (about 1 year ago)
- Last Synced: 2024-08-04T04:05:56.018Z (9 months ago)
- Language: JavaScript
- Homepage: https://rareskills.io
- Size: 5.69 MB
- Stars: 459
- Watchers: 12
- Forks: 178
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [RareSkills](https://rareskills.io) Gas Puzzles
If you want to learn about gas optimization, take the [Udemy gas optimization course](https://www.udemy.com/course/advanced-solidity-understanding-and-optimizing-gas-costs/?referralCode=C4684D6872713525E349)!
## Puzzles that are ready for you
- [x] Distribute (hard)
- [x] Array Sum (easy)
- [x] Mint150 (hard)
- [x] ERC165 (low level programming required)
- [x] Array Sort (medium)
- [x] Security101 (easy/medium)
- [ ] Escrow
- [ ] EscrowV2
- [ ] Mint
- [ ] Presale
- [x] Vote (easy)
- [x] Require (easy)
- [ ] Staking## Contributors
DO NOT COMMIT SOLUTIONS, BE SURE TO PUT ANSWERS IN `contracts/contracts_optimized` to ensure they fall into the `.gitignore`
## Players
Your goal is to optimize the contracts such that they reach the target efficiency.
Rules
- you may not change the optimizer level
- you may not change the solidity version
- you may refactor functionality as long as you don't break the business logic
- you may make reasonable assumptions about what variable sizes are necessary to get things done
- you may remove unnecessary or redundant logic (some have been intentionally added)
- because making functions `payable` is a controversial optimization, you do not need to make functions `payable` to reach the gas target unless the function needs to be payable to fulfill its business logic## Testing
As mentioned above, optimized contracts should be created in their own sub-folder
to prevent committing them publicly.The file structure should look similar to this:
```
- GasPuzzles
|_
contracts
|_
contracts_optimized
| |_
| ArraySum.sol
| Distribute.sol
| ..
| ...
|
ArraySum.sol
Distribute.sol
..
...
```Within the contracts that are optimized be sure to follow the following naming
convention to ensure tests run smoothly:```
contract OptimizedArraySum {...
contract OptimizedDistribute {
...
``````
npx hardhat test
npx hardhat test test/ArraySum
npx prettier --write *
```