Skip to content

Move gasEstimate into CompilerStack#2114

Merged
axic merged 6 commits intodevelopfrom
compilerstack-gasestimate
Apr 13, 2017
Merged

Move gasEstimate into CompilerStack#2114
axic merged 6 commits intodevelopfrom
compilerstack-gasestimate

Conversation

@axic
Copy link
Contributor

@axic axic commented Apr 10, 2017

Depends on #2113.

Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
{
if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max())
return Json::Value(Json::nullValue);
Copy link
Contributor Author

@axic axic Apr 10, 2017

Choose a reason for hiding this comment

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

This is taken from the jsonCompiler now. Not sure if null or -1 is better (jsonCompiler will need to keep null for backwards compatibility).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we go with -1 since the JSON IO documentation says that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I actually think null fits better here - we can still change the documentation, can't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can. I think -1 is nicer because then we are not at the mercy of jsoncpp whether it serialises null or not. With -1 it is clear the function is present, but we couldn't measure it.

Copy link
Contributor Author

@axic axic Apr 10, 2017

Choose a reason for hiding this comment

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

Alternatively we could make it a string and then no truncation is required. Infinity is then either a string ("infinite" or "infinity") as well or a special value (such as -1?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the issue with serializing null. My idea behind null is that (of course depending on the type-safety of the language used after having parsed the json) you cannot really add null to a finite gas value, whereas adding -1 to a finite gas value yields an actual result.

On the other hand, gas values might be quite large - this is an estimation after all and we use bigints here. So perhaps decimal-encoded integers for finite values and the string infinite for unknown upper bounds would be the best solution here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see we already do a range check here. Perhaps it is better to keep it here since users would probably not do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem I have is that null may or may not be serialised in the JSON hence we lose the information that a given function exists.

I am leaning towards using strings, that way both infinity and >53bits can be represented (though this is less of a real issue).

The jsonCompiler will use null for backwards compatibility, but the new JSON IO will have it as a string.

}

if (contract.fallbackFunction())
externalFunctions[""] = gasToJson(GasEstimator::functionalEstimation(*items, ""));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old code used INVALID as a signature here, though that is not needed, as an empty string will simply not trigger the calldata replacement code in functionalEstimation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep INVALID. The fallback function is called for an invalid signature. There is an optimization that jumps directly to the fallback if the input is empty, so I think it would take this optimization here and thus not calculate the upper bound correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back with an explanation of the reason.

Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
{
if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max())
return Json::Value(Json::nullValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I actually think null fits better here - we can still change the documentation, can't we?

}

if (contract.fallbackFunction())
externalFunctions[""] = gasToJson(GasEstimator::functionalEstimation(*items, ""));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep INVALID. The fallback function is called for an invalid signature. There is an optimization that jumps directly to the fallback if the input is empty, so I think it would take this optimization here and thus not calculate the upper bound correctly.

Gas dataGas = bytecodeSize * eth::GasCosts::createDataGas;

Json::Value creation(Json::objectValue);
creation["dataCost"] = gasToJson(dataGas);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it is better to name this codeDepositCost - we both were confused by it already ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change, that matches the YP.

@axic axic force-pushed the compilerstack-gasestimate branch 3 times, most recently from d092cff to 243f1ba Compare April 11, 2017 09:00
}
output["external"] = estimates["external"];
output["internal"] = estimates["internal"];
} else
Copy link
Contributor

Choose a reason for hiding this comment

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

else on the next line.

@axic axic force-pushed the compilerstack-gasestimate branch 4 times, most recently from bd7dd66 to d4f1f99 Compare April 12, 2017 11:11
@axic
Copy link
Contributor Author

axic commented Apr 12, 2017

@chriseth this version has the same output on the CLI and jsonCompiler as before, but internally (and in StandardCompiler) it represents the gas values as a string, including "infinite", to avoid information loss.


Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
{
if (_gas.isInfinite)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use tabs instead of spaces.

return ret;
}

namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Brace to the next line.

@chriseth
Copy link
Contributor

Made style changes myself, please merge if you are fine with it.

@axic axic force-pushed the compilerstack-gasestimate branch from fac0285 to 54dcb0e Compare April 13, 2017 01:18
@axic
Copy link
Contributor Author

axic commented Apr 13, 2017

@chriseth thanks I've folded it into the original commit if you don't mind

@axic axic merged commit 138c952 into develop Apr 13, 2017
@axic axic removed the in progress label Apr 13, 2017
@axic axic deleted the compilerstack-gasestimate branch April 13, 2017 01:37
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.

2 participants