4 #include <llvm/IR/IntrinsicInst.h> 20 m_runtimeManager(_runtimeManager),
28 auto checkBB = llvm::BasicBlock::Create(_builder.getContext(),
"Check",
m_gasCheckFunc);
29 auto updateBB = llvm::BasicBlock::Create(_builder.getContext(),
"Update",
m_gasCheckFunc);
30 auto outOfGasBB = llvm::BasicBlock::Create(_builder.getContext(),
"OutOfGas",
m_gasCheckFunc);
33 llvm::Argument* gasPtr = &(*iter++);
34 gasPtr->setName(
"gasPtr");
35 llvm::Argument* cost = &(*iter++);
36 cost->setName(
"cost");
37 llvm::Argument* jmpBuf = &(*iter);
38 jmpBuf->setName(
"jmpBuf");
42 auto gas =
m_builder.CreateLoad(gasPtr,
"gas");
43 auto gasUpdated =
m_builder.CreateNSWSub(gas, cost,
"gasUpdated");
48 m_builder.CreateStore(gasUpdated, gasPtr);
72 auto tooHigh =
m_builder.CreateICmpUGT(_cost, gasMax256,
"costTooHigh");
88 auto ctlz = llvm::Intrinsic::getDeclaration(
getModule(), llvm::Intrinsic::ctlz,
Type::Word);
99 auto oldValue = _ext.
sload(_index);
102 auto isInsert =
m_builder.CreateAnd(oldValueIsZero, newValueIsntZero,
"isInsert");
103 assert(JITSchedule::sstoreResetGas::value == JITSchedule::sstoreClearGas::value &&
"Update SSTORE gas cost");
104 auto cost =
m_builder.CreateSelect(isInsert,
m_builder.getInt64(JITSchedule::sstoreSetGas::value),
m_builder.getInt64(JITSchedule::sstoreResetGas::value),
"cost");
112 assert(JITSchedule::logDataGas::value != 1 &&
"Log data gas cost has changed. Update GasMeter.");
122 assert(JITSchedule::sha3WordGas::value != 1 &&
"SHA3 data cost has changed. Update GasMeter");
125 auto cost64 =
m_builder.CreateNUWMul(
m_builder.getInt64(JITSchedule::sha3WordGas::value), words64);
156 assert(JITSchedule::memoryGas::value != 1 &&
"Memory gas cost has changed. Update GasMeter.");
157 count(_additionalMemoryInWords, _jmpBuf, _gasPtr);
162 assert(JITSchedule::copyGas::value != 1 &&
"Copy gas cost has changed. Update GasMeter.");
174 return JITSchedule::stepGas0::value;
193 return JITSchedule::stepGas1::value;
218 return JITSchedule::stepGas2::value;
227 return JITSchedule::stepGas3::value;
233 return JITSchedule::stepGas4::value;
238 return JITSchedule::stepGas5::value;
249 return JITSchedule::stepGas6::value;
252 return JITSchedule::sha3Gas::value;
258 return JITSchedule::jumpdestGas::value;
266 auto numTopics =
static_cast<int64_t
>(inst) - static_cast<int64_t>(
Instruction::LOG0);
267 return JITSchedule::logGas::value + numTopics * JITSchedule::logTopicGas::value;
276 return JITSchedule::createGas::value;
signed greater-than comparision
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
unsigned modular addition
get external code size (from another contract)
RuntimeManager & m_runtimeManager
int64_t m_blockCost
Cumulative gas cost of a block of instructions Handle overflow.
void commitCostBlock()
Finalize cost-block by checking gas needed for the block before the block.
unsigned modular multiplication
void setGas(llvm::Value *_gas)
get the block's timestamp
void countSha3Data(llvm::Value *_dataLength)
Count gas cost of SHA3 data.
llvm::Module * getModule()
Reference to the IR module being compiled.
conditionally alter the program counter
llvm::Value * sload(llvm::Value *_index)
llvm::Value * getGasPtr()
void countCopy(llvm::Value *_copyWords)
Count addional gas cost for memory copy.
copy input data in current environment to memory
evm_mode m_mode
EVM compatibility mode.
retrieve single byte from word
get execution origination address
Makes a log entry; 4 topics.
get the block's number
integer division operation
assert(len-trim+(2 *lenIndices)<=WIDTH)
get the block's coinbase address
set a potential jump destination
Instruction
Virtual machine bytecode instruction.
get input data of current environment
halt execution and register account for later deletion
signed integer division operation
signed less-than comparision
halt execution returning output data
Base class for compiler helpers like Memory, GasMeter, etc.
get address of currently executing account
get hash of most recent complete block
static llvm::PointerType * BytePtr
get size of code running in current environment
Makes a log entry; no topics.
get the size of active memory
get the block's gas limit
get balance of the given account
message-call with another account's code only
static llvm::IntegerType * Word
static llvm::ConstantInt * gasMax
get size of input data in current environment
void countExp(llvm::Value *_exponent)
Calculate & count additional gas cost for EXP instruction.
extend length of signed integer
static llvm::ConstantInt * get(int64_t _n)
Returns word-size constant.
copy code running in current environment to memory
evm_mode
EVM compatibility mode aka chain mode.
signed modulo remainder operation
like CALLCODE but keeps caller's value and sender
void abort(llvm::Value *_jmpBuf)
get the amount of available gas
copy external code (from another contract)
void giveBack(llvm::Value *_gas)
Give back an amount of gas not used by a call.
get deposited value by the instruction/transaction responsible for this execution ...
get price of gas in current environment
void countLogData(llvm::Value *_dataLength)
Count gas cost of LOG data.
alter the program counter to a jumpdest
GasMeter(IRBuilder &_builder, RuntimeManager &_runtimeManager, evm_mode mode)
Makes a log entry; 1 topic.
llvm::Function * m_gasCheckFunc
message-call into an account
get the block's difficulty
void count(Instruction _inst)
Count step cost of instruction.
void countMemory(llvm::Value *_additionalMemoryInWords, llvm::Value *_jmpBuf, llvm::Value *_gasPtr)
Generate code that checks the cost of additional memory used by program.
IRBuilder & m_builder
Reference to parent compiler IR builder.
llvm::IRBuilder<> IRBuilder
static llvm::MDNode * expectTrue
int64_t getStepCost(Instruction inst) const
Makes a log entry; 3 topics.
void countSStore(class Ext &_ext, llvm::Value *_index, llvm::Value *_newValue)
Calculate & count gas cost for SSTORE instruction.
static llvm::IntegerType * Gas
llvm::CallInst * m_checkCall
modulo remainder operation
create a new account with associated code
llvm::Value * getJmpBuf()
Makes a log entry; 2 topics.