[Non-Review] Add runtime-aware gas cost accounting #4188
+849
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this pr is experimental for future works, do not review.
Motivation
The current fee schedule applies static, worst-case prices to opcodes and syscalls. Real workloads
show wide variance in CPU, memory, and storage usage, so contracts can significantly underpay (e.g.,
concatenating big buffers or emitting large notifications) while attackers can exploit cheap opcodes
to force expensive work. We also lack a policy knob to tune in-memory allocations independently of
storage writes.
Summary
ResourceCost
model and hook it into the VM so opcodes, syscalls, and native methodscharge for actual CPU, transient memory, and persistent storage.
native contract entry points proportionally to the data they touch.
MemoryFeeFactor
managed by the Policy contract and surface it through RPC, enablinggovernance to tune transient memory pricing.
rules.