Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] EEI: charge for memory gas cost in useGas #65

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ namespace hera {
ensureCondition(gas >= 0, ArgumentOutOfRange, "Negative gas supplied.");

takeGas(gas);

// FIXME: this may overflow
heraAssert((ffsl(gas) + ffsl(memory.size()) <= 64), "Memory gas calculation overflow."); //may need to find alternative to ffsl for cross-libc portability
takeGas(gas * memory.size() / GasSchedule::memoryPageSize * GasSchedule::memoryCostPerPage + 1); //round gas cost up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure whether this should be rounded up or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. What are the pros/cons for each?

}

int64_t EthereumInterface::eeiGetGasLeft()
Expand Down
3 changes: 3 additions & 0 deletions src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class EthereumInterface {
};

struct GasSchedule {
static constexpr unsigned memoryPageSize = 65536;
static constexpr unsigned memoryCostPerPage = 1;

static constexpr unsigned storageLoad = 200;
static constexpr unsigned storageStoreCreate = 20000;
static constexpr unsigned storageStoreChange = 5000;
Expand Down