mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename the SHA3 assembly instruction to KECCAK256
This commit is contained in:
parent
0066a08aa8
commit
0c8beac357
@ -234,7 +234,7 @@ void CSECodeGenerator::addDependencies(Id _c)
|
|||||||
if (expr.item && expr.item->type() == Operation && (
|
if (expr.item && expr.item->type() == Operation && (
|
||||||
expr.item->instruction() == Instruction::SLOAD ||
|
expr.item->instruction() == Instruction::SLOAD ||
|
||||||
expr.item->instruction() == Instruction::MLOAD ||
|
expr.item->instruction() == Instruction::MLOAD ||
|
||||||
expr.item->instruction() == Instruction::SHA3
|
expr.item->instruction() == Instruction::KECCAK256
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
// this loads an unknown value from storage or memory and thus, in addition to its
|
// this loads an unknown value from storage or memory and thus, in addition to its
|
||||||
@ -260,7 +260,7 @@ void CSECodeGenerator::addDependencies(Id _c)
|
|||||||
case Instruction::MLOAD:
|
case Instruction::MLOAD:
|
||||||
knownToBeIndependent = m_expressionClasses.knownToBeDifferentBy32(slot, slotToLoadFrom);
|
knownToBeIndependent = m_expressionClasses.knownToBeDifferentBy32(slot, slotToLoadFrom);
|
||||||
break;
|
break;
|
||||||
case Instruction::SHA3:
|
case Instruction::KECCAK256:
|
||||||
{
|
{
|
||||||
Id length = expr.arguments.at(1);
|
Id length = expr.arguments.at(1);
|
||||||
AssemblyItem offsetInstr(Instruction::SUB, expr.item->location());
|
AssemblyItem offsetInstr(Instruction::SUB, expr.item->location());
|
||||||
|
@ -32,8 +32,8 @@ struct EVMSchedule
|
|||||||
unsigned stackLimit = 1024;
|
unsigned stackLimit = 1024;
|
||||||
unsigned expGas = 10;
|
unsigned expGas = 10;
|
||||||
unsigned expByteGas = 10;
|
unsigned expByteGas = 10;
|
||||||
unsigned sha3Gas = 30;
|
unsigned keccak256Gas = 30;
|
||||||
unsigned sha3WordGas = 6;
|
unsigned keccak256WordGas = 6;
|
||||||
unsigned sloadGas = 200;
|
unsigned sloadGas = 200;
|
||||||
unsigned sstoreSetGas = 20000;
|
unsigned sstoreSetGas = 20000;
|
||||||
unsigned sstoreResetGas = 5000;
|
unsigned sstoreResetGas = 5000;
|
||||||
|
@ -96,9 +96,9 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
|
|||||||
classes.find(AssemblyItem(1))
|
classes.find(AssemblyItem(1))
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case Instruction::SHA3:
|
case Instruction::KECCAK256:
|
||||||
gas = GasCosts::sha3Gas;
|
gas = GasCosts::keccak256Gas;
|
||||||
gas += wordGas(GasCosts::sha3WordGas, m_state->relativeStackElement(-1));
|
gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1));
|
||||||
gas += memoryGas(0, -1);
|
gas += memoryGas(0, -1);
|
||||||
break;
|
break;
|
||||||
case Instruction::CALLDATACOPY:
|
case Instruction::CALLDATACOPY:
|
||||||
|
@ -48,8 +48,8 @@ namespace GasCosts
|
|||||||
static unsigned const balanceGas = 400;
|
static unsigned const balanceGas = 400;
|
||||||
static unsigned const expGas = 10;
|
static unsigned const expGas = 10;
|
||||||
static unsigned const expByteGas = 50;
|
static unsigned const expByteGas = 50;
|
||||||
static unsigned const sha3Gas = 30;
|
static unsigned const keccak256Gas = 30;
|
||||||
static unsigned const sha3WordGas = 6;
|
static unsigned const keccak256WordGas = 6;
|
||||||
static unsigned const sloadGas = 200;
|
static unsigned const sloadGas = 200;
|
||||||
static unsigned const sstoreSetGas = 20000;
|
static unsigned const sstoreSetGas = 20000;
|
||||||
static unsigned const sstoreResetGas = 5000;
|
static unsigned const sstoreResetGas = 5000;
|
||||||
|
@ -53,7 +53,7 @@ const std::map<std::string, Instruction> dev::solidity::c_instructions =
|
|||||||
{ "ADDMOD", Instruction::ADDMOD },
|
{ "ADDMOD", Instruction::ADDMOD },
|
||||||
{ "MULMOD", Instruction::MULMOD },
|
{ "MULMOD", Instruction::MULMOD },
|
||||||
{ "SIGNEXTEND", Instruction::SIGNEXTEND },
|
{ "SIGNEXTEND", Instruction::SIGNEXTEND },
|
||||||
{ "SHA3", Instruction::SHA3 },
|
{ "KECCAK256", Instruction::KECCAK256 },
|
||||||
{ "ADDRESS", Instruction::ADDRESS },
|
{ "ADDRESS", Instruction::ADDRESS },
|
||||||
{ "BALANCE", Instruction::BALANCE },
|
{ "BALANCE", Instruction::BALANCE },
|
||||||
{ "ORIGIN", Instruction::ORIGIN },
|
{ "ORIGIN", Instruction::ORIGIN },
|
||||||
@ -189,7 +189,7 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
|
|||||||
{ Instruction::ADDMOD, { "ADDMOD", 0, 3, 1, false, Tier::Mid } },
|
{ Instruction::ADDMOD, { "ADDMOD", 0, 3, 1, false, Tier::Mid } },
|
||||||
{ Instruction::MULMOD, { "MULMOD", 0, 3, 1, false, Tier::Mid } },
|
{ Instruction::MULMOD, { "MULMOD", 0, 3, 1, false, Tier::Mid } },
|
||||||
{ Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1, false, Tier::Low } },
|
{ Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1, false, Tier::Low } },
|
||||||
{ Instruction::SHA3, { "SHA3", 0, 2, 1, false, Tier::Special } },
|
{ Instruction::KECCAK256, { "KECCAK256", 0, 2, 1, false, Tier::Special } },
|
||||||
{ Instruction::ADDRESS, { "ADDRESS", 0, 0, 1, false, Tier::Base } },
|
{ Instruction::ADDRESS, { "ADDRESS", 0, 0, 1, false, Tier::Base } },
|
||||||
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Balance } },
|
{ Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Balance } },
|
||||||
{ Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, Tier::Base } },
|
{ Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, Tier::Base } },
|
||||||
|
@ -62,7 +62,7 @@ enum class Instruction: uint8_t
|
|||||||
NOT, ///< bitwise NOT opertation
|
NOT, ///< bitwise NOT opertation
|
||||||
BYTE, ///< retrieve single byte from word
|
BYTE, ///< retrieve single byte from word
|
||||||
|
|
||||||
SHA3 = 0x20, ///< compute SHA3-256 hash
|
KECCAK256 = 0x20, ///< compute KECCAK-256 hash
|
||||||
|
|
||||||
ADDRESS = 0x30, ///< get address of currently executing account
|
ADDRESS = 0x30, ///< get address of currently executing account
|
||||||
BALANCE, ///< get balance of the given account
|
BALANCE, ///< get balance of the given account
|
||||||
|
@ -136,10 +136,10 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
|
|||||||
m_stackHeight + _item.deposit(),
|
m_stackHeight + _item.deposit(),
|
||||||
loadFromMemory(arguments[0], _item.location())
|
loadFromMemory(arguments[0], _item.location())
|
||||||
);
|
);
|
||||||
else if (_item.instruction() == Instruction::SHA3)
|
else if (_item.instruction() == Instruction::KECCAK256)
|
||||||
setStackElement(
|
setStackElement(
|
||||||
m_stackHeight + _item.deposit(),
|
m_stackHeight + _item.deposit(),
|
||||||
applySha3(arguments.at(0), arguments.at(1), _item.location())
|
applyKeccak256(arguments.at(0), arguments.at(1), _item.location())
|
||||||
);
|
);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -346,18 +346,18 @@ ExpressionClasses::Id KnownState::loadFromMemory(Id _slot, SourceLocation const&
|
|||||||
return m_memoryContent[_slot] = m_expressionClasses->find(item, {_slot}, true, m_sequenceNumber);
|
return m_memoryContent[_slot] = m_expressionClasses->find(item, {_slot}, true, m_sequenceNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
KnownState::Id KnownState::applySha3(
|
KnownState::Id KnownState::applyKeccak256(
|
||||||
Id _start,
|
Id _start,
|
||||||
Id _length,
|
Id _length,
|
||||||
SourceLocation const& _location
|
SourceLocation const& _location
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
AssemblyItem sha3Item(Instruction::SHA3, _location);
|
AssemblyItem keccak256Item(Instruction::KECCAK256, _location);
|
||||||
// Special logic if length is a short constant, otherwise we cannot tell.
|
// Special logic if length is a short constant, otherwise we cannot tell.
|
||||||
u256 const* l = m_expressionClasses->knownConstant(_length);
|
u256 const* l = m_expressionClasses->knownConstant(_length);
|
||||||
// unknown or too large length
|
// unknown or too large length
|
||||||
if (!l || *l > 128)
|
if (!l || *l > 128)
|
||||||
return m_expressionClasses->find(sha3Item, {_start, _length}, true, m_sequenceNumber);
|
return m_expressionClasses->find(keccak256Item, {_start, _length}, true, m_sequenceNumber);
|
||||||
|
|
||||||
vector<Id> arguments;
|
vector<Id> arguments;
|
||||||
for (u256 i = 0; i < *l; i += 32)
|
for (u256 i = 0; i < *l; i += 32)
|
||||||
@ -368,10 +368,10 @@ KnownState::Id KnownState::applySha3(
|
|||||||
);
|
);
|
||||||
arguments.push_back(loadFromMemory(slot, _location));
|
arguments.push_back(loadFromMemory(slot, _location));
|
||||||
}
|
}
|
||||||
if (m_knownSha3Hashes.count(arguments))
|
if (m_knownKeccak256Hashes.count(arguments))
|
||||||
return m_knownSha3Hashes.at(arguments);
|
return m_knownKeccak256Hashes.at(arguments);
|
||||||
Id v;
|
Id v;
|
||||||
// If all arguments are known constants, compute the sha3 here
|
// If all arguments are known constants, compute the Keccak-256 here
|
||||||
if (all_of(arguments.begin(), arguments.end(), [this](Id _a) { return !!m_expressionClasses->knownConstant(_a); }))
|
if (all_of(arguments.begin(), arguments.end(), [this](Id _a) { return !!m_expressionClasses->knownConstant(_a); }))
|
||||||
{
|
{
|
||||||
bytes data;
|
bytes data;
|
||||||
@ -381,8 +381,8 @@ KnownState::Id KnownState::applySha3(
|
|||||||
v = m_expressionClasses->find(AssemblyItem(u256(dev::keccak256(data)), _location));
|
v = m_expressionClasses->find(AssemblyItem(u256(dev::keccak256(data)), _location));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
v = m_expressionClasses->find(sha3Item, {_start, _length}, true, m_sequenceNumber);
|
v = m_expressionClasses->find(keccak256Item, {_start, _length}, true, m_sequenceNumber);
|
||||||
return m_knownSha3Hashes[arguments] = v;
|
return m_knownKeccak256Hashes[arguments] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
set<u256> KnownState::tagsInExpression(KnownState::Id _expressionId)
|
set<u256> KnownState::tagsInExpression(KnownState::Id _expressionId)
|
||||||
|
@ -150,8 +150,8 @@ private:
|
|||||||
StoreOperation storeInMemory(Id _slot, Id _value, SourceLocation const& _location);
|
StoreOperation storeInMemory(Id _slot, Id _value, SourceLocation const& _location);
|
||||||
/// Retrieves the current value at the given slot in memory or creates a new special mload class.
|
/// Retrieves the current value at the given slot in memory or creates a new special mload class.
|
||||||
Id loadFromMemory(Id _slot, SourceLocation const& _location);
|
Id loadFromMemory(Id _slot, SourceLocation const& _location);
|
||||||
/// Finds or creates a new expression that applies the sha3 hash function to the contents in memory.
|
/// Finds or creates a new expression that applies the Keccak-256 hash function to the contents in memory.
|
||||||
Id applySha3(Id _start, Id _length, SourceLocation const& _location);
|
Id applyKeccak256(Id _start, Id _length, SourceLocation const& _location);
|
||||||
|
|
||||||
/// @returns a new or already used Id representing the given set of tags.
|
/// @returns a new or already used Id representing the given set of tags.
|
||||||
Id tagUnion(std::set<u256> _tags);
|
Id tagUnion(std::set<u256> _tags);
|
||||||
@ -167,8 +167,8 @@ private:
|
|||||||
/// Knowledge about memory content. Keys are memory addresses, note that the values overlap
|
/// Knowledge about memory content. Keys are memory addresses, note that the values overlap
|
||||||
/// and are not contained here if they are not completely known.
|
/// and are not contained here if they are not completely known.
|
||||||
std::map<Id, Id> m_memoryContent;
|
std::map<Id, Id> m_memoryContent;
|
||||||
/// Keeps record of all sha3 hashes that are computed.
|
/// Keeps record of all Keccak-256 hashes that are computed.
|
||||||
std::map<std::vector<Id>, Id> m_knownSha3Hashes;
|
std::map<std::vector<Id>, Id> m_knownKeccak256Hashes;
|
||||||
/// Structure containing the classes of equivalent expressions.
|
/// Structure containing the classes of equivalent expressions.
|
||||||
std::shared_ptr<ExpressionClasses> m_expressionClasses;
|
std::shared_ptr<ExpressionClasses> m_expressionClasses;
|
||||||
/// Container for unions of tags stored on the stack.
|
/// Container for unions of tags stored on the stack.
|
||||||
|
@ -449,7 +449,7 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord
|
|||||||
m_context << Instruction::DUP3 << Instruction::ADD << Instruction::SWAP2;
|
m_context << Instruction::DUP3 << Instruction::ADD << Instruction::SWAP2;
|
||||||
if (_sourceType.isDynamicallySized())
|
if (_sourceType.isDynamicallySized())
|
||||||
{
|
{
|
||||||
// actual array data is stored at SHA3(storage_offset)
|
// actual array data is stored at KECCAK256(storage_offset)
|
||||||
m_context << Instruction::SWAP1;
|
m_context << Instruction::SWAP1;
|
||||||
utils.computeHashStatic();
|
utils.computeHashStatic();
|
||||||
m_context << Instruction::SWAP1;
|
m_context << Instruction::SWAP1;
|
||||||
@ -731,7 +731,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
|
|||||||
_context << Instruction::POP;
|
_context << Instruction::POP;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change of length for a regular array (i.e. length at location, data at sha3(location)).
|
// Change of length for a regular array (i.e. length at location, data at KECCAK256(location)).
|
||||||
// stack: ref new_length old_length
|
// stack: ref new_length old_length
|
||||||
// store new length
|
// store new length
|
||||||
_context << Instruction::DUP2;
|
_context << Instruction::DUP2;
|
||||||
|
@ -934,7 +934,7 @@ unsigned CompilerUtils::sizeOnStack(vector<shared_ptr<Type const>> const& _varia
|
|||||||
void CompilerUtils::computeHashStatic()
|
void CompilerUtils::computeHashStatic()
|
||||||
{
|
{
|
||||||
storeInMemory(0);
|
storeInMemory(0);
|
||||||
m_context << u256(32) << u256(0) << Instruction::SHA3;
|
m_context << u256(32) << u256(0) << Instruction::KECCAK256;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerUtils::storeStringData(bytesConstRef _data)
|
void CompilerUtils::storeStringData(bytesConstRef _data)
|
||||||
|
@ -166,7 +166,7 @@ public:
|
|||||||
static unsigned sizeOnStack(std::vector<T> const& _variables);
|
static unsigned sizeOnStack(std::vector<T> const& _variables);
|
||||||
static unsigned sizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes);
|
static unsigned sizeOnStack(std::vector<std::shared_ptr<Type const>> const& _variableTypes);
|
||||||
|
|
||||||
/// Appends code that computes tha SHA3 hash of the topmost stack element of 32 byte type.
|
/// Appends code that computes tha Keccak-256 hash of the topmost stack element of 32 byte type.
|
||||||
void computeHashStatic();
|
void computeHashStatic();
|
||||||
|
|
||||||
/// Bytes we need to the start of call data.
|
/// Bytes we need to the start of call data.
|
||||||
|
@ -110,7 +110,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
|
|||||||
// move key to memory.
|
// move key to memory.
|
||||||
utils().copyToStackTop(paramTypes.size() - i, 1);
|
utils().copyToStackTop(paramTypes.size() - i, 1);
|
||||||
utils().storeInMemory(0);
|
utils().storeInMemory(0);
|
||||||
m_context << u256(64) << u256(0) << Instruction::SHA3;
|
m_context << u256(64) << u256(0) << Instruction::KECCAK256;
|
||||||
// push offset
|
// push offset
|
||||||
m_context << u256(0);
|
m_context << u256(0);
|
||||||
returnType = mappingType->valueType();
|
returnType = mappingType->valueType();
|
||||||
@ -674,7 +674,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
utils().fetchFreeMemoryPointer();
|
utils().fetchFreeMemoryPointer();
|
||||||
utils().encodeToMemory(argumentTypes, TypePointers(), function.padArguments(), true);
|
utils().encodeToMemory(argumentTypes, TypePointers(), function.padArguments(), true);
|
||||||
utils().toSizeAfterFreeMemoryPointer();
|
utils().toSizeAfterFreeMemoryPointer();
|
||||||
m_context << Instruction::SHA3;
|
m_context << Instruction::KECCAK256;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::Log0:
|
case FunctionType::Kind::Log0:
|
||||||
@ -721,7 +721,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
utils().toSizeAfterFreeMemoryPointer();
|
utils().toSizeAfterFreeMemoryPointer();
|
||||||
m_context << Instruction::SHA3;
|
m_context << Instruction::KECCAK256;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
utils().convertType(
|
utils().convertType(
|
||||||
@ -1214,7 +1214,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
|
|||||||
utils().storeInMemoryDynamic(IntegerType(256));
|
utils().storeInMemoryDynamic(IntegerType(256));
|
||||||
m_context << u256(0);
|
m_context << u256(0);
|
||||||
}
|
}
|
||||||
m_context << Instruction::SHA3;
|
m_context << Instruction::KECCAK256;
|
||||||
m_context << u256(0);
|
m_context << u256(0);
|
||||||
setLValueToStorageItem(_indexAccess);
|
setLValueToStorageItem(_indexAccess);
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(retain_information_in_branches)
|
|||||||
bytes optimizedBytecode = compileAndRunWithOptimizer(sourceCode, 0, "c", true);
|
bytes optimizedBytecode = compileAndRunWithOptimizer(sourceCode, 0, "c", true);
|
||||||
size_t numSHA3s = 0;
|
size_t numSHA3s = 0;
|
||||||
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
||||||
if (_instr == Instruction::SHA3)
|
if (_instr == Instruction::KECCAK256)
|
||||||
numSHA3s++;
|
numSHA3s++;
|
||||||
});
|
});
|
||||||
// TEST DISABLED - OPTIMIZER IS NOT EFFECTIVE ON THIS ONE ANYMORE
|
// TEST DISABLED - OPTIMIZER IS NOT EFFECTIVE ON THIS ONE ANYMORE
|
||||||
@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE(store_tags_as_unions)
|
|||||||
bytes optimizedBytecode = compileAndRunWithOptimizer(sourceCode, 0, "test", true);
|
bytes optimizedBytecode = compileAndRunWithOptimizer(sourceCode, 0, "test", true);
|
||||||
size_t numSHA3s = 0;
|
size_t numSHA3s = 0;
|
||||||
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
|
||||||
if (_instr == Instruction::SHA3)
|
if (_instr == Instruction::KECCAK256)
|
||||||
numSHA3s++;
|
numSHA3s++;
|
||||||
});
|
});
|
||||||
// TEST DISABLED UNTIL 93693404 IS IMPLEMENTED
|
// TEST DISABLED UNTIL 93693404 IS IMPLEMENTED
|
||||||
@ -826,7 +826,7 @@ BOOST_AUTO_TEST_CASE(cse_empty_sha3)
|
|||||||
AssemblyItems input{
|
AssemblyItems input{
|
||||||
u256(0),
|
u256(0),
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
Instruction::SHA3
|
Instruction::KECCAK256
|
||||||
};
|
};
|
||||||
checkCSE(input, {
|
checkCSE(input, {
|
||||||
u256(dev::keccak256(bytesConstRef()))
|
u256(dev::keccak256(bytesConstRef()))
|
||||||
@ -841,7 +841,7 @@ BOOST_AUTO_TEST_CASE(cse_partial_sha3)
|
|||||||
Instruction::MSTORE,
|
Instruction::MSTORE,
|
||||||
u256(2),
|
u256(2),
|
||||||
u256(0),
|
u256(0),
|
||||||
Instruction::SHA3
|
Instruction::KECCAK256
|
||||||
};
|
};
|
||||||
checkCSE(input, {
|
checkCSE(input, {
|
||||||
u256(0xabcd) << (256 - 16),
|
u256(0xabcd) << (256 - 16),
|
||||||
@ -860,10 +860,10 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_location)
|
|||||||
Instruction::MSTORE,
|
Instruction::MSTORE,
|
||||||
u256(64),
|
u256(64),
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
Instruction::SHA3,
|
Instruction::KECCAK256,
|
||||||
u256(64),
|
u256(64),
|
||||||
Instruction::DUP3,
|
Instruction::DUP3,
|
||||||
Instruction::SHA3
|
Instruction::KECCAK256
|
||||||
};
|
};
|
||||||
checkCSE(input, {
|
checkCSE(input, {
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
@ -871,7 +871,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_location)
|
|||||||
Instruction::MSTORE,
|
Instruction::MSTORE,
|
||||||
u256(64),
|
u256(64),
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
Instruction::SHA3,
|
Instruction::KECCAK256,
|
||||||
Instruction::DUP1
|
Instruction::DUP1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -885,13 +885,13 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content)
|
|||||||
Instruction::MSTORE, // m[128] = DUP1
|
Instruction::MSTORE, // m[128] = DUP1
|
||||||
u256(0x20),
|
u256(0x20),
|
||||||
u256(0x80),
|
u256(0x80),
|
||||||
Instruction::SHA3, // sha3(m[128..(128+32)])
|
Instruction::KECCAK256, // keccak256(m[128..(128+32)])
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::MSTORE, // m[12] = DUP1
|
Instruction::MSTORE, // m[12] = DUP1
|
||||||
u256(0x20),
|
u256(0x20),
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::SHA3 // sha3(m[12..(12+32)])
|
Instruction::KECCAK256 // keccak256(m[12..(12+32)])
|
||||||
};
|
};
|
||||||
checkCSE(input, {
|
checkCSE(input, {
|
||||||
u256(0x80),
|
u256(0x80),
|
||||||
@ -900,7 +900,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content)
|
|||||||
Instruction::MSTORE,
|
Instruction::MSTORE,
|
||||||
u256(0x20),
|
u256(0x20),
|
||||||
Instruction::SWAP1,
|
Instruction::SWAP1,
|
||||||
Instruction::SHA3,
|
Instruction::KECCAK256,
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::DUP3,
|
Instruction::DUP3,
|
||||||
Instruction::SWAP1,
|
Instruction::SWAP1,
|
||||||
@ -921,7 +921,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_dynamic_store_in_between)
|
|||||||
u256(0x20),
|
u256(0x20),
|
||||||
Instruction::DUP1,
|
Instruction::DUP1,
|
||||||
Instruction::DUP3,
|
Instruction::DUP3,
|
||||||
Instruction::SHA3, // sha3(m[128..(128+32)])
|
Instruction::KECCAK256, // keccak256(m[128..(128+32)])
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::DUP5,
|
Instruction::DUP5,
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
@ -932,7 +932,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_dynamic_store_in_between)
|
|||||||
Instruction::SWAP2,
|
Instruction::SWAP2,
|
||||||
Instruction::SWAP1,
|
Instruction::SWAP1,
|
||||||
Instruction::SWAP2,
|
Instruction::SWAP2,
|
||||||
Instruction::SHA3 // sha3(m[12..(12+32)])
|
Instruction::KECCAK256 // keccak256(m[12..(12+32)])
|
||||||
};
|
};
|
||||||
checkCSE(input, input);
|
checkCSE(input, input);
|
||||||
}
|
}
|
||||||
@ -949,7 +949,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between
|
|||||||
u256(0x20),
|
u256(0x20),
|
||||||
Instruction::DUP1,
|
Instruction::DUP1,
|
||||||
Instruction::DUP3,
|
Instruction::DUP3,
|
||||||
Instruction::SHA3, // sha3(m[128..(128+32)])
|
Instruction::KECCAK256, // keccak256(m[128..(128+32)])
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::DUP5,
|
Instruction::DUP5,
|
||||||
Instruction::DUP2,
|
Instruction::DUP2,
|
||||||
@ -962,12 +962,12 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between
|
|||||||
Instruction::MSTORE, // does not destoy memory knowledge
|
Instruction::MSTORE, // does not destoy memory knowledge
|
||||||
u256(0x20),
|
u256(0x20),
|
||||||
u256(12),
|
u256(12),
|
||||||
Instruction::SHA3 // sha3(m[12..(12+32)])
|
Instruction::KECCAK256 // keccak256(m[12..(12+32)])
|
||||||
};
|
};
|
||||||
// if this changes too often, only count the number of SHA3 and MSTORE instructions
|
// if this changes too often, only count the number of SHA3 and MSTORE instructions
|
||||||
AssemblyItems output = CSE(input);
|
AssemblyItems output = CSE(input);
|
||||||
BOOST_CHECK_EQUAL(4, count(output.begin(), output.end(), AssemblyItem(Instruction::MSTORE)));
|
BOOST_CHECK_EQUAL(4, count(output.begin(), output.end(), AssemblyItem(Instruction::MSTORE)));
|
||||||
BOOST_CHECK_EQUAL(1, count(output.begin(), output.end(), AssemblyItem(Instruction::SHA3)));
|
BOOST_CHECK_EQUAL(1, count(output.begin(), output.end(), AssemblyItem(Instruction::KECCAK256)));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cse_with_initially_known_stack)
|
BOOST_AUTO_TEST_CASE(cse_with_initially_known_stack)
|
||||||
|
Loading…
Reference in New Issue
Block a user