aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-05-10 15:48:00 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-05-30 17:54:29 +0800
commit0c8beac35785a3c688c48c7f607832c30509c907 (patch)
tree042638c13656bd597f4c8fa719b28c71ddac058d
parent0066a08aa8f6c469cde7947ec50ca662a32123a0 (diff)
downloaddexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar.gz
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar.bz2
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar.lz
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar.xz
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.tar.zst
dexon-solidity-0c8beac35785a3c688c48c7f607832c30509c907.zip
Rename the SHA3 assembly instruction to KECCAK256
-rw-r--r--libevmasm/CommonSubexpressionEliminator.cpp4
-rw-r--r--libevmasm/EVMSchedule.h4
-rw-r--r--libevmasm/GasMeter.cpp6
-rw-r--r--libevmasm/GasMeter.h4
-rw-r--r--libevmasm/Instruction.cpp4
-rw-r--r--libevmasm/Instruction.h2
-rw-r--r--libevmasm/KnownState.cpp20
-rw-r--r--libevmasm/KnownState.h8
-rw-r--r--libsolidity/codegen/ArrayUtils.cpp4
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp2
-rw-r--r--libsolidity/codegen/CompilerUtils.h2
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp8
-rw-r--r--test/libsolidity/SolidityOptimizer.cpp30
13 files changed, 49 insertions, 49 deletions
diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp
index fd4fffa6..70324e7f 100644
--- a/libevmasm/CommonSubexpressionEliminator.cpp
+++ b/libevmasm/CommonSubexpressionEliminator.cpp
@@ -234,7 +234,7 @@ void CSECodeGenerator::addDependencies(Id _c)
if (expr.item && expr.item->type() == Operation && (
expr.item->instruction() == Instruction::SLOAD ||
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
@@ -260,7 +260,7 @@ void CSECodeGenerator::addDependencies(Id _c)
case Instruction::MLOAD:
knownToBeIndependent = m_expressionClasses.knownToBeDifferentBy32(slot, slotToLoadFrom);
break;
- case Instruction::SHA3:
+ case Instruction::KECCAK256:
{
Id length = expr.arguments.at(1);
AssemblyItem offsetInstr(Instruction::SUB, expr.item->location());
diff --git a/libevmasm/EVMSchedule.h b/libevmasm/EVMSchedule.h
index 65d307ae..1695a59c 100644
--- a/libevmasm/EVMSchedule.h
+++ b/libevmasm/EVMSchedule.h
@@ -32,8 +32,8 @@ struct EVMSchedule
unsigned stackLimit = 1024;
unsigned expGas = 10;
unsigned expByteGas = 10;
- unsigned sha3Gas = 30;
- unsigned sha3WordGas = 6;
+ unsigned keccak256Gas = 30;
+ unsigned keccak256WordGas = 6;
unsigned sloadGas = 200;
unsigned sstoreSetGas = 20000;
unsigned sstoreResetGas = 5000;
diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp
index f5fd00ea..260b7439 100644
--- a/libevmasm/GasMeter.cpp
+++ b/libevmasm/GasMeter.cpp
@@ -96,9 +96,9 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
classes.find(AssemblyItem(1))
}));
break;
- case Instruction::SHA3:
- gas = GasCosts::sha3Gas;
- gas += wordGas(GasCosts::sha3WordGas, m_state->relativeStackElement(-1));
+ case Instruction::KECCAK256:
+ gas = GasCosts::keccak256Gas;
+ gas += wordGas(GasCosts::keccak256WordGas, m_state->relativeStackElement(-1));
gas += memoryGas(0, -1);
break;
case Instruction::CALLDATACOPY:
diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h
index 3169ff2a..2c3ecf5a 100644
--- a/libevmasm/GasMeter.h
+++ b/libevmasm/GasMeter.h
@@ -48,8 +48,8 @@ namespace GasCosts
static unsigned const balanceGas = 400;
static unsigned const expGas = 10;
static unsigned const expByteGas = 50;
- static unsigned const sha3Gas = 30;
- static unsigned const sha3WordGas = 6;
+ static unsigned const keccak256Gas = 30;
+ static unsigned const keccak256WordGas = 6;
static unsigned const sloadGas = 200;
static unsigned const sstoreSetGas = 20000;
static unsigned const sstoreResetGas = 5000;
diff --git a/libevmasm/Instruction.cpp b/libevmasm/Instruction.cpp
index 5e92c6e6..25eab60b 100644
--- a/libevmasm/Instruction.cpp
+++ b/libevmasm/Instruction.cpp
@@ -53,7 +53,7 @@ const std::map<std::string, Instruction> dev::solidity::c_instructions =
{ "ADDMOD", Instruction::ADDMOD },
{ "MULMOD", Instruction::MULMOD },
{ "SIGNEXTEND", Instruction::SIGNEXTEND },
- { "SHA3", Instruction::SHA3 },
+ { "KECCAK256", Instruction::KECCAK256 },
{ "ADDRESS", Instruction::ADDRESS },
{ "BALANCE", Instruction::BALANCE },
{ "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::MULMOD, { "MULMOD", 0, 3, 1, false, Tier::Mid } },
{ 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::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Balance } },
{ Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, Tier::Base } },
diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h
index 192fe090..5fec7988 100644
--- a/libevmasm/Instruction.h
+++ b/libevmasm/Instruction.h
@@ -62,7 +62,7 @@ enum class Instruction: uint8_t
NOT, ///< bitwise NOT opertation
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
BALANCE, ///< get balance of the given account
diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp
index 6e3130dd..e2f10f22 100644
--- a/libevmasm/KnownState.cpp
+++ b/libevmasm/KnownState.cpp
@@ -136,10 +136,10 @@ KnownState::StoreOperation KnownState::feedItem(AssemblyItem const& _item, bool
m_stackHeight + _item.deposit(),
loadFromMemory(arguments[0], _item.location())
);
- else if (_item.instruction() == Instruction::SHA3)
+ else if (_item.instruction() == Instruction::KECCAK256)
setStackElement(
m_stackHeight + _item.deposit(),
- applySha3(arguments.at(0), arguments.at(1), _item.location())
+ applyKeccak256(arguments.at(0), arguments.at(1), _item.location())
);
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);
}
-KnownState::Id KnownState::applySha3(
+KnownState::Id KnownState::applyKeccak256(
Id _start,
Id _length,
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.
u256 const* l = m_expressionClasses->knownConstant(_length);
// unknown or too large length
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;
for (u256 i = 0; i < *l; i += 32)
@@ -368,10 +368,10 @@ KnownState::Id KnownState::applySha3(
);
arguments.push_back(loadFromMemory(slot, _location));
}
- if (m_knownSha3Hashes.count(arguments))
- return m_knownSha3Hashes.at(arguments);
+ if (m_knownKeccak256Hashes.count(arguments))
+ return m_knownKeccak256Hashes.at(arguments);
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); }))
{
bytes data;
@@ -381,8 +381,8 @@ KnownState::Id KnownState::applySha3(
v = m_expressionClasses->find(AssemblyItem(u256(dev::keccak256(data)), _location));
}
else
- v = m_expressionClasses->find(sha3Item, {_start, _length}, true, m_sequenceNumber);
- return m_knownSha3Hashes[arguments] = v;
+ v = m_expressionClasses->find(keccak256Item, {_start, _length}, true, m_sequenceNumber);
+ return m_knownKeccak256Hashes[arguments] = v;
}
set<u256> KnownState::tagsInExpression(KnownState::Id _expressionId)
diff --git a/libevmasm/KnownState.h b/libevmasm/KnownState.h
index fd6a26c1..8568b163 100644
--- a/libevmasm/KnownState.h
+++ b/libevmasm/KnownState.h
@@ -150,8 +150,8 @@ private:
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.
Id loadFromMemory(Id _slot, SourceLocation const& _location);
- /// Finds or creates a new expression that applies the sha3 hash function to the contents in memory.
- Id applySha3(Id _start, Id _length, SourceLocation const& _location);
+ /// Finds or creates a new expression that applies the Keccak-256 hash function to the contents in memory.
+ Id applyKeccak256(Id _start, Id _length, SourceLocation const& _location);
/// @returns a new or already used Id representing the given set of 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
/// and are not contained here if they are not completely known.
std::map<Id, Id> m_memoryContent;
- /// Keeps record of all sha3 hashes that are computed.
- std::map<std::vector<Id>, Id> m_knownSha3Hashes;
+ /// Keeps record of all Keccak-256 hashes that are computed.
+ std::map<std::vector<Id>, Id> m_knownKeccak256Hashes;
/// Structure containing the classes of equivalent expressions.
std::shared_ptr<ExpressionClasses> m_expressionClasses;
/// Container for unions of tags stored on the stack.
diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp
index bdd29abd..6a641b02 100644
--- a/libsolidity/codegen/ArrayUtils.cpp
+++ b/libsolidity/codegen/ArrayUtils.cpp
@@ -449,7 +449,7 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord
m_context << Instruction::DUP3 << Instruction::ADD << Instruction::SWAP2;
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;
utils.computeHashStatic();
m_context << Instruction::SWAP1;
@@ -731,7 +731,7 @@ void ArrayUtils::resizeDynamicArray(ArrayType const& _typeIn) const
_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
// store new length
_context << Instruction::DUP2;
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 4ae9a09a..3baaaddf 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -934,7 +934,7 @@ unsigned CompilerUtils::sizeOnStack(vector<shared_ptr<Type const>> const& _varia
void CompilerUtils::computeHashStatic()
{
storeInMemory(0);
- m_context << u256(32) << u256(0) << Instruction::SHA3;
+ m_context << u256(32) << u256(0) << Instruction::KECCAK256;
}
void CompilerUtils::storeStringData(bytesConstRef _data)
diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h
index 4140ce8b..a88951bc 100644
--- a/libsolidity/codegen/CompilerUtils.h
+++ b/libsolidity/codegen/CompilerUtils.h
@@ -166,7 +166,7 @@ public:
static unsigned sizeOnStack(std::vector<T> const& _variables);
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();
/// Bytes we need to the start of call data.
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index 0aa82ea8..25154bc0 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -110,7 +110,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const&
// move key to memory.
utils().copyToStackTop(paramTypes.size() - i, 1);
utils().storeInMemory(0);
- m_context << u256(64) << u256(0) << Instruction::SHA3;
+ m_context << u256(64) << u256(0) << Instruction::KECCAK256;
// push offset
m_context << u256(0);
returnType = mappingType->valueType();
@@ -674,7 +674,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
utils().fetchFreeMemoryPointer();
utils().encodeToMemory(argumentTypes, TypePointers(), function.padArguments(), true);
utils().toSizeAfterFreeMemoryPointer();
- m_context << Instruction::SHA3;
+ m_context << Instruction::KECCAK256;
break;
}
case FunctionType::Kind::Log0:
@@ -721,7 +721,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
true
);
utils().toSizeAfterFreeMemoryPointer();
- m_context << Instruction::SHA3;
+ m_context << Instruction::KECCAK256;
}
else
utils().convertType(
@@ -1214,7 +1214,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
utils().storeInMemoryDynamic(IntegerType(256));
m_context << u256(0);
}
- m_context << Instruction::SHA3;
+ m_context << Instruction::KECCAK256;
m_context << u256(0);
setLValueToStorageItem(_indexAccess);
}
diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp
index d705e3c8..bbd09ce5 100644
--- a/test/libsolidity/SolidityOptimizer.cpp
+++ b/test/libsolidity/SolidityOptimizer.cpp
@@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(retain_information_in_branches)
bytes optimizedBytecode = compileAndRunWithOptimizer(sourceCode, 0, "c", true);
size_t numSHA3s = 0;
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
- if (_instr == Instruction::SHA3)
+ if (_instr == Instruction::KECCAK256)
numSHA3s++;
});
// 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);
size_t numSHA3s = 0;
eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
- if (_instr == Instruction::SHA3)
+ if (_instr == Instruction::KECCAK256)
numSHA3s++;
});
// TEST DISABLED UNTIL 93693404 IS IMPLEMENTED
@@ -826,7 +826,7 @@ BOOST_AUTO_TEST_CASE(cse_empty_sha3)
AssemblyItems input{
u256(0),
Instruction::DUP2,
- Instruction::SHA3
+ Instruction::KECCAK256
};
checkCSE(input, {
u256(dev::keccak256(bytesConstRef()))
@@ -841,7 +841,7 @@ BOOST_AUTO_TEST_CASE(cse_partial_sha3)
Instruction::MSTORE,
u256(2),
u256(0),
- Instruction::SHA3
+ Instruction::KECCAK256
};
checkCSE(input, {
u256(0xabcd) << (256 - 16),
@@ -860,10 +860,10 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_location)
Instruction::MSTORE,
u256(64),
Instruction::DUP2,
- Instruction::SHA3,
+ Instruction::KECCAK256,
u256(64),
Instruction::DUP3,
- Instruction::SHA3
+ Instruction::KECCAK256
};
checkCSE(input, {
Instruction::DUP2,
@@ -871,7 +871,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_location)
Instruction::MSTORE,
u256(64),
Instruction::DUP2,
- Instruction::SHA3,
+ Instruction::KECCAK256,
Instruction::DUP1
});
}
@@ -885,13 +885,13 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content)
Instruction::MSTORE, // m[128] = DUP1
u256(0x20),
u256(0x80),
- Instruction::SHA3, // sha3(m[128..(128+32)])
+ Instruction::KECCAK256, // keccak256(m[128..(128+32)])
Instruction::DUP2,
u256(12),
Instruction::MSTORE, // m[12] = DUP1
u256(0x20),
u256(12),
- Instruction::SHA3 // sha3(m[12..(12+32)])
+ Instruction::KECCAK256 // keccak256(m[12..(12+32)])
};
checkCSE(input, {
u256(0x80),
@@ -900,7 +900,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content)
Instruction::MSTORE,
u256(0x20),
Instruction::SWAP1,
- Instruction::SHA3,
+ Instruction::KECCAK256,
u256(12),
Instruction::DUP3,
Instruction::SWAP1,
@@ -921,7 +921,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_dynamic_store_in_between)
u256(0x20),
Instruction::DUP1,
Instruction::DUP3,
- Instruction::SHA3, // sha3(m[128..(128+32)])
+ Instruction::KECCAK256, // keccak256(m[128..(128+32)])
u256(12),
Instruction::DUP5,
Instruction::DUP2,
@@ -932,7 +932,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_dynamic_store_in_between)
Instruction::SWAP2,
Instruction::SWAP1,
Instruction::SWAP2,
- Instruction::SHA3 // sha3(m[12..(12+32)])
+ Instruction::KECCAK256 // keccak256(m[12..(12+32)])
};
checkCSE(input, input);
}
@@ -949,7 +949,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between
u256(0x20),
Instruction::DUP1,
Instruction::DUP3,
- Instruction::SHA3, // sha3(m[128..(128+32)])
+ Instruction::KECCAK256, // keccak256(m[128..(128+32)])
u256(12),
Instruction::DUP5,
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
u256(0x20),
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
AssemblyItems output = CSE(input);
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)