aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-05 21:47:21 +0800
committerchriseth <c@ethdev.com>2016-09-05 21:52:44 +0800
commit69c175fe22fc876014ac7dcb7abc707be6dabb2c (patch)
treeab538660d262429c8cabcdac705e8ae49a3eab8a
parent341c9436a8b6f5ae49265a482519e165a7f40395 (diff)
downloaddexon-solidity-69c175fe22fc876014ac7dcb7abc707be6dabb2c.tar.gz
dexon-solidity-69c175fe22fc876014ac7dcb7abc707be6dabb2c.tar.zst
dexon-solidity-69c175fe22fc876014ac7dcb7abc707be6dabb2c.zip
Do not pay new account gas.
If we checked that the target contract exists, we do not have to pay the "new account gas".
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp4
2 files changed, 4 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 25890890..c9de0a4b 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -33,6 +33,7 @@ Features:
* Commandline interface: Using ``-`` as filename allows reading from stdin.
* Interface Json: Fallback function is now part of the ABI.
* Interface: Version string now semver compatible.
+ * Code generator: Do not provide "new account gas" if we know the called account exists.
Bugfixes:
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 4a81e27d..7b6aa50a 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -1524,11 +1524,13 @@ void ExpressionCompiler::appendExternalFunctionCall(
m_context << u256(0);
m_context << dupInstruction(m_context.baseToCurrentStackOffset(contractStackPos));
+ bool existenceChecked = false;
// Check the the target contract exists (has code) for non-low-level calls.
if (funKind == FunctionKind::External || funKind == FunctionKind::CallCode || funKind == FunctionKind::DelegateCall)
{
m_context << Instruction::DUP1 << Instruction::EXTCODESIZE << Instruction::ISZERO;
m_context.appendConditionalJumpTo(m_context.errorTag());
+ existenceChecked = true;
}
if (_functionType.gasSet())
@@ -1540,7 +1542,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
u256 gasNeededByCaller = eth::GasCosts::callGas + 10;
if (_functionType.valueSet())
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
- if (!isCallCode && !isDelegateCall)
+ if (!isCallCode && !isDelegateCall && !existenceChecked)
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
m_context <<
gasNeededByCaller <<