mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move to semi-official new Trie format.
This commit is contained in:
parent
1d6b7cff01
commit
58d10e79be
@ -1,13 +1,19 @@
|
|||||||
cmake_policy(SET CMP0015 NEW)
|
cmake_policy(SET CMP0015 NEW)
|
||||||
|
|
||||||
aux_source_directory(. SRC_LIST)
|
aux_source_directory(. SRC_LIST)
|
||||||
|
|
||||||
include_directories(../../secp256k1/include)
|
include_directories(../../secp256k1/include)
|
||||||
|
link_directories(../../secp256k1)
|
||||||
|
|
||||||
|
include_directories(../../cryptopp562)
|
||||||
|
link_directories(../../cryptopp562)
|
||||||
|
|
||||||
include_directories(../libethereum)
|
include_directories(../libethereum)
|
||||||
link_directories(../libethereum)
|
link_directories(../libethereum)
|
||||||
link_directories(../../secp256k1)
|
|
||||||
|
|
||||||
add_executable(testeth ${SRC_LIST})
|
add_executable(testeth ${SRC_LIST})
|
||||||
|
|
||||||
target_link_libraries(testeth ethereum)
|
target_link_libraries(testeth ethereum)
|
||||||
|
target_link_libraries(testeth cryptopp)
|
||||||
target_link_libraries(testeth secp256k1)
|
target_link_libraries(testeth secp256k1)
|
||||||
target_link_libraries(testeth gmp)
|
target_link_libraries(testeth gmp)
|
||||||
|
37
main.cpp
37
main.cpp
@ -33,6 +33,7 @@ using namespace eth;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
// Test transaction.
|
// Test transaction.
|
||||||
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
|
bytes tx = fromUserHex("88005401010101010101010101010101010101010101011f0de0b6b3a76400001ce8d4a5100080181c373130a009ba1f10285d4e659568bfcfec85067855c5a3c150100815dad4ef98fd37cf0593828c89db94bd6c64e210a32ef8956eaa81ea9307194996a3b879441f5d");
|
||||||
cout << "TX: " << RLP(tx) << endl;
|
cout << "TX: " << RLP(tx) << endl;
|
||||||
@ -46,10 +47,10 @@ int main()
|
|||||||
auto msg = t.rlp(false);
|
auto msg = t.rlp(false);
|
||||||
cout << "TX w/o SIG: " << RLP(msg) << endl;
|
cout << "TX w/o SIG: " << RLP(msg) << endl;
|
||||||
cout << "RLP(TX w/o SIG): " << asHex(t.rlpString(false)) << endl;
|
cout << "RLP(TX w/o SIG): " << asHex(t.rlpString(false)) << endl;
|
||||||
std::string hmsg = sha256(t.rlpString(false), false);
|
std::string hmsg = sha3(t.rlpString(false), false);
|
||||||
cout << "SHA256(RLP(TX w/o SIG)): 0x" << asHex(hmsg) << endl;
|
cout << "SHA256(RLP(TX w/o SIG)): 0x" << asHex(hmsg) << endl;
|
||||||
|
|
||||||
bytes privkey = sha256Bytes("123");
|
bytes privkey = sha3Bytes("123");
|
||||||
|
|
||||||
secp256k1_start();
|
secp256k1_start();
|
||||||
|
|
||||||
@ -87,20 +88,32 @@ int main()
|
|||||||
int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v - 27);
|
int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v - 27);
|
||||||
pubkey.resize(pubkeylen);
|
pubkey.resize(pubkeylen);
|
||||||
cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
|
cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << asHex(pubkey) << endl;
|
||||||
cout << "SENDER: " << hex << low160(eth::sha256(bytesConstRef(&pubkey).cropped(1))) << endl;
|
cout << "SENDER: " << hex << low160(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
Trie t;
|
Trie t;
|
||||||
|
cout << hex << hash256(StringMap({})) << endl;
|
||||||
|
cout << hex << t.hash256() << endl;
|
||||||
|
cout << hex << hash256({{"dog", "puppy"}, {"doe", "reindeer"}}) << endl;
|
||||||
t.insert("dog", "puppy");
|
t.insert("dog", "puppy");
|
||||||
assert(t.sha256() == hash256({{"dog", "puppy"}}));
|
t.insert("doe", "reindeer");
|
||||||
|
cout << hex << t.hash256() << endl;
|
||||||
|
cout << RLP(t.rlp()) << endl;
|
||||||
|
cout << asHex(t.rlp()) << endl;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Trie t;
|
||||||
|
|
||||||
|
t.insert("dog", "puppy");
|
||||||
|
assert(t.hash256() == hash256({{"dog", "puppy"}}));
|
||||||
assert(t.at("dog") == "puppy");
|
assert(t.at("dog") == "puppy");
|
||||||
t.insert("doe", "reindeer");
|
t.insert("doe", "reindeer");
|
||||||
assert(t.sha256() == hash256({{"dog", "puppy"}, {"doe", "reindeer"}}));
|
assert(t.hash256() == hash256({{"dog", "puppy"}, {"doe", "reindeer"}}));
|
||||||
assert(t.at("doe") == "reindeer");
|
assert(t.at("doe") == "reindeer");
|
||||||
assert(t.at("dog") == "puppy");
|
assert(t.at("dog") == "puppy");
|
||||||
t.insert("dogglesworth", "cat");
|
t.insert("dogglesworth", "cat");
|
||||||
assert(t.sha256() == hash256({{"doe", "reindeer"}, {"dog", "puppy"}, {"dogglesworth", "cat"}}));
|
assert(t.hash256() == hash256({{"doe", "reindeer"}, {"dog", "puppy"}, {"dogglesworth", "cat"}}));
|
||||||
assert(t.at("doe") == "reindeer");
|
assert(t.at("doe") == "reindeer");
|
||||||
assert(t.at("dog") == "puppy");
|
assert(t.at("dog") == "puppy");
|
||||||
assert(t.at("dogglesworth") == "cat");
|
assert(t.at("dogglesworth") == "cat");
|
||||||
@ -109,11 +122,11 @@ int main()
|
|||||||
assert(t.at("doe").empty());
|
assert(t.at("doe").empty());
|
||||||
assert(t.at("dogglesworth").empty());
|
assert(t.at("dogglesworth").empty());
|
||||||
assert(t.at("dog") == "puppy");
|
assert(t.at("dog") == "puppy");
|
||||||
assert(t.sha256() == hash256({{"dog", "puppy"}}));
|
assert(t.hash256() == hash256({{"dog", "puppy"}}));
|
||||||
t.insert("horse", "stallion");
|
t.insert("horse", "stallion");
|
||||||
t.insert("do", "verb");
|
t.insert("do", "verb");
|
||||||
t.insert("doge", "coin");
|
t.insert("doge", "coin");
|
||||||
assert(t.sha256() == hash256({{"dog", "puppy"}, {"horse", "stallion"}, {"do", "verb"}, {"doge", "coin"}}));
|
assert(t.hash256() == hash256({{"dog", "puppy"}, {"horse", "stallion"}, {"do", "verb"}, {"doge", "coin"}}));
|
||||||
assert(t.at("doge") == "coin");
|
assert(t.at("doge") == "coin");
|
||||||
assert(t.at("do") == "verb");
|
assert(t.at("do") == "verb");
|
||||||
assert(t.at("horse") == "stallion");
|
assert(t.at("horse") == "stallion");
|
||||||
@ -121,7 +134,7 @@ int main()
|
|||||||
t.remove("horse");
|
t.remove("horse");
|
||||||
t.remove("do");
|
t.remove("do");
|
||||||
t.remove("doge");
|
t.remove("doge");
|
||||||
assert(t.sha256() == hash256({{"dog", "puppy"}}));
|
assert(t.hash256() == hash256({{"dog", "puppy"}}));
|
||||||
assert(t.at("dog") == "puppy");
|
assert(t.at("dog") == "puppy");
|
||||||
t.remove("dog");
|
t.remove("dog");
|
||||||
|
|
||||||
@ -134,14 +147,14 @@ int main()
|
|||||||
auto v = toString(i);
|
auto v = toString(i);
|
||||||
m.insert(make_pair(k, v));
|
m.insert(make_pair(k, v));
|
||||||
t.insert(k, v);
|
t.insert(k, v);
|
||||||
assert(hash256(m) == t.sha256());
|
assert(hash256(m) == t.hash256());
|
||||||
}
|
}
|
||||||
while (!m.empty())
|
while (!m.empty())
|
||||||
{
|
{
|
||||||
auto k = m.begin()->first;
|
auto k = m.begin()->first;
|
||||||
t.remove(k);
|
t.remove(k);
|
||||||
m.erase(k);
|
m.erase(k);
|
||||||
assert(hash256(m) == t.sha256());
|
assert(hash256(m) == t.hash256());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user