Suggestion: A few minor gas optimizations for the example contracts
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Refactorización
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- solidity
- Área
- blockchain
Línea de trabajo
Start with VRFConsumerV2.sol and KeepersCounter.sol, focusing on the s_owner declaration, constructor, onlyOwner checks, and performUpkeep. Apply the two requested gas-oriented changes while preserving behavior, then verify that ownership checks and upkeep reverts still work as expected.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi team,
First of all, thanks for this excellent Foundry starter kit! It's a great resource for the community.
While looking through the example contracts (VRFConsumerV2.sol and KeepersCounter.sol), I noticed a couple of small gas optimization opportunities that could be nice additions to make the templates even more efficient.
1. Make s_owner immutable in VRFConsumerV2.sol
The s_owner state variable is set in the constructor and never changed afterwards. Marking it as immutable would save significant gas on every read by replacing an expensive SLOAD opcode with a cheap PUSH of the value directly from the contract's bytecode.
Suggestion:
- address public s_owner;
+ address public immutable s_owner;
Approximate Gas Savings: This typically saves ~2000 gas each time the onlyOwner modifier is checked, as it avoids a storage read.
2. Use Custom Errors in KeepersCounter.sol
The require statement in performUpkeep uses a string message ("Time interval not met"). Since Solidity 0.8.4, using custom errors is more gas-efficient both at deployment and during runtime reverts.
Suggestion:
// At the contract level, above the constructor
+ error UpkeepNotNeeded();
// In the performUpkeep() function
- require(upkeepNeeded, "Time interval not met");
+ if (!upkeepNeeded) {
+ revert UpkeepNotNeeded();
+ }
Approximate Gas Savings: This provides two benefits:
- Deployment: A small saving by not storing the 23-byte revert string in the contract bytecode.
- Runtime (on revert): A more significant saving of ~250-400 gas each time the transaction reverts. This is because a custom error avoids the memory allocation and copying operations required for a revert string.
These are just small suggestions to make the starter kit even better. Thanks again for the great work!
- Lenguaje dominante
- Solidity
- Estrellas
- 364
- Forks
- 107
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de smartcontractkit/foundry-starter-kit
-
FCT Init Does Not WorkAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
-
Add Chainlink Functions exampleAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
smartcontractkit/foundry-starter-kit#37 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
smartcontractkit/foundry-starter-kit#36 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
smartcontractkit/foundry-starter-kit#35 · 1 comentario ·
Todos los issues de smartcontractkit/foundry-starter-kit
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
icon-project/sodax-sdks#696 ·
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
th30d4y/OpenLearnX#737 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
btclib-org/btclib-node#2656 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
hiero-ledger/hiero-sdk-js#4832 ·
Los mantenedores suelen responder en 1 día
-
Bigint RPC params are sent as strings when the application defines BigInt.prototype.toJSONPosiblemente ocupada @andreisilviudragnea la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día