aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2014-10-27 21:13:16 +0800
committerGav Wood <i@gavwood.com>2014-10-27 21:13:16 +0800
commited7a56cc16ad28601d2d6546615a1d1feb5ce527 (patch)
tree08c190587c8203de0a33004ab9f916c72989d080
parent08c45c85b49edad8451a03df4a31363f216db97c (diff)
downloaddexon-solidity-ed7a56cc16ad28601d2d6546615a1d1feb5ce527.tar.gz
dexon-solidity-ed7a56cc16ad28601d2d6546615a1d1feb5ce527.tar.zst
dexon-solidity-ed7a56cc16ad28601d2d6546615a1d1feb5ce527.zip
PoC-7: Reversion of 0-hashes, empty-list hashes and sha3('') -> ''
-rw-r--r--MemTrie.cpp4
-rw-r--r--TrieHash.cpp6
-rw-r--r--crypto.cpp3
-rw-r--r--state.cpp1
-rw-r--r--vm.cpp7
5 files changed, 13 insertions, 8 deletions
diff --git a/MemTrie.cpp b/MemTrie.cpp
index 4879f267..c3a44e1e 100644
--- a/MemTrie.cpp
+++ b/MemTrie.cpp
@@ -437,12 +437,12 @@ MemTrie::~MemTrie()
h256 MemTrie::hash256() const
{
- return m_root ? m_root->hash256() : h256();
+ return m_root ? m_root->hash256() : sha3(dev::rlp(bytesConstRef()));
}
bytes MemTrie::rlp() const
{
- return m_root ? m_root->rlp() : bytes();
+ return m_root ? m_root->rlp() : dev::rlp(bytesConstRef());
}
void MemTrie::debugPrint()
diff --git a/TrieHash.cpp b/TrieHash.cpp
index af32e870..ee4f2e87 100644
--- a/TrieHash.cpp
+++ b/TrieHash.cpp
@@ -162,7 +162,7 @@ h256 hash256(StringMap const& _s)
{
// build patricia tree.
if (_s.empty())
- return h256();
+ return sha3(rlp(""));
HexMap hexMap;
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
hexMap[asNibbles(i->first)] = i->second;
@@ -175,7 +175,7 @@ bytes rlp256(StringMap const& _s)
{
// build patricia tree.
if (_s.empty())
- return bytes();
+ return rlp("");
HexMap hexMap;
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
hexMap[asNibbles(i->first)] = i->second;
@@ -188,7 +188,7 @@ h256 hash256(u256Map const& _s)
{
// build patricia tree.
if (_s.empty())
- return h256();
+ return sha3(rlp(""));
HexMap hexMap;
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second));
diff --git a/crypto.cpp b/crypto.cpp
index 0d3b6202..67286bfc 100644
--- a/crypto.cpp
+++ b/crypto.cpp
@@ -341,6 +341,7 @@ BOOST_AUTO_TEST_CASE(eth_keypairs)
{
eth::Transaction t;
t.nonce = 0;
+ t.type = eth::Transaction::MessageCall;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
auto rlp = t.rlp(false);
@@ -369,6 +370,7 @@ int cryptoTest()
{
eth::Transaction t;
t.nonce = 0;
+ t.type = eth::Transaction::MessageCall;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
auto rlp = t.rlp(false);
@@ -397,6 +399,7 @@ int cryptoTest()
Transaction t;
t.nonce = 0;
t.value = 1; // 1 wei.
+ t.type = eth::Transaction::MessageCall;
t.receiveAddress = toAddress(sha3("123"));
bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s);
diff --git a/state.cpp b/state.cpp
index 99ce3095..b0f279ba 100644
--- a/state.cpp
+++ b/state.cpp
@@ -68,6 +68,7 @@ int stateTest()
Transaction t;
t.nonce = s.transactionsFrom(myMiner.address());
t.value = 1000; // 1e3 wei.
+ t.type = eth::Transaction::MessageCall;
t.receiveAddress = me.address();
t.sign(myMiner.secret());
assert(t.sender() == myMiner.address());
diff --git a/vm.cpp b/vm.cpp
index 2e4571be..b49c5cd2 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -56,14 +56,13 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
get<3>(addresses[ret]) = m_s.code(ret);
}
- t.receiveAddress = ret;
+ t.type = eth::Transaction::ContractCreation;
callcreates.push_back(t);
return ret;
}
bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride)
{
-
u256 contractgas = 0xffff;
Transaction t;
@@ -71,6 +70,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
t.gasPrice = gasPrice;
t.gas = *_gas;
t.data = _data.toVector();
+ t.type = eth::Transaction::MessageCall;
t.receiveAddress = _receiveAddress;
callcreates.push_back(t);
@@ -384,7 +384,7 @@ mArray FakeExtVM::exportCallCreates()
for (Transaction const& tx: callcreates)
{
mObject o;
- o["destination"] = toString(tx.receiveAddress);
+ o["destination"] = tx.type == Transaction::ContractCreation ? "" : toString(tx.receiveAddress);
push(o, "gasLimit", tx.gas);
push(o, "value", tx.value);
o["data"] = "0x" + toHex(tx.data);
@@ -403,6 +403,7 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
BOOST_REQUIRE(tx.count("destination") > 0);
BOOST_REQUIRE(tx.count("gasLimit") > 0);
Transaction t;
+ t.type = tx["destination"].get_str().empty() ? Transaction::ContractCreation : Transaction::MessageCall;
t.receiveAddress = Address(tx["destination"].get_str());
t.value = toInt(tx["value"]);
t.gas = toInt(tx["gasLimit"]);