Conversation
| Json::Value gasToJson(GasEstimator::GasConsumption const& _gas) | ||
| { | ||
| if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max()) | ||
| return Json::Value(Json::nullValue); |
There was a problem hiding this comment.
This is taken from the jsonCompiler now. Not sure if null or -1 is better (jsonCompiler will need to keep null for backwards compatibility).
There was a problem hiding this comment.
I guess we go with -1 since the JSON IO documentation says that.
There was a problem hiding this comment.
Hm, I actually think null fits better here - we can still change the documentation, can't we?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, "")); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, "")); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Perhaps it is better to name this codeDepositCost - we both were confused by it already ;-)
There was a problem hiding this comment.
Will change, that matches the YP.
d092cff to
243f1ba
Compare
solc/jsonCompiler.cpp
Outdated
| } | ||
| output["external"] = estimates["external"]; | ||
| output["internal"] = estimates["internal"]; | ||
| } else |
bd7dd66 to
d4f1f99
Compare
|
@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) |
There was a problem hiding this comment.
Please use tabs instead of spaces.
| return ret; | ||
| } | ||
|
|
||
| namespace { |
|
Made style changes myself, please merge if you are fine with it. |
…ven if empty (backwards compat)
fac0285 to
54dcb0e
Compare
|
@chriseth thanks I've folded it into the original commit if you don't mind |
Depends on #2113.