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

Clean up the handling of gas (use int64_t only) #332

Merged
merged 1 commit into from
Aug 21, 2018
Merged

Conversation

axic
Copy link
Member

@axic axic commented Aug 19, 2018

Part of #311.

@axic axic force-pushed the gas-handling branch 3 times, most recently from 20440d1 to afab377 Compare August 19, 2018 21:16
@axic axic changed the title [WIP] Gas handling Clean up the handling of gas (use int64_t only) Aug 19, 2018
@axic axic requested a review from chfast August 19, 2018 21:16
@axic
Copy link
Member Author

axic commented Aug 19, 2018

@chfast I think this should be correct now (tests are failing though due to the edge cases I guess?). Can you have a look at the logic in this PR?

@axic axic force-pushed the gas-handling branch 4 times, most recently from 93cdff3 to 1287376 Compare August 19, 2018 21:46
@codecov-io
Copy link

codecov-io commented Aug 19, 2018

Codecov Report

Merging #332 into master will increase coverage by 0.03%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   67.28%   67.31%   +0.03%     
==========================================
  Files           5        5              
  Lines         868      875       +7     
  Branches      123      123              
==========================================
+ Hits          584      589       +5     
- Misses        255      257       +2     
  Partials       29       29

src/eei.cpp Outdated
@@ -485,7 +487,7 @@ namespace hera {
static_assert(GasSchedule::logTopic <= 65536, "Gas cost of logTopic could lead to overflow");
static_assert(GasSchedule::logData <= 65536, "Gas cost of logData could lead to overflow");
// Using uint64_t to force a type issue if the underlying API changes.
takeInterfaceGas(GasSchedule::log + (GasSchedule::logTopic * numberOfTopics) + (GasSchedule::logData * static_cast<uint64_t>(length)));
takeInterfaceGas(GasSchedule::log + (GasSchedule::logTopic * numberOfTopics) + (GasSchedule::logData * static_cast<int64_t>(length)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is safe cast, so you can use int64_t(length).

src/eei.cpp Outdated
@@ -1012,7 +1018,7 @@ namespace hera {
// Allow 16 bits here.
static_assert(GasSchedule::copy <= 65536, "Gas cost of copy could lead to overflow");
// Using uint64_t to force a type issue if the underlying API changes.
takeInterfaceGas(GasSchedule::copy * ((static_cast<uint64_t>(length) + 31) / 32));
takeInterfaceGas(GasSchedule::copy * ((static_cast<int64_t>(length) + 31) / 32));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This cast is safe, could use int64_t(length).

@@ -1001,7 +1007,7 @@ namespace hera {
/*
* Utilities
*/
void EthereumInterface::safeChargeDataCopy(uint32_t length, uint32_t baseCost) {
void EthereumInterface::safeChargeDataCopy(uint32_t length, unsigned baseCost) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why have you changed this?
From my little experience I recommend using int or int64_t for cost constants as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

The constants are currently defined as unsigned, wanted to ensure it is the same here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@chfast chfast left a comment

Choose a reason for hiding this comment

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

Approving conditionally, but waiting for two int64_t(length) changes.

@axic axic merged commit 98b47bf into master Aug 21, 2018
@axic axic deleted the gas-handling branch August 21, 2018 07:42
@axic axic removed the in progress label Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants