aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-12 00:30:20 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-12 02:42:34 +0800
commit928ce088456987431143262dcde2d02553b68192 (patch)
tree6c5ca27bac6d81d7df19ce27e662de08edf1da9f
parentd50d1f0ac1841a1d287a216451e93573fc07474e (diff)
downloaddexon-solidity-928ce088456987431143262dcde2d02553b68192.tar.gz
dexon-solidity-928ce088456987431143262dcde2d02553b68192.tar.zst
dexon-solidity-928ce088456987431143262dcde2d02553b68192.zip
Correctly ignore costs of fallback for other functions.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/interface/GasEstimator.cpp9
-rw-r--r--test/libsolidity/GasMeter.cpp13
3 files changed, 22 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 6df11f27..c6de5872 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -27,6 +27,7 @@ Bugfixes:
* Code Generator: Treat empty base constructor argument list as not provided.
* Commandline interface: Support ``--evm-version constantinople`` properly.
* DocString Parser: Fix error message for empty descriptions.
+ * Gas Estimator: Correctly ignore costs of fallback function for other functions.
* Standard JSON: Support ``constantinople`` as ``evmVersion`` properly.
* Type Checker: Fix detection of recursive structs.
* Type Checker: Fix asymmetry bug when comparing with literal numbers.
diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp
index 2139395f..a496cc21 100644
--- a/libsolidity/interface/GasEstimator.cpp
+++ b/libsolidity/interface/GasEstimator.cpp
@@ -136,12 +136,19 @@ GasEstimator::GasConsumption GasEstimator::functionalEstimation(
ExpressionClasses& classes = state->expressionClasses();
using Id = ExpressionClasses::Id;
using Ids = vector<Id>;
+ // div(calldataload(0), 1 << 224) equals to hashValue
Id hashValue = classes.find(u256(FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(_signature)))));
Id calldata = classes.find(Instruction::CALLDATALOAD, Ids{classes.find(u256(0))});
classes.forceEqual(hashValue, Instruction::DIV, Ids{
calldata,
- classes.find(u256(1) << (8 * 28))
+ classes.find(u256(1) << 224)
});
+ // lt(calldatasize(), 4) equals to 0 (ignore the shortcut for fallback functions)
+ classes.forceEqual(
+ classes.find(u256(0)),
+ Instruction::LT,
+ Ids{classes.find(Instruction::CALLDATASIZE), classes.find(u256(4))}
+ );
}
PathGasMeter meter(_items, m_evmVersion);
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index fd2017f9..0d66456c 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -294,6 +294,19 @@ BOOST_AUTO_TEST_CASE(extcodesize_gas)
testRunTimeGas("f()", vector<bytes>{encodeArgs()});
}
+BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
+{
+ // A bug in the estimator caused the costs for a specific function
+ // to always include the costs for the fallback.
+ char const* sourceCode = R"(
+ contract A {
+ uint public x;
+ function() { x = 2; }
+ }
+ )";
+ testCreationTimeGas(sourceCode);
+ testRunTimeGas("x()", vector<bytes>{encodeArgs()});
+}
BOOST_AUTO_TEST_SUITE_END()
}