tejas0111/pharos/gas-optimization

Claude Code and agent skill by tejas0111/pharos

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install tejas0111/pharos/gas-optimization

SKILL.md

The same SKILL.md was published earlier as tejas0111/pharos/gas-optimization.

Gas Optimization

Overview

Optimize Solidity contract gas usage for the Pharos ecosystem. Pharos uses a Dual-VM architecture (EVM + WASM via DTVM) with SALI-aware storage and EIP-1559 fee market. Each Pharos-specific feature changes the optimization calculus vs Ethereum.

Pharos-Specific Gas Model

FeaturePharosEthereum
VMDTVM (EVM + WASM)EVM only
Block Gas Limit1B gas30M gas
Fee ModelEIP-1559EIP-1559
StorageSALI-friendlyStandard
Calldata4 gas/byte (0-calldata ops cheaper)16 gas/byte

Real Contract Optimizations

1. Struct Packing (SALI-Friendly)

Pharos's SALI (Storage Access Layer Interface) rewards tightly packed storage slots. Compare:

Inefficient (3 slots):

solidity
// Gas: ~42,000 for write
struct Loan {
uint256 collateralAmount; // slot 0
uint256 borrowAmount; // slot 1
uint256 lastUpdate; // slot 2
bool active; // slot 3 (wasted!)
}

Optimized (2 slots):

solidity
// Gas: ~28,000 for write (33% savings)
struct Loan {
uint256 collateralAmount; // slot 0
uint128 borrowAmount; // slot 1 (fits in 128 bits)
uint64 lastUpdate; // slot 1
bool active; // slot 1
}
Real example: contracts/PharosLendingPool.sol uses a Position struct — packing timestamp next to amounts saves ~14k gas per liquidation.
2. Use calldata Instead of memory
solidity
// Bad: copies to memory (3,724 gas for 100-element array)
function process(uint256[] memory data) external { }
// Good: reads from calldata (178 gas for same array)
function process(uint256[] calldata data) external { }
Real example: contracts/PharosSPNPaymaster.sol passes PackedUserOperation calldata — 95% gas savings vs memory.
3. Custom Errors Over Strings
solidity
// Bad: ~24,000 gas
require(amount > 0, "Amount must be > 0");
// Good: ~140 gas (99.4% savings)
error ZeroAmount();
if (amount == 0) revert ZeroAmount();
Real example: Every contract in the project uses custom errors. contracts/DEXPool.sol saves ~23k gas per revert vs string errors.
4. Batch Operations
solidity
// Bad: N individual calls
for (uint i; i < users.length; i++) addSponsor(users[i]);
// Good: batch in one call
function addSponsors(address[] calldata _users) external {
// One EVM call, one SSTORE per user
}
Real example: contracts/PharosSPNPaymaster.sol has addSponsors() — saves 21,000 gas vs N individual calls.
5. Use uint256 for Gas-Only Values

Despite packing advice, use uint256 for values that are:

  • Compared against msg.value (always uint256)
  • Used in block.timestamp arithmetic
  • Divided/multiplied (Solidity casts anyway)
Real example: contracts/StakingPool.sol uses uint256 for s_rewardRate since it's involved in division — prevents implicit cast costs.

Testing Gas

bash
# Get per-function gas report
forge test --gas-report | grep -A5 "StakingPool"
# Custom gas test
function test_Gas_Stake() external {
uint256 gasBefore = gasleft();
pool.stake(100 ether);
uint256 gasUsed = gasBefore - gasleft();
assertLt(gasUsed, 100000, "Stake too expensive");
}
Covers: contracts/StakingPool.sol stake function should be <100k gas.

Optimization Cheat Sheet

TechniqueSavingsWhere Applied
Struct packing~14k gas/writeLendingPool, StakingPool
Custom errors~23k gas/revertAll contracts
calldata params~3.5k gas/callSPN Paymaster, DEXPool
Batch operations~21k gas/batchSPN Paymaster
Unchecked blocks~200 gas/opDEXPool loops
Short-circuitVariesOr conditions in all contracts
Pre-increment~5 gas/loop++i vs i++ in loops

References

  • contracts/PharosLendingPool.sol — struct packing example
  • contracts/PharosSPNPaymaster.sol — calldata + batch patterns
  • contracts/DEXPool.sol — unchecked math + custom errors

Security

  • Security scanPassed, 98 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/tejas0111/pharos/gas-optimization/badge)](https://verified-skill.com/skills/tejas0111/pharos/gas-optimization)

Something wrong with this skill or its page? Tell us.