Support shifts in gas estimator

This commit is contained in:
Alex Beregszaszi 2018-04-30 21:22:59 +01:00
parent 2968639406
commit 059e232e69

View File

@ -136,13 +136,22 @@ 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) << 224)
});
if (!m_evmVersion.hasBitwiseShifting())
// div(calldataload(0), 1 << 224) equals to hashValue
classes.forceEqual(
hashValue,
Instruction::DIV,
Ids{calldata, classes.find(u256(1) << 224)}
);
else
// shr(0xe0, calldataload(0)) equals to hashValue
classes.forceEqual(
hashValue,
Instruction::SHR,
Ids{classes.find(u256(0xe0)), calldata}
);
// lt(calldatasize(), 4) equals to 0 (ignore the shortcut for fallback functions)
classes.forceEqual(
classes.find(u256(0)),