storyprotocol / protocol-core-v1

core protocol repo for mainnet launch
Other
44 stars 35 forks source link

Implement Dynamic Gas Cost Calculation for IP Graph Function Calls #231

Open kingster-will opened 2 months ago

kingster-will commented 2 months ago

Description and context

We propose to implement a dynamic gas cost calculation mechanism for different IP Graph function calls, based on memory usage, storage access, and CPU consumption. This enhancement aims to optimize the gas efficiency of our smart contracts by accurately reflecting the computational resources required for each function call.

Details

The current implementation of the IP Graph functions does not dynamically calculate gas costs based on the actual computational resources used. This can lead to inefficiencies, where some operations may consume more gas than necessary.

Implementation Steps:

  1. Benchmarking: Conduct a comprehensive benchmarking of all IP Graph functions to measure memory usage, storage access patterns, and CPU consumption under various conditions.
  2. Gas Cost Model: Develop a gas cost model that calculates the gas cost dynamically based on the benchmarking data. This model should consider gas pricing mechanisms and adjust for future changes in the protocol.
  3. Integration: Integrate the gas cost model into the IP Graph functions, ensuring that gas costs are calculated dynamically at runtime based on the actual computational resources used.

Acceptance Criteria

kingster-will commented 2 months ago

TODO: Add EIP reference link

LeoHChen commented 2 months ago

A good reference for gas cost of precompile.

https://github.com/maticnetwork/Polygon-Improvement-Proposals/pull/147/files#diff-84cb2a1283c96f603aa517fbca6928bd08a918678f466fa136dd8a92afb5a58c

Ramarti commented 1 week ago

Some feedback after talking with auditors scoping, we should have different pricing strategies for read / write. Reads could also be a DDOS vector, but they should be cheaper.