mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Compute SHA3 additional gas cost in 64-bit precision
This commit is contained in:
parent
3ebef61c5b
commit
fdefaca410
1 changed files with 5 additions and 3 deletions
|
|
@ -173,10 +173,12 @@ void GasMeter::countSha3Data(llvm::Value* _dataLength)
|
||||||
assert(m_blockCost > 0); // SHA3 instruction is already counted
|
assert(m_blockCost > 0); // SHA3 instruction is already counted
|
||||||
|
|
||||||
// TODO: This round ups to 32 happens in many places
|
// TODO: This round ups to 32 happens in many places
|
||||||
// FIXME: Overflow possible but Memory::require() also called. Probably 64-bit arith can be used.
|
// FIXME: 64-bit arith used, but not verified
|
||||||
static_assert(c_sha3WordGas != 1, "SHA3 data cost has changed. Update GasMeter");
|
static_assert(c_sha3WordGas != 1, "SHA3 data cost has changed. Update GasMeter");
|
||||||
auto words = m_builder.CreateUDiv(m_builder.CreateAdd(_dataLength, Constant::get(31)), Constant::get(32));
|
auto dataLength64 = getBuilder().CreateTrunc(_dataLength, Type::lowPrecision);
|
||||||
auto cost = m_builder.CreateNUWMul(Constant::get(c_sha3WordGas), words);
|
auto words64 = m_builder.CreateUDiv(m_builder.CreateAdd(dataLength64, getBuilder().getInt64(31)), getBuilder().getInt64(32));
|
||||||
|
auto cost64 = m_builder.CreateNUWMul(getBuilder().getInt64(c_sha3WordGas), words64);
|
||||||
|
auto cost = getBuilder().CreateZExt(cost64, Type::Word);
|
||||||
count(cost);
|
count(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue