Merge pull request #236 from ethereum/hot_gav

Fix up for new API from EIP-1.1.
This commit is contained in:
Gav Wood 2015-11-23 12:42:28 +01:00
commit 2554d6104a
6 changed files with 18 additions and 15 deletions

View File

@ -24,12 +24,11 @@
#include <algorithm> #include <algorithm>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libethcore/ChainOperationParams.h>
#include <libevmasm/Assembly.h> #include <libevmasm/Assembly.h>
#include <libevmcore/Params.h>
#include <libsolidity/ast/AST.h> #include <libsolidity/ast/AST.h>
#include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/codegen/ExpressionCompiler.h>
#include <libsolidity/codegen/CompilerUtils.h> #include <libsolidity/codegen/CompilerUtils.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::solidity; using namespace dev::solidity;
@ -760,6 +759,7 @@ void Compiler::compileExpression(Expression const& _expression, TypePointer cons
eth::Assembly Compiler::cloneRuntime() eth::Assembly Compiler::cloneRuntime()
{ {
eth::EVMSchedule schedule;
eth::Assembly a; eth::Assembly a;
a << eth::Instruction::CALLDATASIZE; a << eth::Instruction::CALLDATASIZE;
a << u256(0) << eth::Instruction::DUP1 << eth::Instruction::CALLDATACOPY; a << u256(0) << eth::Instruction::DUP1 << eth::Instruction::CALLDATACOPY;
@ -771,7 +771,7 @@ eth::Assembly Compiler::cloneRuntime()
// this is the address which has to be substituted by the linker. // this is the address which has to be substituted by the linker.
//@todo implement as special "marker" AssemblyItem. //@todo implement as special "marker" AssemblyItem.
a << u256("0xcafecafecafecafecafecafecafecafecafecafe"); a << u256("0xcafecafecafecafecafecafecafecafecafecafe");
a << u256(eth::c_callGas + eth::c_callValueTransferGas + 10) << eth::Instruction::GAS << eth::Instruction::SUB; a << u256(schedule.callGas + schedule.callValueTransferGas + 10) << eth::Instruction::GAS << eth::Instruction::SUB;
a << eth::Instruction::CALLCODE; a << eth::Instruction::CALLCODE;
//Propagate error condition (if CALLCODE pushes 0 on stack). //Propagate error condition (if CALLCODE pushes 0 on stack).
a << eth::Instruction::ISZERO; a << eth::Instruction::ISZERO;

View File

@ -23,7 +23,6 @@
#include <libsolidity/codegen/CompilerUtils.h> #include <libsolidity/codegen/CompilerUtils.h>
#include <libsolidity/ast/AST.h> #include <libsolidity/ast/AST.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libevmcore/Params.h>
#include <libsolidity/codegen/ArrayUtils.h> #include <libsolidity/codegen/ArrayUtils.h>
#include <libsolidity/codegen/LValue.h> #include <libsolidity/codegen/LValue.h>

View File

@ -23,17 +23,18 @@
#include <utility> #include <utility>
#include <numeric> #include <numeric>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <libevmcore/Params.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/SHA3.h> #include <libdevcore/SHA3.h>
#include <libethcore/ChainOperationParams.h>
#include <libsolidity/ast/AST.h> #include <libsolidity/ast/AST.h>
#include <libsolidity/codegen/ExpressionCompiler.h> #include <libsolidity/codegen/ExpressionCompiler.h>
#include <libsolidity/codegen/CompilerContext.h> #include <libsolidity/codegen/CompilerContext.h>
#include <libsolidity/codegen/CompilerUtils.h> #include <libsolidity/codegen/CompilerUtils.h>
#include <libsolidity/codegen/LValue.h> #include <libsolidity/codegen/LValue.h>
using namespace std; using namespace std;
// TODO: FIXME: HOMESTEAD: XXX: @chriseth Params deprecated - use EVMSchedule instead.
namespace dev namespace dev
{ {
namespace solidity namespace solidity
@ -1195,6 +1196,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
vector<ASTPointer<Expression const>> const& _arguments vector<ASTPointer<Expression const>> const& _arguments
) )
{ {
eth::EVMSchedule schedule;// TODO: Make relevant to current suppose context.
solAssert( solAssert(
_functionType.takesArbitraryParameters() || _functionType.takesArbitraryParameters() ||
_arguments.size() == _functionType.parameterTypes().size(), "" _arguments.size() == _functionType.parameterTypes().size(), ""
@ -1303,11 +1305,11 @@ void ExpressionCompiler::appendExternalFunctionCall(
{ {
// send all gas except the amount needed to execute "SUB" and "CALL" // send all gas except the amount needed to execute "SUB" and "CALL"
// @todo this retains too much gas for now, needs to be fine-tuned. // @todo this retains too much gas for now, needs to be fine-tuned.
u256 gasNeededByCaller = eth::c_callGas + 10; u256 gasNeededByCaller = schedule.callGas + 10;
if (_functionType.valueSet()) if (_functionType.valueSet())
gasNeededByCaller += eth::c_callValueTransferGas; gasNeededByCaller += schedule.callValueTransferGas;
if (!isCallCode) if (!isCallCode)
gasNeededByCaller += eth::c_callNewAccountGas; // we never know gasNeededByCaller += schedule.callNewAccountGas; // we never know
m_context << m_context <<
gasNeededByCaller << gasNeededByCaller <<
eth::Instruction::GAS << eth::Instruction::GAS <<

View File

@ -34,7 +34,6 @@
#include <libdevcore/CommonData.h> #include <libdevcore/CommonData.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libevmcore/Params.h>
#include <libsolidity/interface/Version.h> #include <libsolidity/interface/Version.h>
#include <libsolidity/parsing/Scanner.h> #include <libsolidity/parsing/Scanner.h>
#include <libsolidity/parsing/Parser.h> #include <libsolidity/parsing/Parser.h>
@ -239,6 +238,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
void CommandLineInterface::handleGasEstimation(string const& _contract) void CommandLineInterface::handleGasEstimation(string const& _contract)
{ {
eth::EVMSchedule schedule; // TODO: make it relevant to the SealEngine/EnvInfo.
using Gas = GasEstimator::GasConsumption; using Gas = GasEstimator::GasConsumption;
if (!m_compiler->assemblyItems(_contract) && !m_compiler->runtimeAssemblyItems(_contract)) if (!m_compiler->assemblyItems(_contract) && !m_compiler->runtimeAssemblyItems(_contract))
return; return;
@ -248,8 +248,8 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
Gas gas = GasEstimator::functionalEstimation(*items); Gas gas = GasEstimator::functionalEstimation(*items);
u256 bytecodeSize(m_compiler->runtimeObject(_contract).bytecode.size()); u256 bytecodeSize(m_compiler->runtimeObject(_contract).bytecode.size());
cout << "construction:" << endl; cout << "construction:" << endl;
cout << " " << gas << " + " << (bytecodeSize * eth::c_createDataGas) << " = "; cout << " " << gas << " + " << (bytecodeSize * schedule.createDataGas) << " = ";
gas += bytecodeSize * eth::c_createDataGas; gas += bytecodeSize * schedule.createDataGas;
cout << gas << endl; cout << gas << endl;
} }
if (eth::AssemblyItems const* items = m_compiler->runtimeAssemblyItems(_contract)) if (eth::AssemblyItems const* items = m_compiler->runtimeAssemblyItems(_contract))

View File

@ -27,7 +27,6 @@
#include <libdevcore/CommonData.h> #include <libdevcore/CommonData.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libevmcore/Params.h>
#include <libsolidity/parsing/Scanner.h> #include <libsolidity/parsing/Scanner.h>
#include <libsolidity/parsing/Parser.h> #include <libsolidity/parsing/Parser.h>
#include <libsolidity/ast/ASTPrinter.h> #include <libsolidity/ast/ASTPrinter.h>
@ -67,6 +66,7 @@ Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract) Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
{ {
eth::EVMSchedule schedule;// TODO: make relevant to supposed context.
Json::Value gasEstimates(Json::objectValue); Json::Value gasEstimates(Json::objectValue);
using Gas = GasEstimator::GasConsumption; using Gas = GasEstimator::GasConsumption;
if (!_compiler.assemblyItems(_contract) && !_compiler.runtimeAssemblyItems(_contract)) if (!_compiler.assemblyItems(_contract) && !_compiler.runtimeAssemblyItems(_contract))
@ -77,7 +77,7 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
u256 bytecodeSize(_compiler.runtimeObject(_contract).bytecode.size()); u256 bytecodeSize(_compiler.runtimeObject(_contract).bytecode.size());
Json::Value creationGas(Json::arrayValue); Json::Value creationGas(Json::arrayValue);
creationGas[0] = gasToJson(gas); creationGas[0] = gasToJson(gas);
creationGas[1] = gasToJson(bytecodeSize * eth::c_createDataGas); creationGas[1] = gasToJson(bytecodeSize * schedule.createDataGas);
gasEstimates["creation"] = creationGas; gasEstimates["creation"] = creationGas;
} }
if (eth::AssemblyItems const* items = _compiler.runtimeAssemblyItems(_contract)) if (eth::AssemblyItems const* items = _compiler.runtimeAssemblyItems(_contract))

View File

@ -59,12 +59,14 @@ public:
void testCreationTimeGas(string const& _sourceCode) void testCreationTimeGas(string const& _sourceCode)
{ {
EVMSchedule schedule;// TODO: make relevant to supposed context.
compileAndRun(_sourceCode); compileAndRun(_sourceCode);
auto state = make_shared<KnownState>(); auto state = make_shared<KnownState>();
PathGasMeter meter(*m_compiler.assemblyItems()); PathGasMeter meter(*m_compiler.assemblyItems());
GasMeter::GasConsumption gas = meter.estimateMax(0, state); GasMeter::GasConsumption gas = meter.estimateMax(0, state);
u256 bytecodeSize(m_compiler.runtimeObject().bytecode.size()); u256 bytecodeSize(m_compiler.runtimeObject().bytecode.size());
gas += bytecodeSize * c_createDataGas; gas += bytecodeSize * schedule.createDataGas;
BOOST_REQUIRE(!gas.isInfinite); BOOST_REQUIRE(!gas.isInfinite);
BOOST_CHECK(gas.value == m_gasUsed); BOOST_CHECK(gas.value == m_gasUsed);
} }