Browse Source

Merge remote-tracking branch 'upstream/develop' into stateTests

Conflicts:
	test/vm.cpp
	test/vmArithmeticTestFiller.json
	test/vmSha3TestFiller.json
cl-refactor
Christoph Jentzsch 10 years ago
parent
commit
4b87ee7027
  1. 4
      alethzero/MainWin.cpp
  2. 2
      libdevcore/Common.cpp
  3. 1
      libdevcore/Exceptions.h
  4. 144
      libdevcrypto/Common.cpp
  5. 31
      libdevcrypto/Common.h
  6. 47
      libdevcrypto/CryptoPP.cpp
  7. 42
      libdevcrypto/CryptoPP.h
  8. 168
      libdevcrypto/EC.cpp
  9. 23
      libdevcrypto/EC.h
  10. 1
      libdevcrypto/FileSystem.h
  11. 3
      libdevcrypto/SHA3MAC.cpp
  12. 4
      libethcore/CommonEth.cpp
  13. 9
      libethereum/Executive.cpp
  14. 34
      libethereum/State.cpp
  15. 10
      libethereum/Transaction.cpp
  16. 98
      libethereum/Transaction.h
  17. 14
      libserpent/bignum.cpp
  18. 12
      libserpent/bignum.h
  19. 212
      libserpent/compiler.cpp
  20. 224
      libserpent/opcodes.h
  21. 53
      libserpent/parser.cpp
  22. 870
      libserpent/rewriter.cpp
  23. 2
      libserpent/tokenize.cpp
  24. 22
      libserpent/util.cpp
  25. 6
      libserpent/util.h
  26. 1
      libwhisper/Message.h
  27. 317
      test/crypto.cpp
  28. 804
      test/vmArithmeticTestFiller.json
  29. 932
      test/vmBitwiseLogicOperationTestFiller.json
  30. 80
      test/vmIOandFlowOperationsTestFiller.json
  31. 134
      test/vmPushDupSwapTestFiller.json
  32. 12
      test/vmSha3TestFiller.json

4
alethzero/MainWin.cpp

@ -946,7 +946,7 @@ static bool blockMatch(string const& _f, dev::eth::BlockDetails const& _b, h256
static bool transactionMatch(string const& _f, Transaction const& _t) static bool transactionMatch(string const& _f, Transaction const& _t)
{ {
string info = toHex(_t.receiveAddress().ref()) + " " + toHex(_t.sha3(true).ref()) + " " + toHex(_t.sha3(false).ref()) + " " + toHex(_t.sender().ref()); string info = toHex(_t.receiveAddress().ref()) + " " + toHex(_t.sha3().ref()) + " " + toHex(_t.sha3(eth::WithoutSignature).ref()) + " " + toHex(_t.sender().ref());
if (info.find(_f) != string::npos) if (info.find(_f) != string::npos)
return true; return true;
return false; return false;
@ -1266,7 +1266,7 @@ void Main::on_blocks_currentItemChanged()
s << "<br/>V: <b>" << hex << nouppercase << (int)tx.signature().v << "</b>"; s << "<br/>V: <b>" << hex << nouppercase << (int)tx.signature().v << "</b>";
s << "<br/>R: <b>" << hex << nouppercase << tx.signature().r << "</b>"; s << "<br/>R: <b>" << hex << nouppercase << tx.signature().r << "</b>";
s << "<br/>S: <b>" << hex << nouppercase << tx.signature().s << "</b>"; s << "<br/>S: <b>" << hex << nouppercase << tx.signature().s << "</b>";
s << "<br/>Msg: <b>" << tx.sha3(false) << "</b>"; s << "<br/>Msg: <b>" << tx.sha3(eth::WithoutSignature) << "</b>";
if (tx.isCreation()) if (tx.isCreation())
{ {
if (tx.data().size()) if (tx.data().size())

2
libdevcore/Common.cpp

@ -27,7 +27,7 @@ using namespace dev;
namespace dev namespace dev
{ {
char const* Version = "0.7.8"; char const* Version = "0.7.9";
} }

1
libdevcore/Exceptions.h

@ -24,7 +24,6 @@
#include <exception> #include <exception>
#include <boost/exception/all.hpp> #include <boost/exception/all.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <libdevcrypto/Common.h>
#include "CommonData.h" #include "CommonData.h"
#include "FixedHash.h" #include "FixedHash.h"

144
libdevcrypto/Common.cpp

@ -14,53 +14,33 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonEth.cpp /** @file Common.cpp
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @author Alex Leverington <nessence@gmail.com>
* @date 2014 * @date 2014
*/ */
#include "Common.h"
#include <random> #include <random>
#include <secp256k1/secp256k1.h> #include <mutex>
#include "EC.h" #include "EC.h"
#include "SHA3.h" #include "SHA3.h"
#include "FileSystem.h"
#include "Common.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace crypto;
//#define ETH_ADDRESS_DEBUG 1 //#define ETH_ADDRESS_DEBUG 1
Address dev::toAddress(Secret _private) Address dev::toAddress(Secret _secret)
{ {
secp256k1_start(); return KeyPair(_secret).address();
byte pubkey[65];
int pubkeylen = 65;
int ok = secp256k1_ecdsa_seckey_verify(_private.data());
if (!ok)
return Address();
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, _private.data(), 0);
if (asserts(pubkeylen == 65))
return Address();
if (!ok)
return Address();
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65);
if (!ok)
return Address();
auto ret = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64)));
#if ETH_ADDRESS_DEBUG
cout << "---- ADDRESS -------------------------------" << endl;
cout << "SEC: " << _private << endl;
cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl;
cout << "ADR: " << ret << endl;
#endif
return ret;
} }
KeyPair KeyPair::create() KeyPair KeyPair::create()
{ {
secp256k1_start(); static mt19937_64 s_eng(time(0));
static std::mt19937_64 s_eng(time(0)); uniform_int_distribution<uint16_t> d(0, 255);
std::uniform_int_distribution<uint16_t> d(0, 255);
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
@ -78,24 +58,10 @@ KeyPair KeyPair::create()
KeyPair::KeyPair(h256 _sec): KeyPair::KeyPair(h256 _sec):
m_secret(_sec) m_secret(_sec)
{ {
int ok = secp256k1_ecdsa_seckey_verify(m_secret.data()); toPublic(m_secret, m_public);
if (!ok) if (verifySecret(m_secret, m_public))
return; m_address = right160(dev::sha3(m_public.ref()));
byte pubkey[65];
int pubkeylen = 65;
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, m_secret.data(), 0);
if (!ok || pubkeylen != 65)
return;
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65);
if (!ok)
return;
m_secret = m_secret;
memcpy(m_public.data(), &(pubkey[1]), 64);
m_address = right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64)));
#if ETH_ADDRESS_DEBUG #if ETH_ADDRESS_DEBUG
cout << "---- ADDRESS -------------------------------" << endl; cout << "---- ADDRESS -------------------------------" << endl;
cout << "SEC: " << m_secret << endl; cout << "SEC: " << m_secret << endl;
@ -128,51 +94,55 @@ bool dev::decrypt(Secret _k, bytesConstRef _cipher, bytes& o_plaintext)
Public dev::recover(Signature _sig, h256 _message) Public dev::recover(Signature _sig, h256 _message)
{ {
secp256k1_start(); return crypto::recover(_sig, _message.ref());
byte pubkey[65];
int pubkeylen = 65;
if (!secp256k1_ecdsa_recover_compact(_message.data(), 32, _sig.data(), pubkey, &pubkeylen, 0, (int)_sig[64]))
return Public();
// right160(dev::sha3(bytesConstRef(&(pubkey[1]), 64)));
#if ETH_CRYPTO_TRACE
h256* sig = (h256 const*)_sig.data();
cout << "---- RECOVER -------------------------------" << endl;
cout << "MSG: " << _message << endl;
cout << "R S V: " << sig[0] << " " << sig[1] << " " << (int)(_sig[64] - 27) << "+27" << endl;
cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl;
#endif
Public ret;
memcpy(&ret, &(pubkey[1]), sizeof(Public));
return ret;
} }
inline h256 kFromMessage(h256 _msg, h256 _priv) Signature dev::sign(Secret _k, h256 _hash)
{ {
return _msg ^ _priv; return crypto::sign(_k, _hash);
} }
Signature dev::sign(Secret _k, h256 _message) bool dev::verify(Public _p, Signature _s, h256 _hash)
{ {
int v = 0; return crypto::verify(_p, _s, bytesConstRef(_hash.data(), 32), true);
}
secp256k1_start();
SignatureStruct ret;
h256 nonce = kFromMessage(_message, _k);
if (!secp256k1_ecdsa_sign_compact(_message.data(), 32, ret.r.data(), _k.data(), nonce.data(), &v)) h256 Nonce::get(bool _commit)
return Signature(); {
#if ETH_ADDRESS_DEBUG // todo: atomic efface bit, periodic save, kdf, rr, rng
cout << "---- SIGN -------------------------------" << endl; // todo: encrypt
cout << "MSG: " << _message << endl; static h256 s_seed;
cout << "SEC: " << _k << endl; static string s_seedFile(getDataDir() + "/seed");
cout << "NON: " << nonce << endl; static mutex s_x;
cout << "R S V: " << ret.r << " " << ret.s << " " << v << "+27" << endl; lock_guard<mutex> l(s_x);
#endif if (!s_seed)
{
static Nonce s_nonce;
bytes b = contents(s_seedFile);
if (b.size() == 32)
memcpy(s_seed.data(), b.data(), 32);
else
{
// todo: replace w/entropy from user and system
std::mt19937_64 s_eng(time(0));
std::uniform_int_distribution<uint16_t> d(0, 255);
for (unsigned i = 0; i < 32; ++i)
s_seed[i] = (byte)d(s_eng);
}
if (!s_seed)
BOOST_THROW_EXCEPTION(InvalidState());
// prevent seed reuse if process terminates abnormally
writeFile(s_seedFile, bytes());
}
h256 prev(s_seed);
sha3(prev.ref(), s_seed.ref());
if (_commit)
writeFile(s_seedFile, s_seed.asBytes());
return std::move(s_seed);
}
ret.v = v; Nonce::~Nonce()
return *(Signature const*)&ret; {
Nonce::get(true);
} }

31
libdevcrypto/Common.h

@ -14,8 +14,9 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonEth.h /** @file Common.h
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @author Alex Leverington <nessence@gmail.com>
* @date 2014 * @date 2014
* *
* Ethereum-specific data structures & algorithms. * Ethereum-specific data structures & algorithms.
@ -25,6 +26,7 @@
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/FixedHash.h> #include <libdevcore/FixedHash.h>
#include <libdevcore/Exceptions.h>
namespace dev namespace dev
{ {
@ -62,15 +64,18 @@ Address toAddress(Secret _secret);
/// Encrypts plain text using Public key. /// Encrypts plain text using Public key.
void encrypt(Public _k, bytesConstRef _plain, bytes& o_cipher); void encrypt(Public _k, bytesConstRef _plain, bytes& o_cipher);
/// Decrypts cipher using Secret key. /// Decrypts cipher using Secret key.
bool decrypt(Secret _k, bytesConstRef _cipher, bytes& o_plaintext); bool decrypt(Secret _k, bytesConstRef _cipher, bytes& o_plaintext);
/// Recovers Public key from signed message. /// Recovers Public key from signed message hash.
Public recover(Signature _sig, h256 _message); Public recover(Signature _sig, h256 _hash);
/// Returns siganture of message hash. /// Returns siganture of message hash.
Signature sign(Secret _k, h256 _message); Signature sign(Secret _k, h256 _hash);
/// Verify signature.
bool verify(Public _k, Signature _s, h256 _hash);
/// Simple class that represents a "key pair". /// Simple class that represents a "key pair".
/// All of the data of the class can be regenerated from the secret key (m_secret) alone. /// All of the data of the class can be regenerated from the secret key (m_secret) alone.
@ -110,4 +115,20 @@ private:
Address m_address; Address m_address;
}; };
namespace crypto
{
struct InvalidState: public dev::Exception {};
/**
* @brief Generator for nonce material
*/
struct Nonce
{
static h256 get(bool _commit = false);
private:
Nonce() {}
~Nonce();
};
}
} }

47
libdevcrypto/CryptoPP.cpp

@ -25,50 +25,21 @@ using namespace dev;
using namespace dev::crypto; using namespace dev::crypto;
using namespace CryptoPP; using namespace CryptoPP;
ECP::Point pp::PointFromPublic(Public const& _p)
{
ECP::Point p;
CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> pub;
pub.AccessGroupParameters().Initialize(pp::secp256k1());
bytes prefixedKey(pub.GetGroupParameters().GetEncodedElementSize(true));
prefixedKey[0] = 0x04;
assert(Public::size == prefixedKey.size() - 1);
memcpy(&prefixedKey[1], _p.data(), prefixedKey.size() - 1);
pub.GetGroupParameters().GetCurve().DecodePoint(p, prefixedKey.data(), prefixedKey.size());
return std::move(p);
}
Integer pp::ExponentFromSecret(Secret const& _s) /// Integer and Point Conversion:
{
static_assert(Secret::size == 32, "Secret key must be 32 bytes.");
return std::move(Integer(_s.data(), Secret::size));
}
void pp::PublicFromExponent(Integer const& _e, Public& _p) void pp::exportPublicKey(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const& _k, Public& _p)
{
CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP> k;
k.AccessGroupParameters().Initialize(secp256k1());
k.SetPrivateExponent(_e);
CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> p;
p.AccessGroupParameters().Initialize(secp256k1());
k.MakePublicKey(p);
pp::PublicFromDL_PublicKey_EC(p, _p);
}
void pp::PublicFromDL_PublicKey_EC(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const& _k, Public& _p)
{ {
bytes prefixedKey(_k.GetGroupParameters().GetEncodedElementSize(true)); bytes prefixedKey(_k.GetGroupParameters().GetEncodedElementSize(true));
_k.GetGroupParameters().GetCurve().EncodePoint(prefixedKey.data(), _k.GetPublicElement(), false); secp256k1Params.GetCurve().EncodePoint(prefixedKey.data(), _k.GetPublicElement(), false);
static_assert(Public::size == 64, "Public key must be 64 bytes.");
assert(Public::size + 1 == _k.GetGroupParameters().GetEncodedElementSize(true)); assert(Public::size + 1 == _k.GetGroupParameters().GetEncodedElementSize(true));
memcpy(_p.data(), &prefixedKey[1], Public::size); memcpy(_p.data(), &prefixedKey[1], Public::size);
} }
void pp::SecretFromDL_PrivateKey_EC(CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP> const& _k, Secret& _s) void pp::exponentToPublic(Integer const& _e, Public& _p)
{ {
_k.GetPrivateExponent().Encode(_s.data(), Secret::size); CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> pk;
} pk.Initialize(secp256k1Params, secp256k1Params.ExponentiateBase(_e));
pp::exportPublicKey(pk, _p);
}

42
libdevcrypto/CryptoPP.h

@ -18,7 +18,7 @@
* @author Alex Leverington <nessence@gmail.com> * @author Alex Leverington <nessence@gmail.com>
* @date 2014 * @date 2014
* *
* CryptoPP headers and helper methods * CryptoPP headers and primitive helper methods
*/ */
#pragma once #pragma once
@ -45,7 +45,7 @@
#include <files.h> #include <files.h>
#include <osrng.h> #include <osrng.h>
#include <oids.h> #include <oids.h>
#include <secp256k1/secp256k1.h> #include <dsa.h>
#pragma warning(pop) #pragma warning(pop)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "Common.h" #include "Common.h"
@ -54,30 +54,34 @@ namespace dev
{ {
namespace crypto namespace crypto
{ {
namespace pp namespace pp
{ {
using namespace CryptoPP;
/// CryptoPP random number pool
static CryptoPP::AutoSeededRandomPool PRNG;
/// CryptoPP EC Cruve
static const CryptoPP::OID secp256k1Curve = CryptoPP::ASN1::secp256k1();
static const CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> secp256k1Params(secp256k1Curve);
static ECP::Point publicToPoint(Public const& _p) { Integer x(_p.data(), 32); Integer y(_p.data() + 32, 32); return std::move(ECP::Point(x,y)); }
static Integer secretToExponent(Secret const& _s) { return std::move(Integer(_s.data(), Secret::size)); }
/// RNG used by CryptoPP void exportPublicKey(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const& _k, Public& _p);
inline CryptoPP::AutoSeededRandomPool& PRNG() { static CryptoPP::AutoSeededRandomPool prng; return prng; }
/// EC curve used by CryptoPP
inline CryptoPP::OID const& secp256k1() { static CryptoPP::OID curve = CryptoPP::ASN1::secp256k1(); return curve; }
/// Conversion from bytes to cryptopp point
CryptoPP::ECP::Point PointFromPublic(Public const& _p);
/// Conversion from bytes to cryptopp exponent static void exportPrivateKey(CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP> const& _k, Secret& _s) { _k.GetPrivateExponent().Encode(_s.data(), Secret::size); }
CryptoPP::Integer ExponentFromSecret(Secret const& _s);
/// Conversion from cryptopp exponent Integer to bytes void exponentToPublic(Integer const& _e, Public& _p);
void PublicFromExponent(CryptoPP::Integer const& _k, Public& _s);
/// Conversion from cryptopp public key to bytes template <class T>
void PublicFromDL_PublicKey_EC(CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> const& _k, Public& _p); void initializeDLScheme(Secret const& _s, T& io_operator) { io_operator.AccessKey().Initialize(pp::secp256k1Params, secretToExponent(_s)); }
/// Conversion from cryptopp private key to bytes template <class T>
void SecretFromDL_PrivateKey_EC(CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP> const& _k, Secret& _s); void initializeDLScheme(Public const& _p, T& io_operator) { io_operator.AccessKey().Initialize(pp::secp256k1Params, publicToPoint(_p)); }
} }
} }

168
libdevcrypto/EC.cpp

@ -18,54 +18,65 @@
* @author Alex Leverington <nessence@gmail.com> * @author Alex Leverington <nessence@gmail.com>
* @date 2014 * @date 2014
* *
* Shared EC classes and functions. * ECDSA, ECIES
*/ */
#pragma warning(push) #include <secp256k1/secp256k1.h>
#pragma warning(disable:4100 4244)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
#pragma GCC diagnostic ignored "-Wextra"
#include <files.h>
#pragma warning(pop)
#pragma GCC diagnostic pop
#include "CryptoPP.h" #include "CryptoPP.h"
#include "SHA3.h" #include "SHA3.h"
#include "SHA3MAC.h"
#include "EC.h" #include "EC.h"
// CryptoPP and dev conflict so dev and pp namespace are used explicitly static_assert(dev::Secret::size == 32, "Secret key must be 32 bytes.");
static_assert(dev::Public::size == 64, "Public key must be 64 bytes.");
static_assert(dev::Signature::size == 65, "Signature must be 65 bytes.");
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::crypto; using namespace dev::crypto;
using namespace CryptoPP; using namespace CryptoPP;
using namespace pp;
void crypto::toPublic(Secret const& _s, Public& o_public)
{
exponentToPublic(Integer(_s.data(), sizeof(_s)), o_public);
}
void dev::crypto::encrypt(Public const& _key, bytes& io_cipher) h256 crypto::kdf(Secret const& _priv, h256 const& _hash)
{
// H(H(r||k)^h)
h256 s;
sha3mac(Nonce::get().ref(), _priv.ref(), s.ref());
s ^= _hash;
sha3(s.ref(), s.ref());
if (!s || !_hash || !_priv)
BOOST_THROW_EXCEPTION(InvalidState());
return std::move(s);
}
void crypto::encrypt(Public const& _k, bytes& io_cipher)
{ {
ECIES<ECP>::Encryptor e; ECIES<ECP>::Encryptor e;
e.AccessKey().AccessGroupParameters().Initialize(pp::secp256k1()); initializeDLScheme(_k, e);
e.AccessKey().SetPublicElement(pp::PointFromPublic(_key));
size_t plen = io_cipher.size(); size_t plen = io_cipher.size();
bytes c; bytes c;
c.resize(e.CiphertextLength(plen)); c.resize(e.CiphertextLength(plen));
// todo: use StringSource with _plain as input and output. // todo: use StringSource with io_cipher as input and output.
e.Encrypt(pp::PRNG(), io_cipher.data(), plen, c.data()); e.Encrypt(PRNG, io_cipher.data(), plen, c.data());
memset(io_cipher.data(), 0, io_cipher.size()); memset(io_cipher.data(), 0, io_cipher.size());
io_cipher = std::move(c); io_cipher = std::move(c);
} }
void dev::crypto::decrypt(Secret const& _k, bytes& io_text) void crypto::decrypt(Secret const& _k, bytes& io_text)
{ {
CryptoPP::ECIES<CryptoPP::ECP>::Decryptor d; CryptoPP::ECIES<CryptoPP::ECP>::Decryptor d;
d.AccessKey().AccessGroupParameters().Initialize(pp::secp256k1()); initializeDLScheme(_k, d);
d.AccessKey().SetPrivateExponent(pp::ExponentFromSecret(_k));
size_t clen = io_text.size(); size_t clen = io_text.size();
bytes p; bytes p;
p.resize(d.MaxPlaintextLength(io_text.size())); p.resize(d.MaxPlaintextLength(io_text.size()));
// todo: use StringSource with _c as input and output. // todo: use StringSource with io_text as input and output.
DecodingResult r = d.Decrypt(pp::PRNG(), io_text.data(), clen, p.data()); DecodingResult r = d.Decrypt(PRNG, io_text.data(), clen, p.data());
if (!r.isValidCoding) if (!r.isValidCoding)
{ {
io_text.clear(); io_text.clear();
@ -75,3 +86,114 @@ void dev::crypto::decrypt(Secret const& _k, bytes& io_text)
io_text = std::move(p); io_text = std::move(p);
} }
Signature crypto::sign(Secret const& _k, bytesConstRef _message)
{
return crypto::sign(_k, sha3(_message));
}
Signature crypto::sign(Secret const& _key, h256 const& _hash)
{
ECDSA<ECP,SHA3_256>::Signer signer;
initializeDLScheme(_key, signer);
Integer const& q = secp256k1Params.GetGroupOrder();
Integer const& qs = secp256k1Params.GetSubgroupOrder();
Integer e(_hash.asBytes().data(), 32);
Integer k(kdf(_key, _hash).data(), 32);
if (k == 0)
BOOST_THROW_EXCEPTION(InvalidState());
k = 1 + (k % (qs - 1));
ECP::Point rp = secp256k1Params.ExponentiateBase(k);
Integer r = secp256k1Params.ConvertElementToInteger(rp);
int recid = ((r >= q) ? 2 : 0) | (rp.y.IsOdd() ? 1 : 0);
Integer kInv = k.InverseMod(q);
Integer s = (kInv * (Integer(_key.asBytes().data(), 32)*r + e)) % q;
assert(!!r && !!s);
if (s > qs)
{
s = q - s;
if (recid)
recid ^= 1;
}
Signature sig;
r.Encode(sig.data(), 32);
s.Encode(sig.data() + 32, 32);
sig[64] = recid;
return sig;
}
bool crypto::verify(Signature const& _signature, bytesConstRef _message)
{
return crypto::verify(crypto::recover(_signature, _message), _signature, _message);
}
bool crypto::verify(Public const& _p, Signature const& _sig, bytesConstRef _message, bool _hashed)
{
static size_t derMaxEncodingLength = 72;
if (_hashed)
{
assert(_message.size() == 32);
byte encpub[65] = {0x04};
memcpy(&encpub[1], _p.data(), 64);
byte dersig[derMaxEncodingLength];
size_t cssz = DSAConvertSignatureFormat(dersig, derMaxEncodingLength, DSA_DER, _sig.data(), 64, DSA_P1363);
assert(cssz <= derMaxEncodingLength);
return (1 == secp256k1_ecdsa_verify(_message.data(), _message.size(), dersig, cssz, encpub, 65));
}
ECDSA<ECP, SHA3_256>::Verifier verifier;
initializeDLScheme(_p, verifier);
return verifier.VerifyMessage(_message.data(), _message.size(), _sig.data(), sizeof(Signature) - 1);
}
Public crypto::recover(Signature _signature, bytesConstRef _message)
{
secp256k1_start();
int pubkeylen = 65;
byte pubkey[pubkeylen];
if (!secp256k1_ecdsa_recover_compact(_message.data(), 32, _signature.data(), pubkey, &pubkeylen, 0, (int)_signature[64]))
return Public();
#if ETH_CRYPTO_TRACE
h256* sig = (h256 const*)_signature.data();
cout << "---- RECOVER -------------------------------" << endl;
cout << "MSG: " << _message << endl;
cout << "R S V: " << sig[0] << " " << sig[1] << " " << (int)(_signature[64] - 27) << "+27" << endl;
cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl;
#endif
Public ret;
memcpy(&ret, &(pubkey[1]), sizeof(Public));
return ret;
}
bool crypto::verifySecret(Secret const& _s, Public const& _p)
{
secp256k1_start();
int ok = secp256k1_ecdsa_seckey_verify(_s.data());
if (!ok)
return false;
int pubkeylen = 65;
byte pubkey[pubkeylen];
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, _s.data(), 0);
if (!ok || pubkeylen != 65)
return false;
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65);
if (!ok)
return false;
for (int i = 0; i < 32; i++)
if (pubkey[i+1]!=_p[i])
return false;
return true;
}

23
libdevcrypto/EC.h

@ -18,7 +18,7 @@
* @author Alex Leverington <nessence@gmail.com> * @author Alex Leverington <nessence@gmail.com>
* @date 2014 * @date 2014
* *
* Shared EC classes and functions. * ECDSA, ECIES
*/ */
#pragma once #pragma once
@ -30,12 +30,33 @@ namespace dev
namespace crypto namespace crypto
{ {
void toPublic(Secret const& _s, Public& o_public);
h256 kdf(Secret const& _priv, h256 const& _hash);
/// Encrypts text (in place). /// Encrypts text (in place).
void encrypt(Public const& _k, bytes& io_cipher); void encrypt(Public const& _k, bytes& io_cipher);
/// Decrypts text (in place). /// Decrypts text (in place).
void decrypt(Secret const& _k, bytes& io_text); void decrypt(Secret const& _k, bytes& io_text);
/// Returns siganture of message.
Signature sign(Secret const& _k, bytesConstRef _message);
/// Returns compact siganture of message hash.
Signature sign(Secret const& _k, h256 const& _hash);
/// Verify compact signature (public key is extracted from message).
bool verify(Signature const& _signature, bytesConstRef _message);
/// Verify signature.
bool verify(Public const& _p, Signature const& _sig, bytesConstRef _message, bool _hashed = false);
/// Recovers public key from compact signature. Uses libsecp256k1.
Public recover(Signature _signature, bytesConstRef _message);
bool verifySecret(Secret const& _s, Public const& _p);
} }
} }

1
libdevcrypto/FileSystem.h

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <libdevcore/CommonIO.h>
namespace dev namespace dev
{ {

3
libdevcrypto/SHA3MAC.cpp

@ -28,9 +28,10 @@ using namespace dev;
using namespace dev::crypto; using namespace dev::crypto;
using namespace CryptoPP; using namespace CryptoPP;
void sha3mac(bytesConstRef _secret, bytesConstRef _plain, bytesRef _output) void crypto::sha3mac(bytesConstRef _secret, bytesConstRef _plain, bytesRef _output)
{ {
CryptoPP::SHA3_256 ctx; CryptoPP::SHA3_256 ctx;
assert(_secret.size() > 0);
ctx.Update((byte*)_secret.data(), _secret.size()); ctx.Update((byte*)_secret.data(), _secret.size());
ctx.Update((byte*)_plain.data(), _plain.size()); ctx.Update((byte*)_plain.data(), _plain.size());
assert(_output.size() >= 32); assert(_output.size() >= 32);

4
libethcore/CommonEth.cpp

@ -34,8 +34,8 @@ namespace dev
namespace eth namespace eth
{ {
const unsigned c_protocolVersion = 38; const unsigned c_protocolVersion = 39;
const unsigned c_databaseVersion = 3; const unsigned c_databaseVersion = 4;
static const vector<pair<u256, string>> g_units = static const vector<pair<u256, string>> g_units =
{ {

9
libethereum/Executive.cpp

@ -184,15 +184,10 @@ bool Executive::go(OnOpFunc const& _onOp)
{ {
return false; return false;
} }
catch (OutOfGas const& /*_e*/)
{
clog(StateChat) << "Out of Gas! Reverting.";
revert = true;
}
catch (VMException const& _e) catch (VMException const& _e)
{ {
clog(StateChat) << "VM Exception: " << diagnostic_information(_e); clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
m_endGas = m_vm->gas(); m_endGas = 0;//m_vm->gas();
revert = true; revert = true;
} }
catch (Exception const& _e) catch (Exception const& _e)

34
libethereum/State.cpp

@ -1126,7 +1126,7 @@ u256 State::execute(bytesConstRef _rlp, bytes* o_output, bool _commit)
#if ETH_PARANOIA #if ETH_PARANOIA
ctrace << "Executing" << e.t() << "on" << h; ctrace << "Executing" << e.t() << "on" << h;
ctrace << toHex(e.t().rlp(true)); ctrace << toHex(e.t().rlp());
#endif #endif
e.go(e.simpleTrace()); e.go(e.simpleTrace());
@ -1213,32 +1213,29 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
*o_sub += evm.sub; *o_sub += evm.sub;
if (o_ms) if (o_ms)
o_ms->output = out.toBytes(); o_ms->output = out.toBytes();
} *_gas = vm.gas();
catch (OutOfGas const& /*_e*/)
{
clog(StateChat) << "Out of Gas! Reverting.";
revert = true;
} }
catch (VMException const& _e) catch (VMException const& _e)
{ {
clog(StateChat) << "VM Exception: " << diagnostic_information(_e); clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
revert = true; revert = true;
*_gas = 0;
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
clog(StateChat) << "Exception in VM: " << diagnostic_information(_e); cwarn << "Unexpected exception in VM: " << diagnostic_information(_e) << ". This is exceptionally bad.";
// TODO: use fallback known-safe VM.
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
clog(StateChat) << "std::exception in VM: " << _e.what(); cwarn << "Unexpected exception in VM: " << _e.what() << ". This is exceptionally bad.";
// TODO: use fallback known-safe VM.
} }
// Write state out only in the case of a non-excepted transaction. // Write state out only in the case of a non-excepted transaction.
if (revert) if (revert)
evm.revert(); evm.revert();
*_gas = vm.gas();
return !revert; return !revert;
} }
else else
@ -1281,16 +1278,13 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
o_ms->output = out.toBytes(); o_ms->output = out.toBytes();
if (o_sub) if (o_sub)
*o_sub += evm.sub; *o_sub += evm.sub;
} *_gas = vm.gas();
catch (OutOfGas const& /*_e*/)
{
clog(StateChat) << "Out of Gas! Reverting.";
revert = true;
} }
catch (VMException const& _e) catch (VMException const& _e)
{ {
clog(StateChat) << "VM Exception: " << diagnostic_information(_e); clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
revert = true; revert = true;
*_gas = 0;
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
@ -1317,8 +1311,6 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
if (addressInUse(newAddress)) if (addressInUse(newAddress))
m_cache[newAddress].setCode(out); m_cache[newAddress].setCode(out);
*_gas = vm.gas();
return newAddress; return newAddress;
} }
@ -1380,7 +1372,7 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s)
stringstream contout; stringstream contout;
if ((cache && cache->codeBearing()) || (!cache && r && !r[3].isEmpty())) if ((cache && cache->codeBearing()) || (!cache && r && (h256)r[3] != EmptySHA3))
{ {
std::map<u256, u256> mem; std::map<u256, u256> mem;
std::set<u256> back; std::set<u256> back;
@ -1409,7 +1401,7 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s)
else else
contout << r[2].toHash<h256>(); contout << r[2].toHash<h256>();
if (cache && cache->isFreshCode()) if (cache && cache->isFreshCode())
contout << " $" << cache->code(); contout << " $" << toHex(cache->code());
else else
contout << " $" << (cache ? cache->codeHash() : r[3].toHash<h256>()); contout << " $" << (cache ? cache->codeHash() : r[3].toHash<h256>());

10
libethereum/Transaction.cpp

@ -47,7 +47,7 @@ Transaction::Transaction(bytesConstRef _rlpData, bool _checkSender)
if (_checkSender) if (_checkSender)
m_sender = sender(); m_sender = sender();
} }
catch (Exception & _e) catch (Exception& _e)
{ {
_e << errinfo_name("invalid transaction format") << BadFieldError(field,toHex(rlp[field].data().toBytes())); _e << errinfo_name("invalid transaction format") << BadFieldError(field,toHex(rlp[field].data().toBytes()));
throw; throw;
@ -71,7 +71,7 @@ Address Transaction::sender() const
{ {
if (!m_sender) if (!m_sender)
{ {
auto p = recover(*(Signature const*)&m_vrs, sha3(false)); auto p = recover(*(Signature const*)&m_vrs, sha3(WithoutSignature));
if (!p) if (!p)
BOOST_THROW_EXCEPTION(InvalidSignature()); BOOST_THROW_EXCEPTION(InvalidSignature());
m_sender = right160(dev::sha3(bytesConstRef(p.data(), sizeof(p)))); m_sender = right160(dev::sha3(bytesConstRef(p.data(), sizeof(p))));
@ -81,12 +81,14 @@ Address Transaction::sender() const
void Transaction::sign(Secret _priv) void Transaction::sign(Secret _priv)
{ {
auto sig = dev::sign(_priv, sha3(false)); auto sig = dev::sign(_priv, sha3(WithoutSignature));
m_vrs = *(SignatureStruct const*)&sig; m_vrs = *(SignatureStruct const*)&sig;
} }
void Transaction::streamRLP(RLPStream& _s, bool _sig) const void Transaction::streamRLP(RLPStream& _s, IncludeSignature _sig) const
{ {
if (m_type == NullTransaction)
return;
_s.appendList((_sig ? 3 : 0) + 6); _s.appendList((_sig ? 3 : 0) + 6);
_s << m_nonce << m_gasPrice << m_gas; _s << m_nonce << m_gasPrice << m_gas;
if (m_type == MessageCall) if (m_type == MessageCall)

98
libethereum/Transaction.h

@ -30,52 +30,104 @@ namespace dev
namespace eth namespace eth
{ {
/// Named-boolean type to encode whether a signature be included in the serialisation process.
enum IncludeSignature
{
WithoutSignature = 0, ///< Do not include a signature.
WithSignature = 1, ///< Do include a signature.
};
/// Encodes a transaction, ready to be exported to or freshly imported from RLP.
class Transaction class Transaction
{ {
public: public:
enum Type /// Constructs a null transaction.
{
NullTransaction,
ContractCreation,
MessageCall
};
Transaction() {} Transaction() {}
/// Constructs a signed message-call transaction.
Transaction(u256 _value, u256 _gasPrice, u256 _gas, Address const& _dest, bytes const& _data, u256 _nonce, Secret const& _secret): m_type(MessageCall), m_nonce(_nonce), m_value(_value), m_receiveAddress(_dest), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) { sign(_secret); } Transaction(u256 _value, u256 _gasPrice, u256 _gas, Address const& _dest, bytes const& _data, u256 _nonce, Secret const& _secret): m_type(MessageCall), m_nonce(_nonce), m_value(_value), m_receiveAddress(_dest), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) { sign(_secret); }
/// Constructs a signed contract-creation transaction.
Transaction(u256 _value, u256 _gasPrice, u256 _gas, bytes const& _data, u256 _nonce, Secret const& _secret): m_type(ContractCreation), m_nonce(_nonce), m_value(_value), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) { sign(_secret); } Transaction(u256 _value, u256 _gasPrice, u256 _gas, bytes const& _data, u256 _nonce, Secret const& _secret): m_type(ContractCreation), m_nonce(_nonce), m_value(_value), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) { sign(_secret); }
/// Constructs an unsigned message-call transaction.
Transaction(u256 _value, u256 _gasPrice, u256 _gas, Address const& _dest, bytes const& _data): m_type(MessageCall), m_value(_value), m_receiveAddress(_dest), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) {} Transaction(u256 _value, u256 _gasPrice, u256 _gas, Address const& _dest, bytes const& _data): m_type(MessageCall), m_value(_value), m_receiveAddress(_dest), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) {}
/// Constructs an unsigned contract-creation transaction.
Transaction(u256 _value, u256 _gasPrice, u256 _gas, bytes const& _data): m_type(ContractCreation), m_value(_value), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) {} Transaction(u256 _value, u256 _gasPrice, u256 _gas, bytes const& _data): m_type(ContractCreation), m_value(_value), m_gasPrice(_gasPrice), m_gas(_gas), m_data(_data) {}
Transaction(bytesConstRef _rlp, bool _checkSender = false);
Transaction(bytes const& _rlp, bool _checkSender = false): Transaction(&_rlp, _checkSender) {}
/// Constructs a transaction from the given RLP.
explicit Transaction(bytesConstRef _rlp, bool _checkSender = false);
/// Constructs a transaction from the given RLP.
explicit Transaction(bytes const& _rlp, bool _checkSender = false): Transaction(&_rlp, _checkSender) {}
/// Checks equality of transactions.
bool operator==(Transaction const& _c) const { return m_type == _c.m_type && (m_type == ContractCreation || m_receiveAddress == _c.m_receiveAddress) && m_value == _c.m_value && m_data == _c.m_data; } bool operator==(Transaction const& _c) const { return m_type == _c.m_type && (m_type == ContractCreation || m_receiveAddress == _c.m_receiveAddress) && m_value == _c.m_value && m_data == _c.m_data; }
/// Checks inequality of transactions.
bool operator!=(Transaction const& _c) const { return !operator==(_c); } bool operator!=(Transaction const& _c) const { return !operator==(_c); }
Address safeSender() const noexcept; ///< Like sender() but will never throw. @returns a null Address if the signature is invalid. /// @returns sender of the transaction from the signature (and hash).
Address sender() const; ///< Determine the sender of the transaction from the signature (and hash). Address sender() const;
/// Like sender() but will never throw. @returns a null Address if the signature is invalid.
Address safeSender() const noexcept;
/// @returns true if transaction is non-null.
operator bool() const { return m_type != NullTransaction; }
/// @returns true if transaction is contract-creation.
bool isCreation() const { return m_type == ContractCreation; } bool isCreation() const { return m_type == ContractCreation; }
void streamRLP(RLPStream& _s, bool _sig = true) const; /// @returns true if transaction is message-call.
bool isMessageCall() const { return m_type == MessageCall; }
bytes rlp(bool _sig = true) const { RLPStream s; streamRLP(s, _sig); return s.out(); } /// Serialises this transaction to an RLPStream.
std::string rlpString(bool _sig = true) const { return asString(rlp(_sig)); } void streamRLP(RLPStream& _s, IncludeSignature _sig = WithSignature) const;
h256 sha3(bool _sig = true) const { RLPStream s; streamRLP(s, _sig); return dev::sha3(s.out()); }
bytes sha3Bytes(bool _sig = true) const { RLPStream s; streamRLP(s, _sig); return dev::sha3Bytes(s.out()); }
Type type() const { return m_type; } /// @returns the RLP serialisation of this transaction.
u256 nonce() const { return m_nonce; } bytes rlp(IncludeSignature _sig = WithSignature) const { RLPStream s; streamRLP(s, _sig); return s.out(); }
/// @returns the SHA3 hash of the RLP serialisation of this transaction.
h256 sha3(IncludeSignature _sig = WithSignature) const { RLPStream s; streamRLP(s, _sig); return dev::sha3(s.out()); }
/// @returns the amount of ETH to be transferred by this (message-call) transaction, in Wei. Synonym for endowment().
u256 value() const { return m_value; } u256 value() const { return m_value; }
Address receiveAddress() const { return m_receiveAddress; } /// @returns the amount of ETH to be endowed by this (contract-creation) transaction, in Wei. Synonym for value().
u256 endowment() const { return m_value; }
/// @returns the base fee and thus the implied exchange rate of ETH to GAS.
u256 gasPrice() const { return m_gasPrice; } u256 gasPrice() const { return m_gasPrice; }
/// @returns the total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.
u256 gas() const { return m_gas; } u256 gas() const { return m_gas; }
/// @returns the receiving address of the message-call transaction (undefined for contract-creation transactions).
Address receiveAddress() const { return m_receiveAddress; }
/// @returns the data associated with this (message-call) transaction. Synonym for initCode().
bytes const& data() const { return m_data; } bytes const& data() const { return m_data; }
/// @returns the initialisation code associated with this (contract-creation) transaction. Synonym for data().
bytes const& initCode() const { return m_data; }
/// @returns the transaction-count of the sender.
u256 nonce() const { return m_nonce; }
/// @returns the signature of the transaction. Encodes the sender.
SignatureStruct const& signature() const { return m_vrs; } SignatureStruct const& signature() const { return m_vrs; }
private: private:
void sign(Secret _priv); ///< Sign the transaction. /// Type of transaction.
enum Type
{
NullTransaction, ///< Null transaction.
ContractCreation, ///< Transaction to create contracts - receiveAddress() is ignored.
MessageCall ///< Transaction to invoke a message call - receiveAddress() is used.
};
void sign(Secret _priv); ///< Sign the transaction.
Type m_type = NullTransaction; ///< True if this is a contract-creation transaction. F Type m_type = NullTransaction; ///< Is this a contract-creation transaction or a message-call transaction?
u256 m_nonce; ///< The transaction-count of the sender. u256 m_nonce; ///< The transaction-count of the sender.
u256 m_value; ///< The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions. u256 m_value; ///< The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions.
Address m_receiveAddress; ///< The receiving address of the transaction. Address m_receiveAddress; ///< The receiving address of the transaction.
@ -84,11 +136,13 @@ private:
bytes m_data; ///< The data associated with the transaction, or the initialiser if it's a creation transaction. bytes m_data; ///< The data associated with the transaction, or the initialiser if it's a creation transaction.
SignatureStruct m_vrs; ///< The signature of the transaction. Encodes the sender. SignatureStruct m_vrs; ///< The signature of the transaction. Encodes the sender.
mutable Address m_sender; mutable Address m_sender; ///< Cached sender, determined from signature.
}; };
/// Nice name for vector of Transaction.
using Transactions = std::vector<Transaction>; using Transactions = std::vector<Transaction>;
/// Simple human-readable stream-shift operator.
inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t) inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t)
{ {
_out << "{"; _out << "{";

14
libserpent/bignum.cpp

@ -48,6 +48,20 @@ std::string decimalMul(std::string a, std::string b) {
return o; return o;
} }
//Modexp
std::string decimalModExp(std::string b, std::string e, std::string m) {
if (e == "0") return "1";
else if (e == "1") return b;
else if (decimalMod(e, "2") == "0") {
std::string o = decimalModExp(b, decimalDiv(e, "2"), m);
return decimalMod(decimalMul(o, o), m);
}
else {
std::string o = decimalModExp(b, decimalDiv(e, "2"), m);
return decimalMod(decimalMul(decimalMul(o, o), b), m);
}
}
//Is a greater than b? Flag allows equality //Is a greater than b? Flag allows equality
bool decimalGt(std::string a, std::string b, bool eqAllowed) { bool decimalGt(std::string a, std::string b, bool eqAllowed) {
if (a == b) return eqAllowed; if (a == b) return eqAllowed;

12
libserpent/bignum.h

@ -7,10 +7,16 @@ const std::string tt256 =
"115792089237316195423570985008687907853269984665640564039457584007913129639936" "115792089237316195423570985008687907853269984665640564039457584007913129639936"
; ;
const std::string tt255 = const std::string tt256m1 =
"57896044618658097711785492504343953926634992332820282019728792003956564819968" "115792089237316195423570985008687907853269984665640564039457584007913129639935"
; ;
const std::string tt255 =
"57896044618658097711785492504343953926634992332820282019728792003956564819968";
const std::string tt176 =
"95780971304118053647396689196894323976171195136475136";
std::string unsignedToDecimal(unsigned branch); std::string unsignedToDecimal(unsigned branch);
std::string decimalAdd(std::string a, std::string b); std::string decimalAdd(std::string a, std::string b);
@ -23,6 +29,8 @@ std::string decimalDiv(std::string a, std::string b);
std::string decimalMod(std::string a, std::string b); std::string decimalMod(std::string a, std::string b);
std::string decimalModExp(std::string b, std::string e, std::string m);
bool decimalGt(std::string a, std::string b, bool eqAllowed=false); bool decimalGt(std::string a, std::string b, bool eqAllowed=false);
unsigned decimalToUnsigned(std::string a); unsigned decimalToUnsigned(std::string a);

212
libserpent/compiler.cpp

@ -8,10 +8,18 @@
struct programAux { struct programAux {
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;
int nextVarMem;
bool allocUsed; bool allocUsed;
bool calldataUsed; bool calldataUsed;
int step; int step;
int labelLength; int labelLength;
int functionCount;
};
struct programVerticalAux {
int height;
std::map<std::string, int> dupvars;
std::map<std::string, int> funvars;
}; };
struct programData { struct programData {
@ -25,6 +33,16 @@ programAux Aux() {
o.allocUsed = false; o.allocUsed = false;
o.calldataUsed = false; o.calldataUsed = false;
o.step = 0; o.step = 0;
o.nextVarMem = 32;
o.functionCount = 0;
return o;
}
programVerticalAux verticalAux() {
programVerticalAux o;
o.height = 0;
o.dupvars = std::map<std::string, int>();
o.funvars = std::map<std::string, int>();
return o; return o;
} }
@ -57,28 +75,28 @@ Node popwrap(Node node) {
// Turns LLL tree into tree of code fragments // Turns LLL tree into tree of code fragments
programData opcodeify(Node node, programData opcodeify(Node node,
programAux aux=Aux(), programAux aux=Aux(),
int height=0, programVerticalAux vaux=verticalAux()) {
std::map<std::string, int> dupvars=
std::map<std::string, int>()) {
std::string symb = "_"+mkUniqueToken(); std::string symb = "_"+mkUniqueToken();
Metadata m = node.metadata; Metadata m = node.metadata;
// Numbers // Numbers
if (node.type == TOKEN) { if (node.type == TOKEN) {
return pd(aux, nodeToNumeric(node), 1); return pd(aux, nodeToNumeric(node), 1);
} }
else if (node.val == "ref" || node.val == "get" || node.val == "set") { else if (node.val == "ref" || node.val == "get" ||
node.val == "set" || node.val == "declare") {
std::string varname = node.args[0].val; std::string varname = node.args[0].val;
if (!aux.vars.count(varname)) { if (!aux.vars.count(varname)) {
aux.vars[varname] = unsignedToDecimal(aux.vars.size() * 32); aux.vars[varname] = unsignedToDecimal(aux.nextVarMem);
aux.nextVarMem += 32;
} }
if (varname == "'msg.data") aux.calldataUsed = true; if (varname == "'msg.data") aux.calldataUsed = true;
// Set variable // Set variable
if (node.val == "set") { if (node.val == "set") {
programData sub = opcodeify(node.args[1], aux, height, dupvars); programData sub = opcodeify(node.args[1], aux, vaux);
if (!sub.outs) if (!sub.outs)
err("Value to set variable must have nonzero arity!", m); err("Value to set variable must have nonzero arity!", m);
if (dupvars.count(node.args[0].val)) { if (vaux.dupvars.count(node.args[0].val)) {
int h = height - dupvars[node.args[0].val]; int h = vaux.height - vaux.dupvars[node.args[0].val];
if (h > 16) err("Too deep for stack variable (max 16)", m); if (h > 16) err("Too deep for stack variable (max 16)", m);
Node nodelist[] = { Node nodelist[] = {
sub.code, sub.code,
@ -96,8 +114,8 @@ programData opcodeify(Node node,
} }
// Get variable // Get variable
else if (node.val == "get") { else if (node.val == "get") {
if (dupvars.count(node.args[0].val)) { if (vaux.dupvars.count(node.args[0].val)) {
int h = height - dupvars[node.args[0].val]; int h = vaux.height - vaux.dupvars[node.args[0].val];
if (h > 16) err("Too deep for stack variable (max 16)", m); if (h > 16) err("Too deep for stack variable (max 16)", m);
return pd(aux, token("DUP"+unsignedToDecimal(h)), 1); return pd(aux, token("DUP"+unsignedToDecimal(h)), 1);
} }
@ -106,36 +124,157 @@ programData opcodeify(Node node,
return pd(aux, multiToken(nodelist, 2, m), 1); return pd(aux, multiToken(nodelist, 2, m), 1);
} }
// Refer variable // Refer variable
else { else if (node.val == "ref") {
if (dupvars.count(node.args[0].val)) if (vaux.dupvars.count(node.args[0].val))
err("Cannot ref stack variable!", m); err("Cannot ref stack variable!", m);
return pd(aux, token(aux.vars[varname], m), 1); return pd(aux, token(aux.vars[varname], m), 1);
} }
// Declare variable
else {
Node nodelist[] = { };
return pd(aux, multiToken(nodelist, 0, m), 0);
}
}
// Define functions (TODO: eventually move to rewriter.cpp, keep
// compiler pure LLL)
if (node.val == "def") {
std::vector<std::string> varNames;
std::vector<int> varSizes;
bool useLt32 = false;
int totalSz = 0;
if (node.args.size() != 2)
err("Malformed def!", m);
// Collect the list of variable names and variable byte counts
for (unsigned i = 0; i < node.args[0].args.size(); i++) {
if (node.args[0].args[i].val == "kv") {
if (node.args[0].args[i].args.size() != 2)
err("Malformed def!", m);
varNames.push_back(node.args[0].args[i].args[0].val);
varSizes.push_back(
decimalToUnsigned(node.args[0].args[i].args[1].val));
if (varSizes.back() > 32)
err("Max argument width: 32 bytes", m);
useLt32 = true;
}
else {
varNames.push_back(node.args[0].args[i].val);
varSizes.push_back(32);
}
aux.vars[varNames.back()] = unsignedToDecimal(aux.nextVarMem + 32 * i);
totalSz += varSizes.back();
}
int functionCount = aux.functionCount;
int nextVarMem = aux.nextVarMem;
aux.nextVarMem += 32 * varNames.size();
aux.functionCount += 1;
programData inner;
// If we're only using 32-byte variables, then great, just copy
// over the calldata!
if (!useLt32) {
programData sub = opcodeify(node.args[1], aux, vaux);
Node nodelist[] = {
token(unsignedToDecimal(totalSz), m),
token("1", m),
token(unsignedToDecimal(nextVarMem), m),
token("CALLDATACOPY", m),
sub.code
};
inner = pd(sub.aux, multiToken(nodelist, 5, m), 0);
}
else {
std::vector<Node> innerList;
int cum = 1;
for (unsigned i = 0; i < varNames.size();) {
// If we get a series of 32-byte values, we calldatacopy them
if (varSizes[i] == 32) {
unsigned until = i+1;
while (until < varNames.size() && varSizes[until] == 32)
until += 1;
innerList.push_back(token(unsignedToDecimal((until - i) * 32), m));
innerList.push_back(token(unsignedToDecimal(cum), m));
innerList.push_back(token(unsignedToDecimal(nextVarMem + i * 32), m));
innerList.push_back(token("CALLDATACOPY", m));
cum += (until - i) * 32;
i = until;
}
// Otherwise, we do a clever trick to extract the value
else {
innerList.push_back(token(unsignedToDecimal(32 - varSizes[i]), m));
innerList.push_back(token("256", m));
innerList.push_back(token("EXP", m));
innerList.push_back(token(unsignedToDecimal(cum), m));
innerList.push_back(token("CALLDATALOAD", m));
innerList.push_back(token("DIV", m));
innerList.push_back(token(unsignedToDecimal(nextVarMem + i * 32), m));
innerList.push_back(token("MSTORE", m));
cum += varSizes[i];
i += 1;
}
}
// If caller == origin, then it's from a tx, so unpack, otherwise
// plain copy
programData sub = opcodeify(node.args[1], aux, vaux);
Node ilnode = astnode("", innerList, m);
Node nodelist[] = {
token(unsignedToDecimal(32 * varNames.size()), m),
token("1", m),
token(unsignedToDecimal(nextVarMem), m),
token("CALLDATACOPY", m),
token("CALLER", m),
token("ORIGIN", m),
token("EQ", m),
token("ISZERO", m),
token("$maincode"+symb, m),
token("JUMPI", m),
ilnode,
token("~maincode"+symb, m),
token("JUMPDEST", m),
sub.code
};
inner = pd(sub.aux, multiToken(nodelist, 14, m), 0);
}
// Check if the function call byte is the same
Node nodelist2[] = {
token("0", m),
token("CALLDATALOAD", m),
token("0", m),
token("BYTE", m),
token(unsignedToDecimal(functionCount), m),
token("EQ", m),
token("ISZERO", m),
token("$endcode"+symb, m),
token("JUMPI", m),
inner.code,
token("~endcode"+symb, m),
token("JUMPDEST", m),
};
return pd(inner.aux, multiToken(nodelist2, 12, m), 0);
} }
// Code blocks // Code blocks
if (node.val == "lll" && node.args.size() == 2) { if (node.val == "lll" && node.args.size() == 2) {
if (node.args[1].val != "0") aux.allocUsed = true; if (node.args[1].val != "0") aux.allocUsed = true;
std::vector<Node> o; std::vector<Node> o;
o.push_back(finalize(opcodeify(node.args[0]))); o.push_back(finalize(opcodeify(node.args[0])));
programData sub = opcodeify(node.args[1], aux, height, dupvars); programData sub = opcodeify(node.args[1], aux, vaux);
Node code = astnode("____CODE", o, m); Node code = astnode("____CODE", o, m);
Node nodelist[] = { Node nodelist[] = {
token("$begincode"+symb+".endcode"+symb, m), token("DUP1", m), token("$begincode"+symb+".endcode"+symb, m), token("DUP1", m),
token("$begincode"+symb, m), sub.code, token("CODECOPY", m), token("$begincode"+symb, m), sub.code, token("CODECOPY", m),
token("$endcode"+symb, m), token("JUMP", m), token("$endcode"+symb, m), token("JUMP", m),
token("~begincode"+symb, m), code, token("~endcode"+symb, m), token("~begincode"+symb, m), code,
token("JUMPDEST", m) token("~endcode"+symb, m), token("JUMPDEST", m)
}; };
return pd(sub.aux, multiToken(nodelist, 11, m), 1); return pd(sub.aux, multiToken(nodelist, 11, m), 1);
} }
// Stack variables // Stack variables
if (node.val == "with") { if (node.val == "with") {
std::map<std::string, int> dupvars2 = dupvars; programData initial = opcodeify(node.args[1], aux, vaux);
dupvars2[node.args[0].val] = height; programVerticalAux vaux2 = vaux;
programData initial = opcodeify(node.args[1], aux, height, dupvars); vaux2.dupvars[node.args[0].val] = vaux.height;
vaux2.height += 1;
if (!initial.outs) if (!initial.outs)
err("Initial variable value must have nonzero arity!", m); err("Initial variable value must have nonzero arity!", m);
programData sub = opcodeify(node.args[2], initial.aux, height + 1, dupvars2); programData sub = opcodeify(node.args[2], initial.aux, vaux2);
Node nodelist[] = { Node nodelist[] = {
initial.code, initial.code,
sub.code sub.code
@ -151,7 +290,7 @@ programData opcodeify(Node node,
std::vector<Node> children; std::vector<Node> children;
int lastOut = 0; int lastOut = 0;
for (unsigned i = 0; i < node.args.size(); i++) { for (unsigned i = 0; i < node.args.size(); i++) {
programData sub = opcodeify(node.args[i], aux, height, dupvars); programData sub = opcodeify(node.args[i], aux, vaux);
aux = sub.aux; aux = sub.aux;
if (sub.outs == 1) { if (sub.outs == 1) {
if (i < node.args.size() - 1) sub.code = popwrap(sub.code); if (i < node.args.size() - 1) sub.code = popwrap(sub.code);
@ -163,8 +302,8 @@ programData opcodeify(Node node,
} }
// 2-part conditional (if gets rewritten to unless in rewrites) // 2-part conditional (if gets rewritten to unless in rewrites)
else if (node.val == "unless" && node.args.size() == 2) { else if (node.val == "unless" && node.args.size() == 2) {
programData cond = opcodeify(node.args[0], aux, height, dupvars); programData cond = opcodeify(node.args[0], aux, vaux);
programData action = opcodeify(node.args[1], cond.aux, height, dupvars); programData action = opcodeify(node.args[1], cond.aux, vaux);
aux = action.aux; aux = action.aux;
if (!cond.outs) err("Condition of if/unless statement has arity 0", m); if (!cond.outs) err("Condition of if/unless statement has arity 0", m);
if (action.outs) action.code = popwrap(action.code); if (action.outs) action.code = popwrap(action.code);
@ -178,9 +317,9 @@ programData opcodeify(Node node,
} }
// 3-part conditional // 3-part conditional
else if (node.val == "if" && node.args.size() == 3) { else if (node.val == "if" && node.args.size() == 3) {
programData ifd = opcodeify(node.args[0], aux, height, dupvars); programData ifd = opcodeify(node.args[0], aux, vaux);
programData thend = opcodeify(node.args[1], ifd.aux, height, dupvars); programData thend = opcodeify(node.args[1], ifd.aux, vaux);
programData elsed = opcodeify(node.args[2], thend.aux, height, dupvars); programData elsed = opcodeify(node.args[2], thend.aux, vaux);
aux = elsed.aux; aux = elsed.aux;
if (!ifd.outs) if (!ifd.outs)
err("Condition of if/unless statement has arity 0", m); err("Condition of if/unless statement has arity 0", m);
@ -191,7 +330,7 @@ programData opcodeify(Node node,
if (elsed.outs > outs) elsed.code = popwrap(elsed.code); if (elsed.outs > outs) elsed.code = popwrap(elsed.code);
Node nodelist[] = { Node nodelist[] = {
ifd.code, ifd.code,
token("NOT", m), token("ISZERO", m),
token("$else"+symb, m), token("JUMPI", m), token("$else"+symb, m), token("JUMPI", m),
thend.code, thend.code,
token("$endif"+symb, m), token("JUMP", m), token("$endif"+symb, m), token("JUMP", m),
@ -203,8 +342,8 @@ programData opcodeify(Node node,
} }
// While (rewritten to this in rewrites) // While (rewritten to this in rewrites)
else if (node.val == "until") { else if (node.val == "until") {
programData cond = opcodeify(node.args[0], aux, height, dupvars); programData cond = opcodeify(node.args[0], aux, vaux);
programData action = opcodeify(node.args[1], cond.aux, height, dupvars); programData action = opcodeify(node.args[1], cond.aux, vaux);
aux = action.aux; aux = action.aux;
if (!cond.outs) if (!cond.outs)
err("Condition of while/until loop has arity 0", m); err("Condition of while/until loop has arity 0", m);
@ -215,13 +354,13 @@ programData opcodeify(Node node,
token("$end"+symb, m), token("JUMPI", m), token("$end"+symb, m), token("JUMPI", m),
action.code, action.code,
token("$beg"+symb, m), token("JUMP", m), token("$beg"+symb, m), token("JUMP", m),
token("~end"+symb, m), token("JUMPDEST", m) token("~end"+symb, m), token("JUMPDEST", m),
}; };
return pd(aux, multiToken(nodelist, 10, m)); return pd(aux, multiToken(nodelist, 10, m));
} }
// Memory allocations // Memory allocations
else if (node.val == "alloc") { else if (node.val == "alloc") {
programData bytez = opcodeify(node.args[0], aux, height, dupvars); programData bytez = opcodeify(node.args[0], aux, vaux);
aux = bytez.aux; aux = bytez.aux;
if (!bytez.outs) if (!bytez.outs)
err("Alloc input has arity 0", m); err("Alloc input has arity 0", m);
@ -251,7 +390,9 @@ programData opcodeify(Node node,
for (unsigned i = 0; i < node.args.size(); i++) { for (unsigned i = 0; i < node.args.size(); i++) {
Metadata m2 = node.args[i].metadata; Metadata m2 = node.args[i].metadata;
nodes.push_back(token("DUP1", m2)); nodes.push_back(token("DUP1", m2));
programData sub = opcodeify(node.args[i], aux, height + 2, dupvars); programVerticalAux vaux2 = vaux;
vaux2.height += 2;
programData sub = opcodeify(node.args[i], aux, vaux2);
if (!sub.outs) if (!sub.outs)
err("Array_lit item " + unsignedToDecimal(i) + " has zero arity", m2); err("Array_lit item " + unsignedToDecimal(i) + " has zero arity", m2);
aux = sub.aux; aux = sub.aux;
@ -276,10 +417,9 @@ programData opcodeify(Node node,
err("Invalid arity for "+node.val, m); err("Invalid arity for "+node.val, m);
} }
for (int i = node.args.size() - 1; i >= 0; i--) { for (int i = node.args.size() - 1; i >= 0; i--) {
programData sub = opcodeify(node.args[i], programVerticalAux vaux2 = vaux;
aux, vaux2.height = vaux.height - i - 1 + node.args.size();
height - i - 1 + node.args.size(), programData sub = opcodeify(node.args[i], aux, vaux2);
dupvars);
aux = sub.aux; aux = sub.aux;
if (!sub.outs) if (!sub.outs)
err("Input "+unsignedToDecimal(i)+" has arity 0", sub.code.metadata); err("Input "+unsignedToDecimal(i)+" has arity 0", sub.code.metadata);
@ -305,7 +445,7 @@ Node finalize(programData c) {
if ((c.aux.allocUsed || c.aux.calldataUsed) && c.aux.vars.size() > 0) { if ((c.aux.allocUsed || c.aux.calldataUsed) && c.aux.vars.size() > 0) {
Node nodelist[] = { Node nodelist[] = {
token("0", m), token("0", m),
token(unsignedToDecimal(c.aux.vars.size() * 32 - 1)), token(unsignedToDecimal(c.aux.nextVarMem - 1)),
token("MSTORE8", m) token("MSTORE8", m)
}; };
bottom.push_back(multiToken(nodelist, 3, m)); bottom.push_back(multiToken(nodelist, 3, m));

224
libserpent/opcodes.h

@ -1,20 +1,3 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ETHSERP_OPCODES #ifndef ETHSERP_OPCODES
#define ETHSERP_OPCODES #define ETHSERP_OPCODES
@ -24,128 +7,131 @@
#include <map> #include <map>
class Mapping { class Mapping {
public: public:
Mapping(std::string Op, int Opcode, int In, int Out) { Mapping(std::string Op, int Opcode, int In, int Out) {
op = Op; op = Op;
opcode = Opcode; opcode = Opcode;
in = In; in = In;
out = Out; out = Out;
} }
std::string op; std::string op;
int opcode; int opcode;
int in; int in;
int out; int out;
}; };
Mapping mapping[] = { Mapping mapping[] = {
Mapping("STOP", 0x00, 0, 0), Mapping("STOP", 0x00, 0, 0),
Mapping("ADD", 0x01, 2, 1), Mapping("ADD", 0x01, 2, 1),
Mapping("MUL", 0x02, 2, 1), Mapping("MUL", 0x02, 2, 1),
Mapping("SUB", 0x03, 2, 1), Mapping("SUB", 0x03, 2, 1),
Mapping("DIV", 0x04, 2, 1), Mapping("DIV", 0x04, 2, 1),
Mapping("SDIV", 0x05, 2, 1), Mapping("SDIV", 0x05, 2, 1),
Mapping("MOD", 0x06, 2, 1), Mapping("MOD", 0x06, 2, 1),
Mapping("SMOD", 0x07, 2, 1), Mapping("SMOD", 0x07, 2, 1),
Mapping("EXP", 0x08, 2, 1), Mapping("ADDMOD", 0x08, 3, 1),
Mapping("NEG", 0x09, 1, 1), Mapping("MULMOD", 0x09, 3, 1),
Mapping("LT", 0x0a, 2, 1), Mapping("EXP", 0x0a, 2, 1),
Mapping("GT", 0x0b, 2, 1), Mapping("SIGNEXTEND", 0x0b, 2, 1),
Mapping("SLT", 0x0c, 2, 1), Mapping("LT", 0x10, 2, 1),
Mapping("SGT", 0x0d, 2, 1), Mapping("GT", 0x11, 2, 1),
Mapping("EQ", 0x0e, 2, 1), Mapping("SLT", 0x12, 2, 1),
Mapping("NOT", 0x0f, 1, 1), Mapping("SGT", 0x13, 2, 1),
Mapping("AND", 0x10, 2, 1), Mapping("EQ", 0x14, 2, 1),
Mapping("OR", 0x11, 2, 1), Mapping("ISZERO", 0x15, 1, 1),
Mapping("XOR", 0x12, 2, 1), Mapping("AND", 0x16, 2, 1),
Mapping("BYTE", 0x13, 2, 1), Mapping("OR", 0x17, 2, 1),
Mapping("ADDMOD", 0x14, 3, 1), Mapping("XOR", 0x18, 2, 1),
Mapping("MULMOD", 0x15, 3, 1), Mapping("NOT", 0x19, 1, 1),
Mapping("SIGNEXTEND", 0x16, 2, 1), Mapping("BYTE", 0x1a, 2, 1),
Mapping("SHA3", 0x20, 2, 1), Mapping("ADDMOD", 0x14, 3, 1),
Mapping("ADDRESS", 0x30, 0, 1), Mapping("MULMOD", 0x15, 3, 1),
Mapping("BALANCE", 0x31, 1, 1), Mapping("SIGNEXTEND", 0x16, 2, 1),
Mapping("ORIGIN", 0x32, 0, 1), Mapping("SHA3", 0x20, 2, 1),
Mapping("CALLER", 0x33, 0, 1), Mapping("ADDRESS", 0x30, 0, 1),
Mapping("CALLVALUE", 0x34, 0, 1), Mapping("BALANCE", 0x31, 1, 1),
Mapping("CALLDATALOAD", 0x35, 1, 1), Mapping("ORIGIN", 0x32, 0, 1),
Mapping("CALLDATASIZE", 0x36, 0, 1), Mapping("CALLER", 0x33, 0, 1),
Mapping("CALLDATACOPY", 0x37, 3, 1), Mapping("CALLVALUE", 0x34, 0, 1),
Mapping("CODESIZE", 0x38, 0, 1), Mapping("CALLDATALOAD", 0x35, 1, 1),
Mapping("CODECOPY", 0x39, 3, 1), Mapping("CALLDATASIZE", 0x36, 0, 1),
Mapping("GASPRICE", 0x3a, 0, 1), Mapping("CALLDATACOPY", 0x37, 3, 1),
Mapping("PREVHASH", 0x40, 0, 1), Mapping("CODESIZE", 0x38, 0, 1),
Mapping("COINBASE", 0x41, 0, 1), Mapping("CODECOPY", 0x39, 3, 1),
Mapping("TIMESTAMP", 0x42, 0, 1), Mapping("GASPRICE", 0x3a, 0, 1),
Mapping("NUMBER", 0x43, 0, 1), Mapping("PREVHASH", 0x40, 0, 1),
Mapping("DIFFICULTY", 0x44, 0, 1), Mapping("COINBASE", 0x41, 0, 1),
Mapping("GASLIMIT", 0x45, 0, 1), Mapping("TIMESTAMP", 0x42, 0, 1),
Mapping("POP", 0x50, 1, 0), Mapping("NUMBER", 0x43, 0, 1),
Mapping("MLOAD", 0x53, 1, 1), Mapping("DIFFICULTY", 0x44, 0, 1),
Mapping("MSTORE", 0x54, 2, 0), Mapping("GASLIMIT", 0x45, 0, 1),
Mapping("MSTORE8", 0x55, 2, 0), Mapping("POP", 0x50, 1, 0),
Mapping("SLOAD", 0x56, 1, 1), Mapping("MLOAD", 0x51, 1, 1),
Mapping("SSTORE", 0x57, 2, 0), Mapping("MSTORE", 0x52, 2, 0),
Mapping("JUMP", 0x58, 1, 0), Mapping("MSTORE8", 0x53, 2, 0),
Mapping("JUMPI", 0x59, 2, 0), Mapping("SLOAD", 0x54, 1, 1),
Mapping("PC", 0x5a, 0, 1), Mapping("SSTORE", 0x55, 2, 0),
Mapping("MSIZE", 0x5b, 0, 1), Mapping("JUMP", 0x56, 1, 0),
Mapping("GAS", 0x5c, 0, 1), Mapping("JUMPI", 0x57, 2, 0),
Mapping("JUMPDEST", 0x5d, 0, 0), Mapping("PC", 0x58, 0, 1),
Mapping("CREATE", 0xf0, 3, 1), Mapping("MSIZE", 0x59, 0, 1),
Mapping("CALL", 0xf1, 7, 1), Mapping("GAS", 0x5a, 0, 1),
Mapping("RETURN", 0xf2, 2, 0), Mapping("JUMPDEST", 0x5b, 0, 0),
Mapping("CALL_CODE", 0xf3, 7, 1), Mapping("LOG0", 0xa0, 2, 0),
Mapping("SUICIDE", 0xff, 1, 0), Mapping("LOG1", 0xa1, 3, 0),
Mapping("---END---", 0x00, 0, 0), Mapping("LOG2", 0xa2, 4, 0),
Mapping("LOG3", 0xa3, 5, 0),
Mapping("LOG4", 0xa4, 6, 0),
Mapping("CREATE", 0xf0, 3, 1),
Mapping("CALL", 0xf1, 7, 1),
Mapping("RETURN", 0xf2, 2, 0),
Mapping("CALL_CODE", 0xf3, 7, 1),
Mapping("SUICIDE", 0xff, 1, 0),
Mapping("---END---", 0x00, 0, 0),
}; };
std::map<std::string, std::vector<int> > opcodes; std::map<std::string, std::vector<int> > opcodes;
std::map<int, std::string> reverseOpcodes; std::map<int, std::string> reverseOpcodes;
// Fetches everything EXCEPT PUSH1..32 // Fetches everything EXCEPT PUSH1..32
std::pair<std::string, std::vector<int> > _opdata(std::string ops, int opi) std::pair<std::string, std::vector<int> > _opdata(std::string ops, int opi) {
{ if (!opcodes.size()) {
if (!opcodes.size()) int i = 0;
{ while (mapping[i].op != "---END---") {
int i = 0; Mapping mi = mapping[i];
while (mapping[i].op != "---END---") opcodes[mi.op] = triple(mi.opcode, mi.in, mi.out);
{ i++;
Mapping mi = mapping[i]; }
opcodes[mi.op] = triple(mi.opcode, mi.in, mi.out); for (i = 1; i <= 16; i++) {
i++; opcodes["DUP"+unsignedToDecimal(i)] = triple(0x7f + i, i, i+1);
} opcodes["SWAP"+unsignedToDecimal(i)] = triple(0x8f + i, i+1, i+1);
for (i = 1; i <= 16; i++) }
{ for (std::map<std::string, std::vector<int> >::iterator it=opcodes.begin();
opcodes["DUP"+unsignedToDecimal(i)] = triple(0x7f + i, i, i+1); it != opcodes.end();
opcodes["SWAP"+unsignedToDecimal(i)] = triple(0x8f + i, i+1, i+1); it++) {
} reverseOpcodes[(*it).second[0]] = (*it).first;
for (std::map<std::string, std::vector<int> >::iterator it=opcodes.begin(); it != opcodes.end(); it++) }
reverseOpcodes[(*it).second[0]] = (*it).first; }
} std::string op;
std::string op; std::vector<int> opdata;
std::vector<int> opdata; op = reverseOpcodes.count(opi) ? reverseOpcodes[opi] : "";
op = reverseOpcodes.count(opi) ? reverseOpcodes[opi] : ""; opdata = opcodes.count(ops) ? opcodes[ops] : triple(-1, -1, -1);
opdata = opcodes.count(ops) ? opcodes[ops] : triple(-1, -1, -1); return std::pair<std::string, std::vector<int> >(op, opdata);
return std::pair<std::string, std::vector<int> >(op, opdata);
} }
int opcode(std::string op) int opcode(std::string op) {
{
return _opdata(op, -1).second[0]; return _opdata(op, -1).second[0];
} }
int opinputs(std::string op) int opinputs(std::string op) {
{
return _opdata(op, -1).second[1]; return _opdata(op, -1).second[1];
} }
int opoutputs(std::string op) int opoutputs(std::string op) {
{
return _opdata(op, -1).second[2]; return _opdata(op, -1).second[2];
} }
std::string op(int opcode) std::string op(int opcode) {
{
return _opdata("", opcode).first; return _opdata("", opcode).first;
} }

53
libserpent/parser.cpp

@ -9,20 +9,21 @@
// Extended BEDMAS precedence order // Extended BEDMAS precedence order
int precedence(Node tok) { int precedence(Node tok) {
std::string v = tok.val; std::string v = tok.val;
if (v == "!" || v == "not") return 0; if (v == ".") return -1;
else if (v=="^" || v == "**") return 1; else if (v == "!" || v == "not") return 1;
else if (v=="*" || v=="/" || v=="@/" || v=="%" || v=="@%") return 2; else if (v=="^" || v == "**") return 2;
else if (v=="+" || v=="-") return 3; else if (v=="*" || v=="/" || v=="@/" || v=="%" || v=="@%") return 3;
else if (v=="<" || v==">" || v=="<=" || v==">=") return 4; else if (v=="+" || v=="-") return 4;
else if (v=="@<" || v=="@>" || v=="@<=" || v=="@>=") return 4; else if (v=="<" || v==">" || v=="<=" || v==">=") return 5;
else if (v=="&" || v=="|" || v=="xor" || v=="==" || v == "!=") return 5; else if (v=="@<" || v=="@>" || v=="@<=" || v=="@>=") return 5;
else if (v=="&&" || v=="and") return 6; else if (v=="&" || v=="|" || v=="xor" || v=="==" || v == "!=") return 6;
else if (v=="||" || v=="or") return 7; else if (v=="&&" || v=="and") return 7;
else if (v==":") return 8; else if (v=="||" || v=="or") return 8;
else if (v==":") return 9;
else if (v=="=") return 10; else if (v=="=") return 10;
else if (v=="+=" || v=="-=" || v=="*=" || v=="/=" || v=="%=") return 10; else if (v=="+=" || v=="-=" || v=="*=" || v=="/=" || v=="%=") return 10;
else if (v=="@/=" || v=="@%=") return 10; else if (v=="@/=" || v=="@%=") return 10;
else return -1; else return 0;
} }
// Token classification for shunting-yard purposes // Token classification for shunting-yard purposes
@ -32,8 +33,9 @@ int toktype(Node tok) {
if (v == "(" || v == "[" || v == "{") return LPAREN; if (v == "(" || v == "[" || v == "{") return LPAREN;
else if (v == ")" || v == "]" || v == "}") return RPAREN; else if (v == ")" || v == "]" || v == "}") return RPAREN;
else if (v == ",") return COMMA; else if (v == ",") return COMMA;
else if (v == "!" || v == "not" || v == "neg") return UNARY_OP; else if (v == "!" || v == "~" || v == "not") return UNARY_OP;
else if (precedence(tok) >= 0) return BINARY_OP; else if (precedence(tok) > 0) return BINARY_OP;
else if (precedence(tok) < 0) return TOKEN_SPLITTER;
if (tok.val[0] != '"' && tok.val[0] != '\'') { if (tok.val[0] != '"' && tok.val[0] != '\'') {
for (unsigned i = 0; i < tok.val.length(); i++) { for (unsigned i = 0; i < tok.val.length(); i++) {
if (chartype(tok.val[i]) == SYMB) { if (chartype(tok.val[i]) == SYMB) {
@ -68,6 +70,10 @@ std::vector<Node> shuntingYard(std::vector<Node> tokens) {
} }
// Left parens go on stack and output queue // Left parens go on stack and output queue
else if (toktyp == LPAREN) { else if (toktyp == LPAREN) {
while (stack.size() && toktype(stack.back()) == TOKEN_SPLITTER) {
oq.push_back(stack.back());
stack.pop_back();
}
if (prevtyp != ALPHANUM && prevtyp != RPAREN) { if (prevtyp != ALPHANUM && prevtyp != RPAREN) {
oq.push_back(token("id", tok.metadata)); oq.push_back(token("id", tok.metadata));
} }
@ -88,16 +94,26 @@ std::vector<Node> shuntingYard(std::vector<Node> tokens) {
else if (toktyp == UNARY_OP) { else if (toktyp == UNARY_OP) {
stack.push_back(tok); stack.push_back(tok);
} }
// If token splitter, just push it to the stack
else if (toktyp == TOKEN_SPLITTER) {
while (stack.size() && toktype(stack.back()) == TOKEN_SPLITTER) {
oq.push_back(stack.back());
stack.pop_back();
}
stack.push_back(tok);
}
// If binary op, keep popping from stack while higher bedmas precedence // If binary op, keep popping from stack while higher bedmas precedence
else if (toktyp == BINARY_OP) { else if (toktyp == BINARY_OP) {
if (tok.val == "-" && prevtyp != ALPHANUM && prevtyp != RPAREN) { if (tok.val == "-" && prevtyp != ALPHANUM && prevtyp != RPAREN) {
stack.push_back(token("neg", tok.metadata)); stack.push_back(tok);
oq.push_back(token("0", tok.metadata));
} }
else { else {
int prec = precedence(tok); int prec = precedence(tok);
while (stack.size() while (stack.size()
&& (toktype(stack.back()) == BINARY_OP && (toktype(stack.back()) == BINARY_OP
|| toktype(stack.back()) == UNARY_OP) || toktype(stack.back()) == UNARY_OP
|| toktype(stack.back()) == TOKEN_SPLITTER)
&& precedence(stack.back()) <= prec) { && precedence(stack.back()) <= prec) {
oq.push_back(stack.back()); oq.push_back(stack.back());
stack.pop_back(); stack.pop_back();
@ -133,9 +149,9 @@ Node treefy(std::vector<Node> stream) {
int typ = toktype(tok); int typ = toktype(tok);
// If unary, take node off end of oq and wrap it with the operator // If unary, take node off end of oq and wrap it with the operator
// If binary, do the same with two nodes // If binary, do the same with two nodes
if (typ == UNARY_OP || typ == BINARY_OP) { if (typ == UNARY_OP || typ == BINARY_OP || typ == TOKEN_SPLITTER) {
std::vector<Node> args; std::vector<Node> args;
int rounds = (typ == BINARY_OP) ? 2 : 1; int rounds = (typ == UNARY_OP) ? 1 : 2;
for (int i = 0; i < rounds; i++) { for (int i = 0; i < rounds; i++) {
if (oq.size() == 0) { if (oq.size() == 0) {
err("Line malformed, not enough args for "+tok.val, err("Line malformed, not enough args for "+tok.val,
@ -245,7 +261,8 @@ int spaceCount(std::string s) {
// Is this a command that takes an argument on the same line? // Is this a command that takes an argument on the same line?
bool bodied(std::string tok) { bool bodied(std::string tok) {
return tok == "if" || tok == "elif" || tok == "while" return tok == "if" || tok == "elif" || tok == "while"
|| tok == "with" || tok == "def"; || tok == "with" || tok == "def" || tok == "extern"
|| tok == "data";
} }
// Is this a command that takes an argument as a child block? // Is this a command that takes an argument as a child block?

870
libserpent/rewriter.cpp

File diff suppressed because it is too large

2
libserpent/tokenize.cpp

@ -13,7 +13,7 @@ int chartype(char c) {
if (c >= '0' && c <= '9') return ALPHANUM; if (c >= '0' && c <= '9') return ALPHANUM;
else if (c >= 'a' && c <= 'z') return ALPHANUM; else if (c >= 'a' && c <= 'z') return ALPHANUM;
else if (c >= 'A' && c <= 'Z') return ALPHANUM; else if (c >= 'A' && c <= 'Z') return ALPHANUM;
else if (std::string("~._$").find(c) != std::string::npos) return ALPHANUM; else if (std::string("~_$").find(c) != std::string::npos) return ALPHANUM;
else if (c == '\t' || c == ' ' || c == '\n') return SPACE; else if (c == '\t' || c == ' ' || c == '\n') return SPACE;
else if (std::string("()[]{}").find(c) != std::string::npos) return BRACK; else if (std::string("()[]{}").find(c) != std::string::npos) return BRACK;
else if (c == '"') return DQUOTE; else if (c == '"') return DQUOTE;

22
libserpent/util.cpp

@ -26,6 +26,28 @@ Node astnode(std::string val, std::vector<Node> args, Metadata met) {
return o; return o;
} }
//AST node constructors for a specific number of children
Node astnode(std::string val, Node a, Metadata met) {
std::vector<Node> args;
args.push_back(a);
return astnode(val, args, met);
}
Node astnode(std::string val, Node a, Node b, Metadata met) {
std::vector<Node> args;
args.push_back(a);
args.push_back(b);
return astnode(val, args, met);
}
Node astnode(std::string val, Node a, Node b, Node c, Metadata met) {
std::vector<Node> args;
args.push_back(a);
args.push_back(b);
args.push_back(c);
return astnode(val, args, met);
}
// Print token list // Print token list
std::string printTokens(std::vector<Node> tokens) { std::string printTokens(std::vector<Node> tokens) {
std::string s = ""; std::string s = "";

6
libserpent/util.h

@ -22,7 +22,8 @@ const int TOKEN = 0,
COLON = 11, COLON = 11,
UNARY_OP = 12, UNARY_OP = 12,
BINARY_OP = 13, BINARY_OP = 13,
COMPOUND = 14; COMPOUND = 14,
TOKEN_SPLITTER = 15;
// Stores metadata about each token // Stores metadata about each token
class Metadata { class Metadata {
@ -48,6 +49,9 @@ struct Node {
}; };
Node token(std::string val, Metadata met=Metadata()); Node token(std::string val, Metadata met=Metadata());
Node astnode(std::string val, std::vector<Node> args, Metadata met=Metadata()); Node astnode(std::string val, std::vector<Node> args, Metadata met=Metadata());
Node astnode(std::string val, Node a, Metadata met=Metadata());
Node astnode(std::string val, Node a, Node b, Metadata met=Metadata());
Node astnode(std::string val, Node a, Node b, Node c, Metadata met=Metadata());
// Number of tokens in a tree // Number of tokens in a tree
int treeSize(Node prog); int treeSize(Node prog);

1
libwhisper/Message.h

@ -28,6 +28,7 @@
#include <utility> #include <utility>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcrypto/Common.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include "Common.h" #include "Common.h"

317
test/crypto.cpp

@ -28,6 +28,7 @@
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcrypto/EC.h> #include <libdevcrypto/EC.h>
#include <libdevcrypto/SHA3MAC.h>
#include "TestHelperCrypto.h" #include "TestHelperCrypto.h"
using namespace std; using namespace std;
@ -46,107 +47,220 @@ BOOST_AUTO_TEST_CASE(common_encrypt_decrypt)
KeyPair k = KeyPair::create(); KeyPair k = KeyPair::create();
bytes cipher; bytes cipher;
encrypt(k.pub(), bcr, cipher); encrypt(k.pub(), bcr, cipher);
assert(cipher != asBytes(message) && cipher.size() > 0); BOOST_REQUIRE(cipher != asBytes(message) && cipher.size() > 0);
bytes plain; bytes plain;
decrypt(k.sec(), bytesConstRef(&cipher), plain); decrypt(k.sec(), bytesConstRef(&cipher), plain);
assert(asString(plain) == message); BOOST_REQUIRE(asString(plain) == message);
assert(plain == asBytes(message)); BOOST_REQUIRE(plain == asBytes(message));
} }
BOOST_AUTO_TEST_CASE(cryptopp_vs_secp256k1) BOOST_AUTO_TEST_CASE(cryptopp_vs_secp256k1)
{ {
ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); ECIES<ECP>::Decryptor d(pp::PRNG, pp::secp256k1Curve);
ECIES<ECP>::Encryptor e(d.GetKey()); ECIES<ECP>::Encryptor e(d.GetKey());
Secret s; Secret s;
pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s); pp::exportPrivateKey(d.GetKey(), s);
Public p; Public p;
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); pp::exportPublicKey(e.GetKey(), p);
assert(dev::toAddress(s) == right160(dev::sha3(p.ref()))); BOOST_REQUIRE(dev::toAddress(s) == right160(dev::sha3(p.ref())));
Secret previous = s; Secret previous = s;
for (auto i = 0; i < 30; i++) for (auto i = 0; i < 2; i++)
{ {
ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); ECIES<ECP>::Decryptor d(pp::PRNG, pp::secp256k1Curve);
ECIES<ECP>::Encryptor e(d.GetKey()); ECIES<ECP>::Encryptor e(d.GetKey());
Secret s; Secret s;
pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s); pp::exportPrivateKey(d.GetKey(), s);
assert(s != previous); BOOST_REQUIRE(s != previous);
Public p; Public p;
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); pp::exportPublicKey(e.GetKey(), p);
assert(dev::toAddress(s) == right160(dev::sha3(p.ref()))); h160 secp256k1Addr = dev::toAddress(s);
h160 cryptoppAddr = right160(dev::sha3(p.ref()));
if (secp256k1Addr != cryptoppAddr)
{
BOOST_REQUIRE(secp256k1Addr == cryptoppAddr);
break;
}
} }
} }
BOOST_AUTO_TEST_CASE(cryptopp_keys_cryptor_sipaseckp256k1) BOOST_AUTO_TEST_CASE(cryptopp_cryptopp_secp256k1libport)
{ {
KeyPair k = KeyPair::create(); // cryptopp implementation of secp256k1lib sign_compact w/recid parameter and recovery of public key from signature
Secret s = k.sec();
// base secret
// Convert secret to exponent used by pp Secret secret(sha3("privacy"));
Integer e = pp::ExponentFromSecret(s);
// we get ec params from signer
const CryptoPP::DL_GroupParameters_EC<CryptoPP::ECP> params = pp::secp256k1Params;
ECDSA<ECP, SHA3_256>::Signer signer;
// e := sha3(msg)
bytes e(fromHex("0x01"));
e.resize(32);
int tests = 2; // Oct 29: successful @ 1500
while (sha3(&e, &e), secret = sha3(secret.asBytes()), tests--)
{
KeyPair key(secret);
Public pkey = key.pub();
pp::initializeDLScheme(secret, signer);
h256 he(sha3(e));
Integer heInt(he.asBytes().data(), 32);
h256 k(crypto::kdf(secret, he));
Integer kInt(k.asBytes().data(), 32);
kInt %= params.GetSubgroupOrder()-1;
ECP::Point rp = params.ExponentiateBase(kInt);
Integer const& q = params.GetGroupOrder();
Integer r = params.ConvertElementToInteger(rp);
int recid = ((r >= q) ? 2 : 0) | (rp.y.IsOdd() ? 1 : 0);
Integer kInv = kInt.InverseMod(q);
Integer s = (kInv * (Integer(secret.asBytes().data(), 32)*r + heInt)) % q;
BOOST_REQUIRE(!!r && !!s);
/*
// For future reference:
// According to maths, this codepath can't be reached, however, it's in secp256k1.
// Commenting this out diverges from codebase implementation.
// To be removed after upstream PR and proof are evaulated.
if (s > params.GetSubgroupOrder())
{
// note: this rarely happens
s = params.GetGroupOrder() - s;
if (recid)
recid ^= 1;
}
*/
// Test that exported DL_EC private is same as exponent from Secret Signature sig;
CryptoPP::DL_PrivateKey_EC<CryptoPP::ECP> privatek; r.Encode(sig.data(), 32);
privatek.AccessGroupParameters().Initialize(pp::secp256k1()); s.Encode(sig.data() + 32, 32);
privatek.SetPrivateExponent(e); sig[64] = recid;
assert(e == privatek.GetPrivateExponent());
Public p = dev::recover(sig, he);
// Test that exported secret is same as decryptor(privatek) secret BOOST_REQUIRE(p == pkey);
ECIES<ECP>::Decryptor d;
d.AccessKey().AccessGroupParameters().Initialize(pp::secp256k1()); // verify w/cryptopp
d.AccessKey().SetPrivateExponent(e); BOOST_REQUIRE(crypto::verify(pkey, sig, bytesConstRef(&e)));
assert(d.AccessKey().GetPrivateExponent() == e);
// verify with secp256k1lib
// Test that decryptor->encryptor->public == private->makepublic->public byte encpub[65] = {0x04};
CryptoPP::DL_PublicKey_EC<CryptoPP::ECP> pubk; memcpy(&encpub[1], pkey.data(), 64);
pubk.AccessGroupParameters().Initialize(pp::secp256k1()); byte dersig[72];
privatek.MakePublicKey(pubk); size_t cssz = DSAConvertSignatureFormat(dersig, 72, DSA_DER, sig.data(), 64, DSA_P1363);
BOOST_CHECK(cssz <= 72);
ECIES<ECP>::Encryptor enc(d); BOOST_REQUIRE(1 == secp256k1_ecdsa_verify(he.data(), sizeof(he), dersig, cssz, encpub, 65));
assert(pubk.GetPublicElement() == enc.AccessKey().GetPublicElement()); }
}
// Test against sipa/seckp256k1
Public p; BOOST_AUTO_TEST_CASE(cryptopp_ecdsa_sipaseckp256k1)
pp::PublicFromExponent(pp::ExponentFromSecret(s), p); {
assert(toAddress(s) == dev::right160(dev::sha3(p.ref()))); // cryptopp integer encoding
assert(k.pub() == p); Integer nHex("f2ee15ea639b73fa3db9b34a245bdfa015c260c598b211bf05a1ecc4b3e3b4f2H");
Integer nB(fromHex("f2ee15ea639b73fa3db9b34a245bdfa015c260c598b211bf05a1ecc4b3e3b4f2").data(), 32);
BOOST_REQUIRE(nHex == nB);
bytes sbytes(fromHex("0x01"));
Secret secret(sha3(sbytes)); // 5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2
KeyPair key(secret);
bytes m(fromHex("0x01"));
int tests = 2;
while (m[0]++, tests--)
{
h256 hm(sha3(m));
Integer hInt(hm.asBytes().data(), 32);
h256 k(hm ^ key.sec());
Integer kInt(k.asBytes().data(), 32);
// raw sign w/cryptopp (doesn't pass through cryptopp hash filter)
ECDSA<ECP, SHA3_256>::Signer signer;
pp::initializeDLScheme(key.sec(), signer);
Integer r, s;
signer.RawSign(kInt, hInt, r, s);
// verify cryptopp raw-signature w/cryptopp
ECDSA<ECP, SHA3_256>::Verifier verifier;
pp::initializeDLScheme(key.pub(), verifier);
Signature sigppraw;
r.Encode(sigppraw.data(), 32);
s.Encode(sigppraw.data() + 32, 32);
BOOST_REQUIRE(verifier.VerifyMessage(m.data(), m.size(), sigppraw.data(), 64));
BOOST_REQUIRE(crypto::verify(key.pub(), sigppraw, bytesConstRef(&m)));
BOOST_REQUIRE(dev::verify(key.pub(), sigppraw, hm));
// sign with cryptopp, verify, recover w/sec256lib
Signature seclibsig(dev::sign(key.sec(), hm));
BOOST_REQUIRE(verifier.VerifyMessage(m.data(), m.size(), seclibsig.data(), 64));
BOOST_REQUIRE(crypto::verify(key.pub(), seclibsig, bytesConstRef(&m)));
BOOST_REQUIRE(dev::verify(key.pub(), seclibsig, hm));
BOOST_REQUIRE(dev::recover(seclibsig, hm) == key.pub());
// sign with cryptopp (w/hash filter?), verify with cryptopp
bytes sigppb(signer.MaxSignatureLength());
size_t ssz = signer.SignMessage(pp::PRNG, m.data(), m.size(), sigppb.data());
Signature sigpp;
memcpy(sigpp.data(), sigppb.data(), 64);
BOOST_REQUIRE(verifier.VerifyMessage(m.data(), m.size(), sigppb.data(), ssz));
BOOST_REQUIRE(crypto::verify(key.pub(), sigpp, bytesConstRef(&m)));
BOOST_REQUIRE(dev::verify(key.pub(), sigpp, hm));
// sign with cryptopp and stringsource hash filter
string sigstr;
StringSource ssrc(asString(m), true, new SignerFilter(pp::PRNG, signer, new StringSink(sigstr)));
FixedHash<sizeof(Signature)> retsig((byte const*)sigstr.data(), Signature::ConstructFromPointer);
BOOST_REQUIRE(verifier.VerifyMessage(m.data(), m.size(), retsig.data(), 64));
BOOST_REQUIRE(crypto::verify(key.pub(), retsig, bytesConstRef(&m)));
BOOST_REQUIRE(dev::verify(key.pub(), retsig, hm));
/// verification w/sec256lib
// requires public key and sig in standard format
byte encpub[65] = {0x04};
memcpy(&encpub[1], key.pub().data(), 64);
byte dersig[72];
// verify sec256lib sig w/sec256lib
size_t cssz = DSAConvertSignatureFormat(dersig, 72, DSA_DER, seclibsig.data(), 64, DSA_P1363);
BOOST_CHECK(cssz <= 72);
BOOST_REQUIRE(1 == secp256k1_ecdsa_verify(hm.data(), sizeof(hm), dersig, cssz, encpub, 65));
// verify cryptopp-raw sig w/sec256lib
cssz = DSAConvertSignatureFormat(dersig, 72, DSA_DER, sigppraw.data(), 64, DSA_P1363);
BOOST_CHECK(cssz <= 72);
BOOST_REQUIRE(1 == secp256k1_ecdsa_verify(hm.data(), sizeof(hm), dersig, cssz, encpub, 65));
// verify cryptopp sig w/sec256lib
cssz = DSAConvertSignatureFormat(dersig, 72, DSA_DER, sigppb.data(), 64, DSA_P1363);
BOOST_CHECK(cssz <= 72);
BOOST_REQUIRE(1 == secp256k1_ecdsa_verify(hm.data(), sizeof(hm), dersig, cssz, encpub, 65));
}
} }
BOOST_AUTO_TEST_CASE(cryptopp_public_export_import) BOOST_AUTO_TEST_CASE(cryptopp_public_export_import)
{ {
ECIES<ECP>::Decryptor d(pp::PRNG(), pp::secp256k1()); ECIES<ECP>::Decryptor d(pp::PRNG, pp::secp256k1Curve);
ECIES<ECP>::Encryptor e(d.GetKey()); ECIES<ECP>::Encryptor e(d.GetKey());
Secret s; Secret s;
pp::SecretFromDL_PrivateKey_EC(d.GetKey(), s); pp::exportPrivateKey(d.GetKey(), s);
Public p; Public p;
pp::PublicFromDL_PublicKey_EC(e.GetKey(), p); pp::exportPublicKey(e.GetKey(), p);
Address addr = right160(dev::sha3(p.ref())); Address addr = right160(dev::sha3(p.ref()));
assert(toAddress(s) == addr); BOOST_REQUIRE(toAddress(s) == addr);
KeyPair l(s); KeyPair l(s);
assert(l.address() == addr); BOOST_REQUIRE(l.address() == addr);
DL_PublicKey_EC<ECP> pub;
pub.Initialize(pp::secp256k1(), pp::PointFromPublic(p));
assert(pub.GetPublicElement() == e.GetKey().GetPublicElement());
KeyPair k = KeyPair::create();
Public p2;
pp::PublicFromExponent(pp::ExponentFromSecret(k.sec()), p2);
assert(k.pub() == p2);
Address a = k.address();
Address a2 = toAddress(k.sec());
assert(a2 == a);
} }
BOOST_AUTO_TEST_CASE(ecies_eckeypair) BOOST_AUTO_TEST_CASE(ecies_eckeypair)
@ -158,10 +272,10 @@ BOOST_AUTO_TEST_CASE(ecies_eckeypair)
bytes b = asBytes(message); bytes b = asBytes(message);
encrypt(k.pub(), b); encrypt(k.pub(), b);
assert(b != asBytes(original)); BOOST_REQUIRE(b != asBytes(original));
decrypt(k.sec(), b); decrypt(k.sec(), b);
assert(b == asBytes(original)); BOOST_REQUIRE(b == asBytes(original));
} }
BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac) BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac)
@ -172,9 +286,6 @@ BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac)
// All connections should share seed for PRF (or PRNG) for nonces // All connections should share seed for PRF (or PRNG) for nonces
} }
BOOST_AUTO_TEST_CASE(cryptopp_ecies_message) BOOST_AUTO_TEST_CASE(cryptopp_ecies_message)
@ -183,7 +294,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecies_message)
string const message("Now is the time for all good persons to come to the aide of humanity."); string const message("Now is the time for all good persons to come to the aide of humanity.");
ECIES<ECP>::Decryptor localDecryptor(pp::PRNG(), pp::secp256k1()); ECIES<ECP>::Decryptor localDecryptor(pp::PRNG, pp::secp256k1Curve);
SavePrivateKey(localDecryptor.GetPrivateKey()); SavePrivateKey(localDecryptor.GetPrivateKey());
ECIES<ECP>::Encryptor localEncryptor(localDecryptor); ECIES<ECP>::Encryptor localEncryptor(localDecryptor);
@ -191,43 +302,43 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecies_message)
ECIES<ECP>::Decryptor futureDecryptor; ECIES<ECP>::Decryptor futureDecryptor;
LoadPrivateKey(futureDecryptor.AccessPrivateKey()); LoadPrivateKey(futureDecryptor.AccessPrivateKey());
futureDecryptor.GetPrivateKey().ThrowIfInvalid(pp::PRNG(), 3); futureDecryptor.GetPrivateKey().ThrowIfInvalid(pp::PRNG, 3);
ECIES<ECP>::Encryptor futureEncryptor; ECIES<ECP>::Encryptor futureEncryptor;
LoadPublicKey(futureEncryptor.AccessPublicKey()); LoadPublicKey(futureEncryptor.AccessPublicKey());
futureEncryptor.GetPublicKey().ThrowIfInvalid(pp::PRNG(), 3); futureEncryptor.GetPublicKey().ThrowIfInvalid(pp::PRNG, 3);
// encrypt/decrypt with local // encrypt/decrypt with local
string cipherLocal; string cipherLocal;
StringSource ss1 (message, true, new PK_EncryptorFilter(pp::PRNG(), localEncryptor, new StringSink(cipherLocal) ) ); StringSource ss1 (message, true, new PK_EncryptorFilter(pp::PRNG, localEncryptor, new StringSink(cipherLocal) ) );
string plainLocal; string plainLocal;
StringSource ss2 (cipherLocal, true, new PK_DecryptorFilter(pp::PRNG(), localDecryptor, new StringSink(plainLocal) ) ); StringSource ss2 (cipherLocal, true, new PK_DecryptorFilter(pp::PRNG, localDecryptor, new StringSink(plainLocal) ) );
// encrypt/decrypt with future // encrypt/decrypt with future
string cipherFuture; string cipherFuture;
StringSource ss3 (message, true, new PK_EncryptorFilter(pp::PRNG(), futureEncryptor, new StringSink(cipherFuture) ) ); StringSource ss3 (message, true, new PK_EncryptorFilter(pp::PRNG, futureEncryptor, new StringSink(cipherFuture) ) );
string plainFuture; string plainFuture;
StringSource ss4 (cipherFuture, true, new PK_DecryptorFilter(pp::PRNG(), futureDecryptor, new StringSink(plainFuture) ) ); StringSource ss4 (cipherFuture, true, new PK_DecryptorFilter(pp::PRNG, futureDecryptor, new StringSink(plainFuture) ) );
// decrypt local w/future // decrypt local w/future
string plainFutureFromLocal; string plainFutureFromLocal;
StringSource ss5 (cipherLocal, true, new PK_DecryptorFilter(pp::PRNG(), futureDecryptor, new StringSink(plainFutureFromLocal) ) ); StringSource ss5 (cipherLocal, true, new PK_DecryptorFilter(pp::PRNG, futureDecryptor, new StringSink(plainFutureFromLocal) ) );
// decrypt future w/local // decrypt future w/local
string plainLocalFromFuture; string plainLocalFromFuture;
StringSource ss6 (cipherFuture, true, new PK_DecryptorFilter(pp::PRNG(), localDecryptor, new StringSink(plainLocalFromFuture) ) ); StringSource ss6 (cipherFuture, true, new PK_DecryptorFilter(pp::PRNG, localDecryptor, new StringSink(plainLocalFromFuture) ) );
assert(plainLocal == message); BOOST_REQUIRE(plainLocal == message);
assert(plainFuture == plainLocal); BOOST_REQUIRE(plainFuture == plainLocal);
assert(plainFutureFromLocal == plainLocal); BOOST_REQUIRE(plainFutureFromLocal == plainLocal);
assert(plainLocalFromFuture == plainLocal); BOOST_REQUIRE(plainLocalFromFuture == plainLocal);
} }
BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
{ {
const int aesKeyLen = 16; const int aesKeyLen = 16;
assert(sizeof(char) == sizeof(byte)); BOOST_REQUIRE(sizeof(char) == sizeof(byte));
// generate test key // generate test key
AutoSeededRandomPool rng; AutoSeededRandomPool rng;
@ -250,7 +361,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
CTR_Mode<AES>::Encryption e; CTR_Mode<AES>::Encryption e;
e.SetKeyWithIV(key, key.size(), ctr); e.SetKeyWithIV(key, key.size(), ctr);
e.ProcessData(out, in, text.size()); e.ProcessData(out, in, text.size());
assert(text != original); BOOST_REQUIRE(text != original);
cipherCopy = text; cipherCopy = text;
} }
catch(CryptoPP::Exception& e) catch(CryptoPP::Exception& e)
@ -263,7 +374,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
CTR_Mode< AES >::Decryption d; CTR_Mode< AES >::Decryption d;
d.SetKeyWithIV(key, key.size(), ctr); d.SetKeyWithIV(key, key.size(), ctr);
d.ProcessData(out, in, text.size()); d.ProcessData(out, in, text.size());
assert(text == original); BOOST_REQUIRE(text == original);
} }
catch(CryptoPP::Exception& e) catch(CryptoPP::Exception& e)
{ {
@ -274,7 +385,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
// reencrypt ciphertext... // reencrypt ciphertext...
try try
{ {
assert(cipherCopy != text); BOOST_REQUIRE(cipherCopy != text);
in = (unsigned char*)&cipherCopy[0]; in = (unsigned char*)&cipherCopy[0];
out = (unsigned char*)&cipherCopy[0]; out = (unsigned char*)&cipherCopy[0];
@ -283,7 +394,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
e.ProcessData(out, in, text.size()); e.ProcessData(out, in, text.size());
// yep, ctr mode. // yep, ctr mode.
assert(cipherCopy == original); BOOST_REQUIRE(cipherCopy == original);
} }
catch(CryptoPP::Exception& e) catch(CryptoPP::Exception& e)
{ {
@ -295,7 +406,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr)
BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc) BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc)
{ {
const int aesKeyLen = 16; const int aesKeyLen = 16;
assert(sizeof(char) == sizeof(byte)); BOOST_REQUIRE(sizeof(char) == sizeof(byte));
AutoSeededRandomPool rng; AutoSeededRandomPool rng;
SecByteBlock key(0x00, aesKeyLen); SecByteBlock key(0x00, aesKeyLen);
@ -310,11 +421,11 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc)
CryptoPP::CBC_Mode<Rijndael>::Encryption cbcEncryption(key, key.size(), iv); CryptoPP::CBC_Mode<Rijndael>::Encryption cbcEncryption(key, key.size(), iv);
cbcEncryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); cbcEncryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size());
assert(string128 != plainOriginal); BOOST_REQUIRE(string128 != plainOriginal);
CBC_Mode<Rijndael>::Decryption cbcDecryption(key, key.size(), iv); CBC_Mode<Rijndael>::Decryption cbcDecryption(key, key.size(), iv);
cbcDecryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); cbcDecryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size());
assert(plainOriginal == string128); BOOST_REQUIRE(plainOriginal == string128);
// plaintext whose size isn't divisible by block size must use stream filter for padding // plaintext whose size isn't divisible by block size must use stream filter for padding
@ -324,10 +435,10 @@ BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc)
string cipher; string cipher;
StreamTransformationFilter* aesStream = new StreamTransformationFilter(cbcEncryption, new StringSink(cipher)); StreamTransformationFilter* aesStream = new StreamTransformationFilter(cbcEncryption, new StringSink(cipher));
StringSource source(string192, true, aesStream); StringSource source(string192, true, aesStream);
assert(cipher.size() == 32); BOOST_REQUIRE(cipher.size() == 32);
cbcDecryption.ProcessData((byte*)&cipher[0], (byte*)&string192[0], cipher.size()); cbcDecryption.ProcessData((byte*)&cipher[0], (byte*)&string192[0], cipher.size());
assert(string192 == plainOriginal); BOOST_REQUIRE(string192 == plainOriginal);
} }
BOOST_AUTO_TEST_CASE(eth_keypairs) BOOST_AUTO_TEST_CASE(eth_keypairs)
@ -340,14 +451,14 @@ BOOST_AUTO_TEST_CASE(eth_keypairs)
BOOST_REQUIRE(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075"))); BOOST_REQUIRE(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{ {
eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret()); eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret());
auto rlp = t.rlp(false); auto rlp = t.rlp(eth::WithoutSignature);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(eth::WithoutSignature);
rlp = t.rlp(true); rlp = t.rlp(eth::WithSignature);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(true); cnote << t.sha3(eth::WithSignature);
BOOST_REQUIRE(t.sender() == p.address()); BOOST_REQUIRE(t.sender() == p.address());
} }
@ -360,18 +471,18 @@ int cryptoTest()
secp256k1_start(); secp256k1_start();
KeyPair p(Secret(fromHex("3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4"))); KeyPair p(Secret(fromHex("3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4")));
assert(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f"))); BOOST_REQUIRE(p.pub() == Public(fromHex("97466f2b32bc3bb76d4741ae51cd1d8578b48d3f1e68da206d47321aec267ce78549b514e4453d74ef11b0cd5e4e4c364effddac8b51bcfc8de80682f952896f")));
assert(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075"))); BOOST_REQUIRE(p.address() == Address(fromHex("8a40bfaa73256b60764c1bf40675a99083efb075")));
{ {
eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret()); eth::Transaction t(1000, 0, 0, h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")), bytes(), 0, p.secret());
auto rlp = t.rlp(false); auto rlp = t.rlp(eth::WithoutSignature);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(eth::WithoutSignature);
rlp = t.rlp(true); rlp = t.rlp(eth::WithSignature);
cnote << RLP(rlp); cnote << RLP(rlp);
cnote << toHex(rlp); cnote << toHex(rlp);
cnote << t.sha3(true); cnote << t.sha3(eth::WithSignature);
assert(t.sender() == p.address()); assert(t.sender() == p.address());
} }
@ -397,8 +508,8 @@ int cryptoTest()
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): " << toHex(t.rlpString(false)) << endl; cout << "RLP(TX w/o SIG): " << toHex(t.rlp(false)) << endl;
std::string hmsg = sha3(t.rlpString(false), false); std::string hmsg = sha3(t.rlp(false), false);
cout << "SHA256(RLP(TX w/o SIG)): 0x" << toHex(hmsg) << endl; cout << "SHA256(RLP(TX w/o SIG)): 0x" << toHex(hmsg) << endl;
bytes privkey = sha3Bytes("123"); bytes privkey = sha3Bytes("123");

804
test/vmArithmeticTestFiller.json

File diff suppressed because it is too large

932
test/vmBitwiseLogicOperationTestFiller.json

File diff suppressed because it is too large

80
test/vmIOandFlowOperationsTestFiller.json

@ -12,7 +12,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6002600360045057", "code" : "0x6002600360045055",
"storage": {} "storage": {}
} }
}, },
@ -40,7 +40,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x5060026003600457", "code" : "0x5060026003600455",
"storage": {} "storage": {}
} }
}, },
@ -68,7 +68,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600260035157", "code" : "0x600260035155",
"storage": {} "storage": {}
} }
}, },
@ -96,7 +96,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600260035257", "code" : "0x600260035255",
"storage": {} "storage": {}
} }
}, },
@ -488,7 +488,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6023600058", "code" : "0x600056",
"storage": {} "storage": {}
} }
}, },
@ -516,7 +516,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60236007586001600257", "code" : "0x60236007566001600255",
"storage": {} "storage": {}
} }
}, },
@ -543,7 +543,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x602360085860015d600257", "code" : "0x602360075660015b600255",
"storage": {} "storage": {}
} }
}, },
@ -571,7 +571,63 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x602360075860015d600257", "code" : "0x602360085660015b600255",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"jump0_jumpdest2": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : 0,
"code" : "0x6023600a6008505660015b600255",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"jump0_jumpdest3": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : 0,
"code" : "0x6023600b6008505660015b600255",
"storage": {} "storage": {}
} }
}, },
@ -599,7 +655,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x602360016009596001600257", "code" : "0x602360016009576001600255",
"storage": {} "storage": {}
} }
}, },
@ -627,7 +683,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60236001600a5960015d600257", "code" : "0x60236001600a5760015b600255",
"storage": {} "storage": {}
} }
}, },
@ -655,7 +711,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x602360006009596001600257", "code" : "0x602360006009576001600255",
"storage": {} "storage": {}
} }
}, },
@ -683,7 +739,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff596002600357", "code" : "0x60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff576002600355",
"storage": {} "storage": {}
} }
}, },

134
test/vmPushDupSwapTestFiller.json

@ -12,7 +12,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60ff600357", "code" : "0x60ff600355",
"storage": {} "storage": {}
} }
}, },
@ -68,7 +68,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x61eeff600357", "code" : "0x61eeff600355",
"storage": {} "storage": {}
} }
}, },
@ -96,7 +96,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x62ddeeff600357", "code" : "0x62ddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -124,7 +124,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x63ccddeeff600357", "code" : "0x63ccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -152,7 +152,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x64bbccddeeff600357", "code" : "0x64bbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -180,7 +180,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x65aabbccddeeff600357", "code" : "0x65aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -208,7 +208,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6699aabbccddeeff600357", "code" : "0x6699aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -236,7 +236,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x678899aabbccddeeff600357", "code" : "0x678899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -264,7 +264,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x68778899aabbccddeeff600357", "code" : "0x68778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -292,7 +292,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6966778899aabbccddeeff600357", "code" : "0x6966778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -320,7 +320,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6a5566778899aabbccddeeff600357", "code" : "0x6a5566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -348,7 +348,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6b445566778899aabbccddeeff600357", "code" : "0x6b445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -376,7 +376,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6c33445566778899aabbccddeeff600357", "code" : "0x6c33445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -404,7 +404,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6d2233445566778899aabbccddeeff600357", "code" : "0x6d2233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -432,7 +432,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6e112233445566778899aabbccddeeff600357", "code" : "0x6e112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -460,7 +460,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6f10112233445566778899aabbccddeeff600357", "code" : "0x6f10112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -488,7 +488,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x70ff00112233445566778899aabbccddeeff600357", "code" : "0x70ff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -516,7 +516,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x71eeff00112233445566778899aabbccddeeff600357", "code" : "0x71eeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -544,7 +544,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x72ddeeff00112233445566778899aabbccddeeff600357", "code" : "0x72ddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -572,7 +572,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x73ccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x73ccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -600,7 +600,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x74bbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x74bbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -628,7 +628,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x75aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x75aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -656,7 +656,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7699aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7699aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -684,7 +684,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -712,7 +712,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x78778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x78778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -740,7 +740,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7966778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7966778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -769,7 +769,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7a5566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7a5566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -797,7 +797,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7b445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7b445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -825,7 +825,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7c33445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7c33445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -853,7 +853,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7d2233445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7d2233445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -881,7 +881,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7e112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7e112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -909,7 +909,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -937,7 +937,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7fff10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600357", "code" : "0x7fff10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff600355",
"storage": {} "storage": {}
} }
}, },
@ -965,7 +965,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff80600357", "code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff80600355",
"storage": {} "storage": {}
} }
}, },
@ -993,7 +993,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff81600357", "code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff81600355",
"storage": {} "storage": {}
} }
}, },
@ -1021,7 +1021,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6002600181600357", "code" : "0x6002600181600355",
"storage": {} "storage": {}
} }
}, },
@ -1049,7 +1049,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60036002600182600357", "code" : "0x60036002600182600355",
"storage": {} "storage": {}
} }
}, },
@ -1077,7 +1077,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600460036002600183600357", "code" : "0x600460036002600183600355",
"storage": {} "storage": {}
} }
}, },
@ -1105,7 +1105,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6005600460036002600184600357", "code" : "0x6005600460036002600184600355",
"storage": {} "storage": {}
} }
}, },
@ -1133,7 +1133,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60066005600460036002600185600357", "code" : "0x60066005600460036002600185600355",
"storage": {} "storage": {}
} }
}, },
@ -1161,7 +1161,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600760066005600460036002600186600357", "code" : "0x600760066005600460036002600186600355",
"storage": {} "storage": {}
} }
}, },
@ -1189,7 +1189,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6008600760066005600460036002600187600357", "code" : "0x6008600760066005600460036002600187600355",
"storage": {} "storage": {}
} }
}, },
@ -1217,7 +1217,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60096008600760066005600460036002600188600357", "code" : "0x60096008600760066005600460036002600188600355",
"storage": {} "storage": {}
} }
}, },
@ -1245,7 +1245,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600a60096008600760066005600460036002600189600357", "code" : "0x600a60096008600760066005600460036002600189600355",
"storage": {} "storage": {}
} }
}, },
@ -1273,7 +1273,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600b600a6009600860076006600560046003600260018a600357", "code" : "0x600b600a6009600860076006600560046003600260018a600355",
"storage": {} "storage": {}
} }
}, },
@ -1301,7 +1301,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600c600b600a6009600860076006600560046003600260018b600357", "code" : "0x600c600b600a6009600860076006600560046003600260018b600355",
"storage": {} "storage": {}
} }
}, },
@ -1329,7 +1329,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600d600c600b600a6009600860076006600560046003600260018c600357", "code" : "0x600d600c600b600a6009600860076006600560046003600260018c600355",
"storage": {} "storage": {}
} }
}, },
@ -1357,7 +1357,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600e600d600c600b600a6009600860076006600560046003600260018d600357", "code" : "0x600e600d600c600b600a6009600860076006600560046003600260018d600355",
"storage": {} "storage": {}
} }
}, },
@ -1385,7 +1385,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600f600e600d600c600b600a6009600860076006600560046003600260018e600357", "code" : "0x600f600e600d600c600b600a6009600860076006600560046003600260018e600355",
"storage": {} "storage": {}
} }
}, },
@ -1413,7 +1413,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6010600f600e600d600c600b600a6009600860076006600560046003600260018f600357", "code" : "0x6010600f600e600d600c600b600a6009600860076006600560046003600260018f600355",
"storage": {} "storage": {}
} }
}, },
@ -1441,7 +1441,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff60039057", "code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff60039055",
"storage": {} "storage": {}
} }
}, },
@ -1469,7 +1469,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff60039157", "code" : "0x7f10112233445566778899aabbccddeeff00112233445566778899aabbccddeeff60039155",
"storage": {} "storage": {}
} }
}, },
@ -1497,7 +1497,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6002600160039157", "code" : "0x6002600160039155",
"storage": {} "storage": {}
} }
}, },
@ -1525,7 +1525,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60036002600160039257", "code" : "0x60036002600160039255",
"storage": {} "storage": {}
} }
}, },
@ -1553,7 +1553,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600460036002600160039357", "code" : "0x600460036002600160039355",
"storage": {} "storage": {}
} }
}, },
@ -1581,7 +1581,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6005600460036002600160039457", "code" : "0x6005600460036002600160039455",
"storage": {} "storage": {}
} }
}, },
@ -1609,7 +1609,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60066005600460036002600160039557", "code" : "0x60066005600460036002600160039555",
"storage": {} "storage": {}
} }
}, },
@ -1637,7 +1637,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600760066005600460036002600160039657", "code" : "0x600760066005600460036002600160039655",
"storage": {} "storage": {}
} }
}, },
@ -1665,7 +1665,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6008600760066005600460036002600160039757", "code" : "0x6008600760066005600460036002600160039755",
"storage": {} "storage": {}
} }
}, },
@ -1693,7 +1693,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x60096008600760066005600460036002600160039857", "code" : "0x60096008600760066005600460036002600160039855",
"storage": {} "storage": {}
} }
}, },
@ -1721,7 +1721,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600a60096008600760066005600460036002600160039957", "code" : "0x600a60096008600760066005600460036002600160039955",
"storage": {} "storage": {}
} }
}, },
@ -1749,7 +1749,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600b600a60096008600760066005600460036002600160039a57", "code" : "0x600b600a60096008600760066005600460036002600160039a55",
"storage": {} "storage": {}
} }
}, },
@ -1777,7 +1777,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600c600b600a60096008600760066005600460036002600160039b57", "code" : "0x600c600b600a60096008600760066005600460036002600160039b55",
"storage": {} "storage": {}
} }
}, },
@ -1805,7 +1805,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600d600c600b600a60096008600760066005600460036002600160039c57", "code" : "0x600d600c600b600a60096008600760066005600460036002600160039c55",
"storage": {} "storage": {}
} }
}, },
@ -1833,7 +1833,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600e600d600c600b600a60096008600760066005600460036002600160039d57", "code" : "0x600e600d600c600b600a60096008600760066005600460036002600160039d55",
"storage": {} "storage": {}
} }
}, },
@ -1861,7 +1861,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x600f600e600d600c600b600a60096008600760066005600460036002600160039e57", "code" : "0x600f600e600d600c600b600a60096008600760066005600460036002600160039e55",
"storage": {} "storage": {}
} }
}, },
@ -1889,7 +1889,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "0x6010600f600e600d600c600b600a60096008600760066005600460036002600160039f57", "code" : "0x6010600f600e600d600c600b600a60096008600760066005600460036002600160039f55",
"storage": {} "storage": {}
} }
}, },

12
test/vmSha3TestFiller.json

@ -111,7 +111,7 @@
} }
}, },
"sha3_3": { "sha3_4": {
"env" : { "env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0", "currentNumber" : "0",
@ -139,7 +139,7 @@
} }
}, },
"sha3_4": { "sha3_5": {
"env" : { "env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0", "currentNumber" : "0",
@ -152,7 +152,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 100)}", "code" : "{ [[ 0 ]] (SHA3 10000 0xfffffffff )}",
"storage": {} "storage": {}
} }
}, },
@ -167,7 +167,7 @@
} }
}, },
"sha3_5": { "sha3_6": {
"env" : { "env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0", "currentNumber" : "0",
@ -180,7 +180,7 @@
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000", "balance" : "1000000000000000000",
"nonce" : 0, "nonce" : 0,
"code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}", "code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}",
"storage": {} "storage": {}
} }
}, },
@ -193,5 +193,5 @@
"gasPrice" : "100000000000000", "gasPrice" : "100000000000000",
"gas" : "10000" "gas" : "10000"
} }
}, }
} }

Loading…
Cancel
Save