Browse Source

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

cl-refactor
Paweł Bylica 10 years ago
parent
commit
cd27cd1b6c
  1. 4
      libethcore/BlockInfo.cpp
  2. 5
      libethereum/BlockChain.cpp
  3. 4
      libethereum/Client.cpp
  4. 3
      libethereum/Transaction.cpp
  5. 3
      libevm/VM.cpp
  6. 3
      libevmcore/Assembly.cpp
  7. 13
      libevmcore/Assembly.h
  8. 24
      libevmcore/SourceLocation.h
  9. 63
      libjsqrc/ethereumjs/.jshintrc
  10. 2
      libjsqrc/ethereumjs/README.md
  11. 5
      libjsqrc/ethereumjs/bower.json
  12. 29
      libjsqrc/ethereumjs/dist/ethereum.js
  13. 18
      libjsqrc/ethereumjs/dist/ethereum.js.map
  14. 2
      libjsqrc/ethereumjs/dist/ethereum.min.js
  15. 4
      libjsqrc/ethereumjs/gulpfile.js
  16. 2
      libjsqrc/ethereumjs/lib/abi.js
  17. 2
      libjsqrc/ethereumjs/lib/contract.js
  18. 4
      libjsqrc/ethereumjs/lib/event.js
  19. 2
      libjsqrc/ethereumjs/lib/filter.js
  20. 1
      libjsqrc/ethereumjs/lib/formatters.js
  21. 11
      libjsqrc/ethereumjs/lib/requestmanager.js
  22. 1
      libjsqrc/ethereumjs/lib/utils.js
  23. 4
      libjsqrc/ethereumjs/lib/web3.js
  24. 1
      libjsqrc/ethereumjs/package.json
  25. 96
      libsolidity/AST.h
  26. 2
      libsolidity/ASTPrinter.cpp
  27. 36
      libsolidity/Compiler.cpp
  28. 6
      libsolidity/Compiler.h
  29. 37
      libsolidity/CompilerContext.cpp
  30. 28
      libsolidity/CompilerContext.h
  31. 4
      libsolidity/Exceptions.h
  32. 632
      libsolidity/ExpressionCompiler.cpp
  33. 126
      libsolidity/ExpressionCompiler.h
  34. 223
      libsolidity/LValue.cpp
  35. 112
      libsolidity/LValue.h
  36. 16
      libsolidity/Parser.cpp
  37. 4
      libsolidity/Parser.h
  38. 10
      libsolidity/Scanner.h
  39. 4
      libsolidity/SourceReferenceFormatter.cpp
  40. 4
      libsolidity/SourceReferenceFormatter.h
  41. 4
      mix/CodeHighlighter.cpp
  42. 5
      mix/CodeHighlighter.h
  43. 3
      mix/CodeModel.cpp
  44. 47
      mix/FileIo.cpp
  45. 1
      mix/FileIo.h
  46. 2
      mix/qml/NewProjectDialog.qml
  47. 129
      test/Assembly.cpp
  48. 3
      test/SolidityExpressionCompiler.cpp
  49. 2
      test/SolidityInterface.cpp
  50. 50
      test/TestHelper.cpp
  51. 5
      test/block.cpp
  52. 1533
      test/stMemoryTestFiller.json
  53. 352
      test/stQuadraticComplexityTestFiller.json
  54. 55
      test/stSolidityTestFiller.json
  55. 1015
      test/stSystemOperationsTestFiller.json
  56. 10
      test/stTransactionTestFiller.json
  57. 23
      test/state.cpp
  58. 19
      test/transaction.cpp
  59. 169
      test/ttTransactionTestFiller.json
  60. 6
      test/vm.cpp
  61. 142
      test/vmArithmeticTestFiller.json
  62. 168
      test/vmEnvironmentalInfoTestFiller.json
  63. 238
      test/vmSha3TestFiller.json

4
libethcore/BlockInfo.cpp

@ -134,7 +134,7 @@ void BlockInfo::populate(bytesConstRef _block, bool _checkNonce)
RLP header = root[0];
if (!header.isList())
BOOST_THROW_EXCEPTION(InvalidBlockFormat(0,header.data()) << errinfo_comment("block header needs to be a list"));
BOOST_THROW_EXCEPTION(InvalidBlockFormat(0, header.data()) << errinfo_comment("block header needs to be a list"));
populateFromHeader(header, _checkNonce);
if (!root[1].isList())
@ -191,7 +191,7 @@ u256 BlockInfo::calculateDifficulty(BlockInfo const& _parent) const
if (!parentHash)
return c_genesisDifficulty;
else
return timestamp >= _parent.timestamp + (c_protocolVersion == 49 ? 5 : 8) ? _parent.difficulty - (_parent.difficulty >> 10) : (_parent.difficulty + (_parent.difficulty >> 10));
return max<u256>(1024, timestamp >= _parent.timestamp + (c_protocolVersion == 49 ? 5 : 8) ? _parent.difficulty - (_parent.difficulty >> 10) : (_parent.difficulty + (_parent.difficulty >> 10)));
}
void BlockInfo::verifyParent(BlockInfo const& _parent) const

5
libethereum/BlockChain.cpp

@ -209,6 +209,11 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
try
#endif
{
RLP blockRLP(_block);
if (!blockRLP.isList())
BOOST_THROW_EXCEPTION(InvalidBlockFormat(0, blockRLP.data()) << errinfo_comment("block header needs to be a list"));
bi.populate(&_block);
bi.verifyInternals(&_block);
}

4
libethereum/Client.cpp

@ -257,7 +257,9 @@ LocalisedLogEntries Client::peekWatch(unsigned _watchId) const
Guard l(m_filterLock);
try {
cdebug << "peekWatch" << _watchId;
auto& w = m_watches.at(_watchId);
cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
w.lastPoll = chrono::system_clock::now();
return w.changes;
} catch (...) {}
@ -271,7 +273,9 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId)
LocalisedLogEntries ret;
try {
cdebug << "checkWatch" << _watchId;
auto& w = m_watches.at(_watchId);
cdebug << "lastPoll updated to " << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
std::swap(ret, w.changes);
w.lastPoll = chrono::system_clock::now();
} catch (...) {}

3
libethereum/Transaction.cpp

@ -36,6 +36,9 @@ Transaction::Transaction(bytesConstRef _rlpData, CheckSignature _checkSig)
RLP rlp(_rlpData);
try
{
if (!rlp.isList())
BOOST_THROW_EXCEPTION(BadRLP() << errinfo_comment("transaction RLP must be a list"));
m_nonce = rlp[field = 0].toInt<u256>();
m_gasPrice = rlp[field = 1].toInt<u256>();
m_gas = rlp[field = 2].toInt<u256>();

3
libevm/VM.cpp

@ -38,8 +38,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
auto gasForMem = [](bigint _size) -> bigint
{
bigint s = _size / 32;
// return (bigint)c_memoryGas * (s + s * s / 1024);
return (bigint)c_memoryGas * s;
return (bigint)c_memoryGas * (s + s * s / 1024);
};
if (m_jumpDests.empty())

3
libevmcore/Assembly.cpp

@ -229,10 +229,11 @@ ostream& Assembly::streamRLP(ostream& _out, string const& _prefix) const
return _out;
}
AssemblyItem const& Assembly::append(AssemblyItem const& _i)
AssemblyItem const& Assembly::append(AssemblyItem const& _i, SourceLocation const& _location)
{
m_deposit += _i.deposit();
m_items.push_back(_i);
m_items.back().setLocation(_location);
return back();
}

13
libevmcore/Assembly.h

@ -24,6 +24,7 @@
#include <iostream>
#include <sstream>
#include <libdevcore/Common.h>
#include <libevmcore/SourceLocation.h>
#include <libevmcore/Instruction.h>
#include "Exceptions.h"
@ -57,10 +58,13 @@ public:
int deposit() const;
bool match(AssemblyItem const& _i) const { return _i.m_type == UndefinedItem || (m_type == _i.m_type && (m_type != Operation || m_data == _i.m_data)); }
void setLocation(SourceLocation const& _location) { m_location = _location;}
SourceLocation const& getLocation() const { return m_location; }
private:
AssemblyItemType m_type;
u256 m_data;
SourceLocation m_location;
};
using AssemblyItems = std::vector<AssemblyItem>;
@ -84,9 +88,9 @@ public:
AssemblyItem append() { return append(newTag()); }
void append(Assembly const& _a);
void append(Assembly const& _a, int _deposit);
AssemblyItem const& append(AssemblyItem const& _i);
AssemblyItem const& append(std::string const& _data) { return append(newPushString(_data)); }
AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); }
AssemblyItem const& append(AssemblyItem const& _i, SourceLocation const& _location = SourceLocation());
AssemblyItem const& append(std::string const& _data, SourceLocation const& _location = SourceLocation()) { return append(newPushString(_data), _location); }
AssemblyItem const& append(bytes const& _data, SourceLocation const& _location = SourceLocation()) { return append(newData(_data), _location); }
AssemblyItem appendSubSize(Assembly const& _a) { auto ret = newSub(_a); append(newPushSubSize(ret.data())); return ret; }
/// Pushes the final size of the current assembly itself. Use this when the code is modified
/// after compilation and CODESIZE is not an option.
@ -99,7 +103,8 @@ public:
template <class T> Assembly& operator<<(T const& _d) { append(_d); return *this; }
AssemblyItem const& back() { return m_items.back(); }
AssemblyItems const& getItems() const { return m_items; }
AssemblyItem const& back() const { return m_items.back(); }
std::string backString() const { return m_items.size() && m_items.back().m_type == PushString ? m_strings.at((h256)m_items.back().m_data) : std::string(); }
void onePath() { if (asserts(!m_totalDeposit && !m_baseDeposit)) BOOST_THROW_EXCEPTION(InvalidDeposit()); m_baseDeposit = m_deposit; m_totalDeposit = INT_MAX; }

24
libsolidity/BaseTypes.h → libevmcore/SourceLocation.h

@ -15,9 +15,9 @@
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @author Christian <c@ethdev.com>
* @date 2014
* Some elementary types for the parser.
* @author Lefteris Karapetsas <lefteris@ethdev.com>
* @date 2015
* Represents a location in a source file
*/
#pragma once
@ -28,18 +28,23 @@
namespace dev
{
namespace solidity
{
/**
* Representation of an interval of source positions.
* The interval includes start and excludes end.
*/
struct Location
struct SourceLocation
{
Location(int _start, int _end, std::shared_ptr<std::string const> _sourceName):
SourceLocation(int _start, int _end, std::shared_ptr<std::string const> _sourceName):
start(_start), end(_end), sourceName(_sourceName) { }
Location(): start(-1), end(-1) { }
SourceLocation(): start(-1), end(-1) { }
SourceLocation(SourceLocation const& _other):
start(_other.start), end(_other.end), sourceName(_other.sourceName) {}
SourceLocation& operator=(SourceLocation const& _other) { start = _other.start; end = _other.end; sourceName = _other.sourceName; return *this;}
bool operator==(SourceLocation const& _other) const { return start == _other.start && end == _other.end;}
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }
bool isEmpty() const { return start == -1 && end == -1; }
@ -49,7 +54,7 @@ struct Location
};
/// Stream output for Location (used e.g. in boost exceptions).
inline std::ostream& operator<<(std::ostream& _out, Location const& _location)
inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location)
{
if (_location.isEmpty())
return _out << "NO_LOCATION_SPECIFIED";
@ -57,4 +62,3 @@ inline std::ostream& operator<<(std::ostream& _out, Location const& _location)
}
}
}

63
libjsqrc/ethereumjs/.jshintrc

@ -1,50 +1,19 @@
{
"predef": [
"console",
"require",
"equal",
"test",
"testBoth",
"testWithDefault",
"raises",
"deepEqual",
"start",
"stop",
"ok",
"strictEqual",
"module",
"expect",
"reject",
"impl"
],
"esnext": true,
"proto": true,
"node" : true,
"browser" : true,
"browserify" : true,
"boss" : true,
"curly": false,
"debug": true,
"devel": true,
"browserify": true,
"bitwise": true,
"camelcase": true,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"freeze": true,
"funcscope": false,
"maxcomplexity": 4, /* our target is 3! */
"maxdepth": 3,
"maxerr": 50,
/*"maxlen": 80*/ /*this should be our goal*/
"maxparams": 3,
"nonew": true,
"unused": true,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"shadow": true,
"eqnull": true
}
"predef": [
"console"
]
}

2
libjsqrc/ethereumjs/README.md

@ -1,7 +1,7 @@
# Ethereum JavaScript API
This is the Ethereum compatible [JavaScript API](https://github.com/ethereum/wiki/wiki/JavaScript-API)
which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC) spec. It's available on npm as a node module and also for bower and component as an embeddable js
which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC) spec. It's available on npm as a node module and also for bower and component as an embeddable js
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] [![dev dependency status][dep-dev-image]][dep-dev-url][![Coverage Status][coveralls-image]][coveralls-url]

5
libjsqrc/ethereumjs/bower.json

@ -3,7 +3,10 @@
"namespace": "ethereum",
"version": "0.0.15",
"description": "Ethereum Compatible JavaScript API",
"main": ["./dist/ethereum.js", "./dist/ethereum.min.js"],
"main": [
"./dist/ethereum.js",
"./dist/ethereum.min.js"
],
"dependencies": {
"bignumber.js": ">=2.0.0"
},

29
libjsqrc/ethereumjs/dist/ethereum.js

@ -53,7 +53,6 @@ var inputTypes = types.inputTypes();
/// @returns bytes representation of input params
var formatInput = function (inputs, params) {
var bytes = "";
var padding = c.ETH_PADDING * 2;
/// first we iterate in search for dynamic
inputs.forEach(function (input, index) {
@ -110,6 +109,7 @@ var formatOutput = function (outs, output) {
output = output.slice(dynamicPartLength);
outs.forEach(function (out, i) {
/*jshint maxcomplexity:6 */
var typeMatch = false;
for (var j = 0; j < outputTypes.length && !typeMatch; j++) {
typeMatch = outputTypes[j].type(outs[i].type);
@ -296,7 +296,6 @@ var web3 = require('./web3');
var abi = require('./abi');
var utils = require('./utils');
var eventImpl = require('./event');
var filter = require('./filter');
var exportNatspecGlobals = function (vars) {
// it's used byt natspec.js
@ -342,6 +341,7 @@ var addFunctionsToContract = function (contract, desc, address) {
var typeName = utils.extractTypeName(method.name);
var impl = function () {
/*jshint maxcomplexity:7 */
var params = Array.prototype.slice.call(arguments);
var signature = abi.signatureFromAscii(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params);
@ -489,7 +489,7 @@ var contract = function (address, desc) {
module.exports = contract;
},{"./abi":1,"./event":6,"./filter":7,"./utils":15,"./web3":17}],4:[function(require,module,exports){
},{"./abi":1,"./event":6,"./utils":15,"./web3":17}],4:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -697,9 +697,9 @@ var getArgumentsObject = function (inputs, indexed, notIndexed) {
return inputs.reduce(function (acc, current) {
var value;
if (current.indexed)
value = indexed.splice(0, 1)[0];
value = indexedCopy.splice(0, 1)[0];
else
value = notIndexed.splice(0, 1)[0];
value = notIndexedCopy.splice(0, 1)[0];
acc[current.name] = value;
return acc;
@ -847,7 +847,7 @@ var filter = function(options, implementation, formatter) {
return implementation.getMessages(filterId);
};
var uninstall = function (callback) {
var uninstall = function () {
implementation.stopPolling(filterId);
implementation.uninstallFilter(filterId);
callbacks = [];
@ -909,6 +909,7 @@ var padLeft = function (string, chars, sign) {
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
/*jshint maxcomplexity:7 */
var padding = c.ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')
@ -1210,6 +1211,7 @@ var c = require('./const');
*/
var requestManager = function() {
var polls = [];
var timeout = null;
var provider;
var send = function (data) {
@ -1234,9 +1236,11 @@ var requestManager = function() {
provider = p;
};
/*jshint maxparams:4 */
var startPolling = function (data, pollId, callback, uninstall) {
polls.push({data: data, id: pollId, callback: callback, uninstall: uninstall});
};
/*jshint maxparams:3 */
var stopPolling = function (pollId) {
for (var i = polls.length; i--;) {
@ -1252,6 +1256,12 @@ var requestManager = function() {
poll.uninstall(poll.id);
});
polls = [];
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
poll();
};
var poll = function () {
@ -1262,7 +1272,7 @@ var requestManager = function() {
}
data.callback(result);
});
setTimeout(poll, c.ETH_POLLING_TIMEOUT);
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT);
};
poll();
@ -1509,6 +1519,7 @@ var filterEvents = function (json) {
/// TODO: use BigNumber.js to parse int
/// TODO: add tests for it!
var toEth = function (str) {
/*jshint maxcomplexity:7 */
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;
var unit = 0;
var units = c.ETH_UNITS;
@ -1677,12 +1688,14 @@ var setupProperties = function (obj, properties) {
});
};
/*jshint maxparams:4 */
var startPolling = function (method, id, callback, uninstall) {
web3.manager.startPolling({
method: method,
params: [id]
}, id, callback, uninstall);
};
/*jshint maxparams:3 */
var stopPolling = function (id) {
web3.manager.stopPolling(id);
@ -1740,12 +1753,14 @@ var web3 = {
/// @param indexed is optional, this is an object with optional event indexed params
/// @param options is optional, this is an object with optional event options ('max'...)
/// TODO: fix it, 4 params? no way
/*jshint maxparams:4 */
watch: function (fil, indexed, options, formatter) {
if (fil._isEvent) {
return fil(indexed, options);
}
return filter(fil, ethWatch, formatter);
}
/*jshint maxparams:3 */
},
/// db object prototype

18
libjsqrc/ethereumjs/dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/dist/ethereum.min.js

File diff suppressed because one or more lines are too long

4
libjsqrc/ethereumjs/gulpfile.js

@ -10,8 +10,6 @@ var browserify = require('browserify');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var envify = require('envify/custom');
var unreach = require('unreachable-branch-transform');
var source = require('vinyl-source-stream');
var exorcist = require('exorcist');
var bower = require('bower');
@ -23,7 +21,7 @@ var dst = 'ethereum';
var browserifyOptions = {
debug: true,
insert_global_vars: false,
insert_global_vars: false, // jshint ignore:line
detectGlobals: false,
bundleExternal: false
};

2
libjsqrc/ethereumjs/lib/abi.js

@ -52,7 +52,6 @@ var inputTypes = types.inputTypes();
/// @returns bytes representation of input params
var formatInput = function (inputs, params) {
var bytes = "";
var padding = c.ETH_PADDING * 2;
/// first we iterate in search for dynamic
inputs.forEach(function (input, index) {
@ -109,6 +108,7 @@ var formatOutput = function (outs, output) {
output = output.slice(dynamicPartLength);
outs.forEach(function (out, i) {
/*jshint maxcomplexity:6 */
var typeMatch = false;
for (var j = 0; j < outputTypes.length && !typeMatch; j++) {
typeMatch = outputTypes[j].type(outs[i].type);

2
libjsqrc/ethereumjs/lib/contract.js

@ -24,7 +24,6 @@ var web3 = require('./web3');
var abi = require('./abi');
var utils = require('./utils');
var eventImpl = require('./event');
var filter = require('./filter');
var exportNatspecGlobals = function (vars) {
// it's used byt natspec.js
@ -70,6 +69,7 @@ var addFunctionsToContract = function (contract, desc, address) {
var typeName = utils.extractTypeName(method.name);
var impl = function () {
/*jshint maxcomplexity:7 */
var params = Array.prototype.slice.call(arguments);
var signature = abi.signatureFromAscii(method.name);
var parsed = inputParser[displayName][typeName].apply(null, params);

4
libjsqrc/ethereumjs/lib/event.js

@ -81,9 +81,9 @@ var getArgumentsObject = function (inputs, indexed, notIndexed) {
return inputs.reduce(function (acc, current) {
var value;
if (current.indexed)
value = indexed.splice(0, 1)[0];
value = indexedCopy.splice(0, 1)[0];
else
value = notIndexed.splice(0, 1)[0];
value = notIndexedCopy.splice(0, 1)[0];
acc[current.name] = value;
return acc;

2
libjsqrc/ethereumjs/lib/filter.js

@ -93,7 +93,7 @@ var filter = function(options, implementation, formatter) {
return implementation.getMessages(filterId);
};
var uninstall = function (callback) {
var uninstall = function () {
implementation.stopPolling(filterId);
implementation.uninstallFilter(filterId);
callbacks = [];

1
libjsqrc/ethereumjs/lib/formatters.js

@ -40,6 +40,7 @@ var padLeft = function (string, chars, sign) {
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
/*jshint maxcomplexity:7 */
var padding = c.ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')

11
libjsqrc/ethereumjs/lib/requestmanager.js

@ -33,6 +33,7 @@ var c = require('./const');
*/
var requestManager = function() {
var polls = [];
var timeout = null;
var provider;
var send = function (data) {
@ -57,9 +58,11 @@ var requestManager = function() {
provider = p;
};
/*jshint maxparams:4 */
var startPolling = function (data, pollId, callback, uninstall) {
polls.push({data: data, id: pollId, callback: callback, uninstall: uninstall});
};
/*jshint maxparams:3 */
var stopPolling = function (pollId) {
for (var i = polls.length; i--;) {
@ -75,6 +78,12 @@ var requestManager = function() {
poll.uninstall(poll.id);
});
polls = [];
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
poll();
};
var poll = function () {
@ -85,7 +94,7 @@ var requestManager = function() {
}
data.callback(result);
});
setTimeout(poll, c.ETH_POLLING_TIMEOUT);
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT);
};
poll();

1
libjsqrc/ethereumjs/lib/utils.js

@ -107,6 +107,7 @@ var filterEvents = function (json) {
/// TODO: use BigNumber.js to parse int
/// TODO: add tests for it!
var toEth = function (str) {
/*jshint maxcomplexity:7 */
var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;
var unit = 0;
var units = c.ETH_UNITS;

4
libjsqrc/ethereumjs/lib/web3.js

@ -80,12 +80,14 @@ var setupProperties = function (obj, properties) {
});
};
/*jshint maxparams:4 */
var startPolling = function (method, id, callback, uninstall) {
web3.manager.startPolling({
method: method,
params: [id]
}, id, callback, uninstall);
};
/*jshint maxparams:3 */
var stopPolling = function (id) {
web3.manager.stopPolling(id);
@ -143,12 +145,14 @@ var web3 = {
/// @param indexed is optional, this is an object with optional event indexed params
/// @param options is optional, this is an object with optional event options ('max'...)
/// TODO: fix it, 4 params? no way
/*jshint maxparams:4 */
watch: function (fil, indexed, options, formatter) {
if (fil._isEvent) {
return fil(indexed, options);
}
return filter(fil, ethWatch, formatter);
}
/*jshint maxparams:3 */
},
/// db object prototype

1
libjsqrc/ethereumjs/package.json

@ -9,7 +9,6 @@
},
"dependencies": {
"bignumber.js": ">=2.0.0",
"ws": "*",
"xmlhttprequest": "*"
},
"devDependencies": {

96
libsolidity/AST.h

@ -27,9 +27,9 @@
#include <vector>
#include <memory>
#include <boost/noncopyable.hpp>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/Utils.h>
#include <libsolidity/ASTForward.h>
#include <libsolidity/BaseTypes.h>
#include <libsolidity/Token.h>
#include <libsolidity/Types.h>
#include <libsolidity/Exceptions.h>
@ -51,7 +51,7 @@ class ASTConstVisitor;
class ASTNode: private boost::noncopyable
{
public:
explicit ASTNode(Location const& _location): m_location(_location) {}
explicit ASTNode(SourceLocation const& _location): m_location(_location) {}
virtual ~ASTNode() {}
@ -71,7 +71,7 @@ public:
}
/// Returns the source code location of this node.
Location const& getLocation() const { return m_location; }
SourceLocation const& getLocation() const { return m_location; }
/// Creates a @ref TypeError exception and decorates it with the location of the node and
/// the given description
@ -85,7 +85,7 @@ public:
///@}
private:
Location m_location;
SourceLocation m_location;
};
/**
@ -94,7 +94,7 @@ private:
class SourceUnit: public ASTNode
{
public:
SourceUnit(Location const& _location, std::vector<ASTPointer<ASTNode>> const& _nodes):
SourceUnit(SourceLocation const& _location, std::vector<ASTPointer<ASTNode>> const& _nodes):
ASTNode(_location), m_nodes(_nodes) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -114,7 +114,7 @@ private:
class ImportDirective: public ASTNode
{
public:
ImportDirective(Location const& _location, ASTPointer<ASTString> const& _identifier):
ImportDirective(SourceLocation const& _location, ASTPointer<ASTString> const& _identifier):
ASTNode(_location), m_identifier(_identifier) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -135,7 +135,7 @@ public:
/// Visibility ordered from restricted to unrestricted.
enum class Visibility { Default, Private, Internal, Public, External };
Declaration(Location const& _location, ASTPointer<ASTString> const& _name,
Declaration(SourceLocation const& _location, ASTPointer<ASTString> const& _name,
Visibility _visibility = Visibility::Default):
ASTNode(_location), m_name(_name), m_visibility(_visibility), m_scope(nullptr) {}
@ -205,7 +205,7 @@ protected:
class ContractDefinition: public Declaration, public Documented
{
public:
ContractDefinition(Location const& _location,
ContractDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
std::vector<ASTPointer<InheritanceSpecifier>> const& _baseContracts,
@ -278,7 +278,7 @@ private:
class InheritanceSpecifier: public ASTNode
{
public:
InheritanceSpecifier(Location const& _location, ASTPointer<Identifier> const& _baseName,
InheritanceSpecifier(SourceLocation const& _location, ASTPointer<Identifier> const& _baseName,
std::vector<ASTPointer<Expression>> _arguments):
ASTNode(_location), m_baseName(_baseName), m_arguments(_arguments) {}
@ -298,7 +298,7 @@ private:
class StructDefinition: public Declaration
{
public:
StructDefinition(Location const& _location,
StructDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
std::vector<ASTPointer<VariableDeclaration>> const& _members):
Declaration(_location, _name), m_members(_members) {}
@ -323,7 +323,7 @@ private:
class EnumDefinition: public Declaration
{
public:
EnumDefinition(Location const& _location,
EnumDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
std::vector<ASTPointer<EnumValue>> const& _members):
Declaration(_location, _name), m_members(_members) {}
@ -344,7 +344,7 @@ private:
class EnumValue: public Declaration
{
public:
EnumValue(Location const& _location,
EnumValue(SourceLocation const& _location,
ASTPointer<ASTString> const& _name):
Declaration(_location, _name) {}
@ -361,7 +361,7 @@ class EnumValue: public Declaration
class ParameterList: public ASTNode
{
public:
ParameterList(Location const& _location,
ParameterList(SourceLocation const& _location,
std::vector<ASTPointer<VariableDeclaration>> const& _parameters):
ASTNode(_location), m_parameters(_parameters) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -376,7 +376,7 @@ private:
class FunctionDefinition: public Declaration, public VariableScope, public Documented
{
public:
FunctionDefinition(Location const& _location, ASTPointer<ASTString> const& _name,
FunctionDefinition(SourceLocation const& _location, ASTPointer<ASTString> const& _name,
Declaration::Visibility _visibility, bool _isConstructor,
ASTPointer<ASTString> const& _documentation,
ASTPointer<ParameterList> const& _parameters,
@ -431,7 +431,7 @@ private:
class VariableDeclaration: public Declaration
{
public:
VariableDeclaration(Location const& _location, ASTPointer<TypeName> const& _type,
VariableDeclaration(SourceLocation const& _location, ASTPointer<TypeName> const& _type,
ASTPointer<ASTString> const& _name, ASTPointer<Expression> _value,
Visibility _visibility,
bool _isStateVar = false, bool _isIndexed = false):
@ -476,7 +476,7 @@ private:
class ModifierDefinition: public Declaration, public VariableScope, public Documented
{
public:
ModifierDefinition(Location const& _location,
ModifierDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<ParameterList> const& _parameters,
@ -506,7 +506,7 @@ private:
class ModifierInvocation: public ASTNode
{
public:
ModifierInvocation(Location const& _location, ASTPointer<Identifier> const& _name,
ModifierInvocation(SourceLocation const& _location, ASTPointer<Identifier> const& _name,
std::vector<ASTPointer<Expression>> _arguments):
ASTNode(_location), m_modifierName(_name), m_arguments(_arguments) {}
@ -529,7 +529,7 @@ private:
class EventDefinition: public Declaration, public VariableScope, public Documented
{
public:
EventDefinition(Location const& _location,
EventDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<ParameterList> const& _parameters):
@ -560,7 +560,7 @@ class MagicVariableDeclaration: public Declaration
{
public:
MagicVariableDeclaration(ASTString const& _name, std::shared_ptr<Type const> const& _type):
Declaration(Location(), std::make_shared<ASTString>(_name)), m_type(_type) {}
Declaration(SourceLocation(), std::make_shared<ASTString>(_name)), m_type(_type) {}
virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_comment("MagicVariableDeclaration used inside real AST.")); }
virtual void accept(ASTConstVisitor&) const override { BOOST_THROW_EXCEPTION(InternalCompilerError()
@ -581,7 +581,7 @@ private:
class TypeName: public ASTNode
{
public:
explicit TypeName(Location const& _location): ASTNode(_location) {}
explicit TypeName(SourceLocation const& _location): ASTNode(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -598,7 +598,7 @@ public:
class ElementaryTypeName: public TypeName
{
public:
explicit ElementaryTypeName(Location const& _location, Token::Value _type):
explicit ElementaryTypeName(SourceLocation const& _location, Token::Value _type):
TypeName(_location), m_type(_type)
{
solAssert(Token::isElementaryTypeName(_type), "");
@ -619,7 +619,7 @@ private:
class UserDefinedTypeName: public TypeName
{
public:
UserDefinedTypeName(Location const& _location, ASTPointer<ASTString> const& _name):
UserDefinedTypeName(SourceLocation const& _location, ASTPointer<ASTString> const& _name):
TypeName(_location), m_name(_name), m_referencedDeclaration(nullptr) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -641,7 +641,7 @@ private:
class Mapping: public TypeName
{
public:
Mapping(Location const& _location, ASTPointer<ElementaryTypeName> const& _keyType,
Mapping(SourceLocation const& _location, ASTPointer<ElementaryTypeName> const& _keyType,
ASTPointer<TypeName> const& _valueType):
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -662,7 +662,7 @@ private:
class ArrayTypeName: public TypeName
{
public:
ArrayTypeName(Location const& _location, ASTPointer<TypeName> const& _baseType,
ArrayTypeName(SourceLocation const& _location, ASTPointer<TypeName> const& _baseType,
ASTPointer<Expression> const& _length):
TypeName(_location), m_baseType(_baseType), m_length(_length) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -689,7 +689,7 @@ private:
class Statement: public ASTNode
{
public:
explicit Statement(Location const& _location): ASTNode(_location) {}
explicit Statement(SourceLocation const& _location): ASTNode(_location) {}
/// Check all type requirements, throws exception if some requirement is not met.
/// This includes checking that operators are applicable to their arguments but also that
@ -703,7 +703,7 @@ public:
class Block: public Statement
{
public:
Block(Location const& _location, std::vector<ASTPointer<Statement>> const& _statements):
Block(SourceLocation const& _location, std::vector<ASTPointer<Statement>> const& _statements):
Statement(_location), m_statements(_statements) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -721,7 +721,7 @@ private:
class PlaceholderStatement: public Statement
{
public:
PlaceholderStatement(Location const& _location): Statement(_location) {}
PlaceholderStatement(SourceLocation const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -736,7 +736,7 @@ public:
class IfStatement: public Statement
{
public:
IfStatement(Location const& _location, ASTPointer<Expression> const& _condition,
IfStatement(SourceLocation const& _location, ASTPointer<Expression> const& _condition,
ASTPointer<Statement> const& _trueBody, ASTPointer<Statement> const& _falseBody):
Statement(_location),
m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {}
@ -761,13 +761,13 @@ private:
class BreakableStatement: public Statement
{
public:
BreakableStatement(Location const& _location): Statement(_location) {}
BreakableStatement(SourceLocation const& _location): Statement(_location) {}
};
class WhileStatement: public BreakableStatement
{
public:
WhileStatement(Location const& _location, ASTPointer<Expression> const& _condition,
WhileStatement(SourceLocation const& _location, ASTPointer<Expression> const& _condition,
ASTPointer<Statement> const& _body):
BreakableStatement(_location), m_condition(_condition), m_body(_body) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -788,7 +788,7 @@ private:
class ForStatement: public BreakableStatement
{
public:
ForStatement(Location const& _location,
ForStatement(SourceLocation const& _location,
ASTPointer<Statement> const& _initExpression,
ASTPointer<Expression> const& _conditionExpression,
ASTPointer<ExpressionStatement> const& _loopExpression,
@ -821,7 +821,7 @@ private:
class Continue: public Statement
{
public:
Continue(Location const& _location): Statement(_location) {}
Continue(SourceLocation const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
@ -830,7 +830,7 @@ public:
class Break: public Statement
{
public:
Break(Location const& _location): Statement(_location) {}
Break(SourceLocation const& _location): Statement(_location) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
virtual void checkTypeRequirements() override {}
@ -839,7 +839,7 @@ public:
class Return: public Statement
{
public:
Return(Location const& _location, ASTPointer<Expression> _expression):
Return(SourceLocation const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression), m_returnParameters(nullptr) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -864,7 +864,7 @@ private:
class VariableDeclarationStatement: public Statement
{
public:
VariableDeclarationStatement(Location const& _location, ASTPointer<VariableDeclaration> _variable):
VariableDeclarationStatement(SourceLocation const& _location, ASTPointer<VariableDeclaration> _variable):
Statement(_location), m_variable(_variable) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -883,7 +883,7 @@ private:
class ExpressionStatement: public Statement
{
public:
ExpressionStatement(Location const& _location, ASTPointer<Expression> _expression):
ExpressionStatement(SourceLocation const& _location, ASTPointer<Expression> _expression):
Statement(_location), m_expression(_expression) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -908,7 +908,7 @@ private:
class Expression: public ASTNode
{
public:
Expression(Location const& _location): ASTNode(_location) {}
Expression(SourceLocation const& _location): ASTNode(_location) {}
virtual void checkTypeRequirements() = 0;
std::shared_ptr<Type const> const& getType() const { return m_type; }
@ -939,7 +939,7 @@ protected:
class Assignment: public Expression
{
public:
Assignment(Location const& _location, ASTPointer<Expression> const& _leftHandSide,
Assignment(SourceLocation const& _location, ASTPointer<Expression> const& _leftHandSide,
Token::Value _assignmentOperator, ASTPointer<Expression> const& _rightHandSide):
Expression(_location), m_leftHandSide(_leftHandSide),
m_assigmentOperator(_assignmentOperator), m_rightHandSide(_rightHandSide)
@ -967,7 +967,7 @@ private:
class UnaryOperation: public Expression
{
public:
UnaryOperation(Location const& _location, Token::Value _operator,
UnaryOperation(SourceLocation const& _location, Token::Value _operator,
ASTPointer<Expression> const& _subExpression, bool _isPrefix):
Expression(_location), m_operator(_operator),
m_subExpression(_subExpression), m_isPrefix(_isPrefix)
@ -995,7 +995,7 @@ private:
class BinaryOperation: public Expression
{
public:
BinaryOperation(Location const& _location, ASTPointer<Expression> const& _left,
BinaryOperation(SourceLocation const& _location, ASTPointer<Expression> const& _left,
Token::Value _operator, ASTPointer<Expression> const& _right):
Expression(_location), m_left(_left), m_operator(_operator), m_right(_right)
{
@ -1026,7 +1026,7 @@ private:
class FunctionCall: public Expression
{
public:
FunctionCall(Location const& _location, ASTPointer<Expression> const& _expression,
FunctionCall(SourceLocation const& _location, ASTPointer<Expression> const& _expression,
std::vector<ASTPointer<Expression>> const& _arguments, std::vector<ASTPointer<ASTString>> const& _names):
Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -1053,7 +1053,7 @@ private:
class NewExpression: public Expression
{
public:
NewExpression(Location const& _location, ASTPointer<Identifier> const& _contractName):
NewExpression(SourceLocation const& _location, ASTPointer<Identifier> const& _contractName):
Expression(_location), m_contractName(_contractName) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -1074,7 +1074,7 @@ private:
class MemberAccess: public Expression
{
public:
MemberAccess(Location const& _location, ASTPointer<Expression> _expression,
MemberAccess(SourceLocation const& _location, ASTPointer<Expression> _expression,
ASTPointer<ASTString> const& _memberName):
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -1094,7 +1094,7 @@ private:
class IndexAccess: public Expression
{
public:
IndexAccess(Location const& _location, ASTPointer<Expression> const& _base,
IndexAccess(SourceLocation const& _location, ASTPointer<Expression> const& _base,
ASTPointer<Expression> const& _index):
Expression(_location), m_base(_base), m_index(_index) {}
virtual void accept(ASTVisitor& _visitor) override;
@ -1116,7 +1116,7 @@ private:
class PrimaryExpression: public Expression
{
public:
PrimaryExpression(Location const& _location): Expression(_location) {}
PrimaryExpression(SourceLocation const& _location): Expression(_location) {}
};
/**
@ -1125,7 +1125,7 @@ public:
class Identifier: public PrimaryExpression
{
public:
Identifier(Location const& _location, ASTPointer<ASTString> const& _name):
Identifier(SourceLocation const& _location, ASTPointer<ASTString> const& _name):
PrimaryExpression(_location), m_name(_name) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
@ -1160,7 +1160,7 @@ private:
class ElementaryTypeNameExpression: public PrimaryExpression
{
public:
ElementaryTypeNameExpression(Location const& _location, Token::Value _typeToken):
ElementaryTypeNameExpression(SourceLocation const& _location, Token::Value _typeToken):
PrimaryExpression(_location), m_typeToken(_typeToken)
{
solAssert(Token::isElementaryTypeName(_typeToken), "");
@ -1189,7 +1189,7 @@ public:
Finney = Token::SubFinney,
Ether = Token::SubEther
};
Literal(Location const& _location, Token::Value _token,
Literal(SourceLocation const& _location, Token::Value _token,
ASTPointer<ASTString> const& _value,
SubDenomination _sub = SubDenomination::None):
PrimaryExpression(_location), m_token(_token), m_value(_value), m_subDenomination(_sub) {}

2
libsolidity/ASTPrinter.cpp

@ -555,7 +555,7 @@ void ASTPrinter::printSourcePart(ASTNode const& _node)
{
if (!m_source.empty())
{
Location const& location(_node.getLocation());
SourceLocation const& location(_node.getLocation());
*m_ostream << getIndentation() << " Source: "
<< escaped(m_source.substr(location.start, location.end - location.start), false) << endl;
}

36
libsolidity/Compiler.cpp

@ -74,6 +74,7 @@ void Compiler::initializeContext(ContractDefinition const& _contract,
m_context.setCompiledContracts(_contracts);
m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts());
registerStateVariables(_contract);
m_context.resetVisitedNodes(&_contract);
}
void Compiler::packIntoContractCreator(ContractDefinition const& _contract, CompilerContext const& _runtimeContext)
@ -128,6 +129,7 @@ void Compiler::packIntoContractCreator(ContractDefinition const& _contract, Comp
void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor,
vector<ASTPointer<Expression>> const& _arguments)
{
CompilerContext::LocationSetter locationSetter(m_context, &_constructor);
FunctionType constructorType(_constructor);
eth::AssemblyItem returnLabel = m_context.pushNewTag();
for (unsigned i = 0; i < _arguments.size(); ++i)
@ -138,6 +140,7 @@ void Compiler::appendBaseConstructorCall(FunctionDefinition const& _constructor,
void Compiler::appendConstructorCall(FunctionDefinition const& _constructor)
{
CompilerContext::LocationSetter locationSetter(m_context, &_constructor);
eth::AssemblyItem returnTag = m_context.pushNewTag();
// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
unsigned argumentSize = 0;
@ -247,7 +250,7 @@ void Compiler::appendReturnValuePacker(TypePointers const& _typeParameters)
for (TypePointer const& type: _typeParameters)
{
CompilerUtils(m_context).copyToStackTop(stackDepth, *type);
ExpressionCompiler::appendTypeConversion(m_context, *type, *type, true);
ExpressionCompiler(m_context, m_optimize).appendTypeConversion(*type, *type, true);
bool const c_padToWords = true;
dataOffset += CompilerUtils(m_context).storeInMemory(dataOffset, *type, c_padToWords);
stackDepth -= type->getSizeOnStack();
@ -267,25 +270,27 @@ void Compiler::initializeStateVariables(ContractDefinition const& _contract)
{
for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables())
if (variable->getValue())
ExpressionCompiler::appendStateVariableInitialization(m_context, *variable);
ExpressionCompiler(m_context, m_optimize).appendStateVariableInitialization(*variable);
}
bool Compiler::visit(VariableDeclaration const& _variableDeclaration)
{
solAssert(_variableDeclaration.isStateVariable(), "Compiler visit to non-state variable declaration.");
CompilerContext::LocationSetter locationSetter(m_context, &_variableDeclaration);
m_context.startFunction(_variableDeclaration);
m_breakTags.clear();
m_continueTags.clear();
m_context << m_context.getFunctionEntryLabel(_variableDeclaration);
ExpressionCompiler::appendStateVariableAccessor(m_context, _variableDeclaration);
ExpressionCompiler(m_context, m_optimize).appendStateVariableAccessor(_variableDeclaration);
return false;
}
bool Compiler::visit(FunctionDefinition const& _function)
{
CompilerContext::LocationSetter locationSetter(m_context, &_function);
//@todo to simplify this, the calling convention could by changed such that
// caller puts: [retarg0] ... [retargm] [return address] [arg0] ... [argn]
// although note that this reduces the size of the visible stack
@ -355,7 +360,7 @@ bool Compiler::visit(FunctionDefinition const& _function)
bool Compiler::visit(IfStatement const& _ifStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_ifStatement);
compileExpression(_ifStatement.getCondition());
eth::AssemblyItem trueTag = m_context.appendConditionalJump();
if (_ifStatement.getFalseStatement())
@ -372,7 +377,7 @@ bool Compiler::visit(IfStatement const& _ifStatement)
bool Compiler::visit(WhileStatement const& _whileStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_whileStatement);
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
m_continueTags.push_back(loopStart);
@ -398,7 +403,7 @@ bool Compiler::visit(WhileStatement const& _whileStatement)
bool Compiler::visit(ForStatement const& _forStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_forStatement);
eth::AssemblyItem loopStart = m_context.newTag();
eth::AssemblyItem loopEnd = m_context.newTag();
m_continueTags.push_back(loopStart);
@ -433,15 +438,17 @@ bool Compiler::visit(ForStatement const& _forStatement)
return false;
}
bool Compiler::visit(Continue const&)
bool Compiler::visit(Continue const& _continueStatement)
{
CompilerContext::LocationSetter locationSetter(m_context, &_continueStatement);
if (!m_continueTags.empty())
m_context.appendJumpTo(m_continueTags.back());
return false;
}
bool Compiler::visit(Break const&)
bool Compiler::visit(Break const& _breakStatement)
{
CompilerContext::LocationSetter locationSetter(m_context, &_breakStatement);
if (!m_breakTags.empty())
m_context.appendJumpTo(m_breakTags.back());
return false;
@ -449,6 +456,7 @@ bool Compiler::visit(Break const&)
bool Compiler::visit(Return const& _return)
{
CompilerContext::LocationSetter locationSetter(m_context, &_return);
//@todo modifications are needed to make this work with functions returning multiple values
if (Expression const* expression = _return.getExpression())
{
@ -467,6 +475,7 @@ bool Compiler::visit(Return const& _return)
bool Compiler::visit(VariableDeclarationStatement const& _variableDeclarationStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_variableDeclarationStatement);
if (Expression const* expression = _variableDeclarationStatement.getExpression())
{
compileExpression(*expression, _variableDeclarationStatement.getDeclaration().getType());
@ -479,6 +488,7 @@ bool Compiler::visit(VariableDeclarationStatement const& _variableDeclarationSta
bool Compiler::visit(ExpressionStatement const& _expressionStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_expressionStatement);
Expression const& expression = _expressionStatement.getExpression();
compileExpression(expression);
CompilerUtils(m_context).popStackElement(*expression.getType());
@ -486,9 +496,10 @@ bool Compiler::visit(ExpressionStatement const& _expressionStatement)
return false;
}
bool Compiler::visit(PlaceholderStatement const&)
bool Compiler::visit(PlaceholderStatement const& _placeholderStatement)
{
StackHeightChecker checker(m_context);
CompilerContext::LocationSetter locationSetter(m_context, &_placeholderStatement);
++m_modifierDepth;
appendModifierOrFunctionCode();
--m_modifierDepth;
@ -504,8 +515,8 @@ void Compiler::appendModifierOrFunctionCode()
else
{
ASTPointer<ModifierInvocation> const& modifierInvocation = m_currentFunction->getModifiers()[m_modifierDepth];
ModifierDefinition const& modifier = m_context.getFunctionModifier(modifierInvocation->getName()->getName());
CompilerContext::LocationSetter locationSetter(m_context, &modifier);
solAssert(modifier.getParameters().size() == modifierInvocation->getArguments().size(), "");
for (unsigned i = 0; i < modifier.getParameters().size(); ++i)
{
@ -530,9 +541,10 @@ void Compiler::appendModifierOrFunctionCode()
void Compiler::compileExpression(Expression const& _expression, TypePointer const& _targetType)
{
ExpressionCompiler::compileExpression(m_context, _expression, m_optimize);
ExpressionCompiler expressionCompiler(m_context, m_optimize);
expressionCompiler.compile(_expression);
if (_targetType)
ExpressionCompiler::appendTypeConversion(m_context, *_expression.getType(), *_targetType);
expressionCompiler.appendTypeConversion(*_expression.getType(), *_targetType);
}
}

6
libsolidity/Compiler.h

@ -26,6 +26,7 @@
#include <functional>
#include <libsolidity/ASTVisitor.h>
#include <libsolidity/CompilerContext.h>
#include <libevmcore/Assembly.h>
namespace dev {
namespace solidity {
@ -42,6 +43,11 @@ public:
bytes getRuntimeBytecode() { return m_runtimeContext.getAssembledBytecode(m_optimize);}
void streamAssembly(std::ostream& _stream) const { m_context.streamAssembly(_stream); }
/// @returns Assembly items of the normal compiler context
eth::AssemblyItems const& getAssemblyItems() const { return m_context.getAssembly().getItems(); }
/// @returns Assembly items of the runtime compiler context
eth::AssemblyItems const& getRuntimeAssemblyItems() const { return m_runtimeContext.getAssembly().getItems(); }
private:
/// Registers the non-function objects inside the contract with the context.
void initializeContext(ContractDefinition const& _contract,

37
libsolidity/CompilerContext.cpp

@ -65,8 +65,8 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration,
void CompilerContext::addAndInitializeVariable(VariableDeclaration const& _declaration)
{
LocationSetter locationSetter(*this, &_declaration);
addVariable(_declaration);
int const size = _declaration.getType()->getSizeOnStack();
for (int i = 0; i < size; ++i)
*this << u256(0);
@ -166,5 +166,40 @@ u256 CompilerContext::getStorageLocationOfVariable(const Declaration& _declarati
return it->second;
}
void CompilerContext::resetVisitedNodes(ASTNode const* _node)
{
stack<ASTNode const*> newStack;
newStack.push(_node);
std::swap(m_visitedNodes, newStack);
}
CompilerContext& CompilerContext::operator<<(eth::AssemblyItem const& _item)
{
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_item, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(eth::Instruction _instruction)
{
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_instruction, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(u256 const& _value)
{
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_value, m_visitedNodes.top()->getLocation());
return *this;
}
CompilerContext& CompilerContext::operator<<(bytes const& _data)
{
solAssert(!m_visitedNodes.empty(), "No node on the visited stack");
m_asm.append(_data, m_visitedNodes.top()->getLocation());
return *this;
}
}
}

28
libsolidity/CompilerContext.h

@ -23,6 +23,7 @@
#pragma once
#include <ostream>
#include <stack>
#include <libevmcore/Instruction.h>
#include <libevmcore/Assembly.h>
#include <libsolidity/ASTForward.h>
@ -99,19 +100,34 @@ public:
void appendProgramSize() { return m_asm.appendProgramSize(); }
/// Adds data to the data section, pushes a reference to the stack
eth::AssemblyItem appendData(bytes const& _data) { return m_asm.append(_data); }
/// Resets the stack of visited nodes with a new stack having only @c _node
void resetVisitedNodes(ASTNode const* _node);
/// Pops the stack of visited nodes
void popVisitedNodes() { m_visitedNodes.pop(); }
/// Pushes an ASTNode to the stack of visited nodes
void pushVisitedNodes(ASTNode const* _node) { m_visitedNodes.push(_node); }
/// Append elements to the current instruction list and adjust @a m_stackOffset.
CompilerContext& operator<<(eth::AssemblyItem const& _item) { m_asm.append(_item); return *this; }
CompilerContext& operator<<(eth::Instruction _instruction) { m_asm.append(_instruction); return *this; }
CompilerContext& operator<<(u256 const& _value) { m_asm.append(_value); return *this; }
CompilerContext& operator<<(bytes const& _data) { m_asm.append(_data); return *this; }
CompilerContext& operator<<(eth::AssemblyItem const& _item);
CompilerContext& operator<<(eth::Instruction _instruction);
CompilerContext& operator<<(u256 const& _value);
CompilerContext& operator<<(bytes const& _data);
eth::Assembly const& getAssembly() const { return m_asm; }
void streamAssembly(std::ostream& _stream) const { _stream << m_asm; }
bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); }
private:
/**
* Helper class to pop the visited nodes stack when a scope closes
*/
class LocationSetter: public ScopeGuard
{
public:
LocationSetter(CompilerContext& _compilerContext, ASTNode const* _node):
ScopeGuard(std::bind(&CompilerContext::popVisitedNodes, _compilerContext)) { _compilerContext.pushVisitedNodes(_node); }
};
eth::Assembly m_asm;
private:
/// Magic global variables like msg, tx or this, distinguished by type.
std::set<Declaration const*> m_magicGlobals;
@ -129,6 +145,8 @@ private:
std::set<Declaration const*> m_functionsWithCode;
/// List of current inheritance hierarchy from derived to base.
std::vector<ContractDefinition const*> m_inheritanceHierarchy;
/// Stack of current visited AST nodes, used for location attachment
std::stack<ASTNode const*> m_visitedNodes;
};
}

4
libsolidity/Exceptions.h

@ -24,7 +24,7 @@
#include <string>
#include <libdevcore/Exceptions.h>
#include <libsolidity/BaseTypes.h>
#include <libevmcore/SourceLocation.h>
namespace dev
{
@ -38,7 +38,7 @@ struct CompilerError: virtual Exception {};
struct InternalCompilerError: virtual Exception {};
struct DocstringParsingError: virtual Exception {};
using errinfo_sourceLocation = boost::error_info<struct tag_sourceLocation, Location>;
using errinfo_sourceLocation = boost::error_info<struct tag_sourceLocation, SourceLocation>;
}
}

632
libsolidity/ExpressionCompiler.cpp

@ -29,6 +29,7 @@
#include <libsolidity/ExpressionCompiler.h>
#include <libsolidity/CompilerContext.h>
#include <libsolidity/CompilerUtils.h>
#include <libsolidity/LValue.h>
using namespace std;
@ -37,68 +38,198 @@ namespace dev
namespace solidity
{
void ExpressionCompiler::compileExpression(CompilerContext& _context, Expression const& _expression, bool _optimize)
void ExpressionCompiler::compile(Expression const& _expression)
{
ExpressionCompiler compiler(_context, _optimize);
_expression.accept(compiler);
_expression.accept(*this);
}
void ExpressionCompiler::appendTypeConversion(CompilerContext& _context, Type const& _typeOnStack,
Type const& _targetType, bool _cleanupNeeded)
void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration const& _varDecl)
{
ExpressionCompiler compiler(_context);
compiler.appendTypeConversion(_typeOnStack, _targetType, _cleanupNeeded);
}
if (!_varDecl.getValue())
return;
solAssert(!!_varDecl.getValue()->getType(), "Type information not available.");
CompilerContext::LocationSetter locationSetter(m_context, &_varDecl);
_varDecl.getValue()->accept(*this);
appendTypeConversion(*_varDecl.getValue()->getType(), *_varDecl.getType(), true);
void ExpressionCompiler::appendStateVariableAccessor(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize)
{
ExpressionCompiler compiler(_context, _optimize);
compiler.appendStateVariableAccessor(_varDecl);
StorageItem(m_context, _varDecl).storeValue(*_varDecl.getType(), _varDecl.getLocation(), true);
}
void ExpressionCompiler::appendStateVariableInitialization(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize)
void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl)
{
compileExpression(_context, *(_varDecl.getValue()), _optimize);
if (_varDecl.getValue()->getType())
appendTypeConversion(_context, *(_varDecl.getValue())->getType(), *(_varDecl.getValue())->getType());
CompilerContext::LocationSetter locationSetter(m_context, &_varDecl);
FunctionType accessorType(_varDecl);
unsigned length = 0;
TypePointers const& paramTypes = accessorType.getParameterTypes();
// move arguments to memory
for (TypePointer const& paramType: boost::adaptors::reverse(paramTypes))
length += CompilerUtils(m_context).storeInMemory(length, *paramType, true);
// retrieve the position of the variable
m_context << m_context.getStorageLocationOfVariable(_varDecl);
TypePointer returnType = _varDecl.getType();
for (TypePointer const& paramType: paramTypes)
{
// move offset to memory
CompilerUtils(m_context).storeInMemory(length);
unsigned argLen = CompilerUtils::getPaddedSize(paramType->getCalldataEncodedSize());
length -= argLen;
m_context << u256(argLen + 32) << u256(length) << eth::Instruction::SHA3;
returnType = dynamic_cast<MappingType const&>(*returnType).getValueType();
}
ExpressionCompiler compiler(_context, _optimize);
compiler.appendStateVariableInitialization(_varDecl);
unsigned retSizeOnStack = 0;
solAssert(accessorType.getReturnParameterTypes().size() >= 1, "");
if (StructType const* structType = dynamic_cast<StructType const*>(returnType.get()))
{
auto const& names = accessorType.getReturnParameterNames();
auto const& types = accessorType.getReturnParameterTypes();
// struct
for (size_t i = 0; i < names.size(); ++i)
{
m_context << eth::Instruction::DUP1
<< structType->getStorageOffsetOfMember(names[i])
<< eth::Instruction::ADD;
StorageItem(m_context, types[i]).retrieveValue(SourceLocation(), true);
solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented.");
m_context << eth::Instruction::SWAP1;
retSizeOnStack += types[i]->getSizeOnStack();
}
m_context << eth::Instruction::POP;
}
else
{
// simple value
solAssert(accessorType.getReturnParameterTypes().size() == 1, "");
StorageItem(m_context, returnType).retrieveValue(SourceLocation(), true);
retSizeOnStack = returnType->getSizeOnStack();
}
solAssert(retSizeOnStack <= 15, "Stack too deep.");
m_context << eth::dupInstruction(retSizeOnStack + 1) << eth::Instruction::JUMP;
}
void ExpressionCompiler::appendStateVariableInitialization(VariableDeclaration const& _varDecl)
void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded)
{
LValue var = LValue(m_context);
var.fromDeclaration(_varDecl, _varDecl.getValue()->getLocation());
var.storeValue(*_varDecl.getType(), _varDecl.getLocation());
// For a type extension, we need to remove all higher-order bits that we might have ignored in
// previous operations.
// @todo: store in the AST whether the operand might have "dirty" higher order bits
if (_typeOnStack == _targetType && !_cleanupNeeded)
return;
Type::Category stackTypeCategory = _typeOnStack.getCategory();
Type::Category targetTypeCategory = _targetType.getCategory();
if (stackTypeCategory == Type::Category::String)
{
StaticStringType const& typeOnStack = dynamic_cast<StaticStringType const&>(_typeOnStack);
if (targetTypeCategory == Type::Category::Integer)
{
// conversion from string to hash. no need to clean the high bit
// only to shift right because of opposite alignment
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
solAssert(targetIntegerType.isHash(), "Only conversion between String and Hash is allowed.");
solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same.");
m_context << (u256(1) << (256 - typeOnStack.getNumBytes() * 8)) << eth::Instruction::SWAP1 << eth::Instruction::DIV;
}
else
{
// clear lower-order bytes for conversion to shorter strings - we always clean
solAssert(targetTypeCategory == Type::Category::String, "Invalid type conversion requested.");
StaticStringType const& targetType = dynamic_cast<StaticStringType const&>(_targetType);
if (targetType.getNumBytes() < typeOnStack.getNumBytes())
{
if (targetType.getNumBytes() == 0)
m_context << eth::Instruction::DUP1 << eth::Instruction::XOR;
else
m_context << (u256(1) << (256 - targetType.getNumBytes() * 8))
<< eth::Instruction::DUP1 << eth::Instruction::SWAP2
<< eth::Instruction::DIV << eth::Instruction::MUL;
}
}
}
else if (stackTypeCategory == Type::Category::Enum)
solAssert(targetTypeCategory == Type::Category::Integer ||
targetTypeCategory == Type::Category::Enum, "");
else if (stackTypeCategory == Type::Category::Integer ||
stackTypeCategory == Type::Category::Contract ||
stackTypeCategory == Type::Category::IntegerConstant)
{
if (targetTypeCategory == Type::Category::String && stackTypeCategory == Type::Category::Integer)
{
// conversion from hash to string. no need to clean the high bit
// only to shift left because of opposite alignment
StaticStringType const& targetStringType = dynamic_cast<StaticStringType const&>(_targetType);
IntegerType const& typeOnStack = dynamic_cast<IntegerType const&>(_typeOnStack);
solAssert(typeOnStack.isHash(), "Only conversion between String and Hash is allowed.");
solAssert(typeOnStack.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same.");
m_context << (u256(1) << (256 - typeOnStack.getNumBits())) << eth::Instruction::MUL;
}
else if (targetTypeCategory == Type::Category::Enum)
// just clean
appendTypeConversion(_typeOnStack, *_typeOnStack.getRealType(), true);
else
{
solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, "");
IntegerType addressType(0, IntegerType::Modifier::Address);
IntegerType const& targetType = targetTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_targetType) : addressType;
if (stackTypeCategory == Type::Category::IntegerConstant)
{
IntegerConstantType const& constType = dynamic_cast<IntegerConstantType const&>(_typeOnStack);
// We know that the stack is clean, we only have to clean for a narrowing conversion
// where cleanup is forced.
if (targetType.getNumBits() < constType.getIntegerType()->getNumBits() && _cleanupNeeded)
appendHighBitsCleanup(targetType);
}
else
{
IntegerType const& typeOnStack = stackTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_typeOnStack) : addressType;
// Widening: clean up according to source type width
// Non-widening and force: clean up according to target type bits
if (targetType.getNumBits() > typeOnStack.getNumBits())
appendHighBitsCleanup(typeOnStack);
else if (_cleanupNeeded)
appendHighBitsCleanup(targetType);
}
}
}
else if (_typeOnStack != _targetType)
// All other types should not be convertible to non-equal types.
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested."));
}
bool ExpressionCompiler::visit(Assignment const& _assignment)
{
CompilerContext::LocationSetter locationSetter(m_context, &_assignment);
_assignment.getRightHandSide().accept(*this);
if (_assignment.getType()->isValueType())
appendTypeConversion(*_assignment.getRightHandSide().getType(), *_assignment.getType());
_assignment.getLeftHandSide().accept(*this);
solAssert(m_currentLValue.isValid(), "LValue not retrieved.");
solAssert(!!m_currentLValue, "LValue not retrieved.");
Token::Value op = _assignment.getAssignmentOperator();
if (op != Token::Assign) // compound assignment
{
solAssert(_assignment.getType()->isValueType(), "Compound operators not implemented for non-value types.");
if (m_currentLValue.storesReferenceOnStack())
if (m_currentLValue->storesReferenceOnStack())
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2;
m_currentLValue.retrieveValue(_assignment.getLocation(), true);
m_currentLValue->retrieveValue(_assignment.getLocation(), true);
appendOrdinaryBinaryOperatorCode(Token::AssignmentToBinaryOp(op), *_assignment.getType());
if (m_currentLValue.storesReferenceOnStack())
if (m_currentLValue->storesReferenceOnStack())
m_context << eth::Instruction::SWAP1;
}
m_currentLValue.storeValue(*_assignment.getRightHandSide().getType(), _assignment.getLocation());
m_currentLValue->storeValue(*_assignment.getRightHandSide().getType(), _assignment.getLocation());
m_currentLValue.reset();
return false;
}
bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
{
CompilerContext::LocationSetter locationSetter(m_context, &_unaryOperation);
//@todo type checking and creating code for an operator should be in the same place:
// the operator should know how to convert itself and to which types it applies, so
// put this code together with "Type::acceptsBinary/UnaryOperator" into a class that
@ -120,17 +251,17 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
m_context << eth::Instruction::NOT;
break;
case Token::Delete: // delete
solAssert(m_currentLValue.isValid(), "LValue not retrieved.");
m_currentLValue.setToZero(_unaryOperation.getLocation());
solAssert(!!m_currentLValue, "LValue not retrieved.");
m_currentLValue->setToZero(_unaryOperation.getLocation());
m_currentLValue.reset();
break;
case Token::Inc: // ++ (pre- or postfix)
case Token::Dec: // -- (pre- or postfix)
solAssert(m_currentLValue.isValid(), "LValue not retrieved.");
m_currentLValue.retrieveValue(_unaryOperation.getLocation());
solAssert(!!m_currentLValue, "LValue not retrieved.");
m_currentLValue->retrieveValue(_unaryOperation.getLocation());
if (!_unaryOperation.isPrefixOperation())
{
if (m_currentLValue.storesReferenceOnStack())
if (m_currentLValue->storesReferenceOnStack())
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2;
else
m_context << eth::Instruction::DUP1;
@ -142,10 +273,11 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
m_context << eth::Instruction::SWAP1 << eth::Instruction::SUB; // @todo avoid the swap
// Stack for prefix: [ref] (*ref)+-1
// Stack for postfix: *ref [ref] (*ref)+-1
if (m_currentLValue.storesReferenceOnStack())
if (m_currentLValue->storesReferenceOnStack())
m_context << eth::Instruction::SWAP1;
m_currentLValue.storeValue(*_unaryOperation.getType(), _unaryOperation.getLocation(),
!_unaryOperation.isPrefixOperation());
m_currentLValue->storeValue(
*_unaryOperation.getType(), _unaryOperation.getLocation(),
!_unaryOperation.isPrefixOperation());
m_currentLValue.reset();
break;
case Token::Add: // +
@ -163,6 +295,7 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
{
CompilerContext::LocationSetter locationSetter(m_context, &_binaryOperation);
Expression const& leftExpression = _binaryOperation.getLeftExpression();
Expression const& rightExpression = _binaryOperation.getRightExpression();
Type const& commonType = _binaryOperation.getCommonType();
@ -175,7 +308,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
else
{
bool cleanupNeeded = commonType.getCategory() == Type::Category::Integer &&
(Token::isCompareOp(c_op) || c_op == Token::Div || c_op == Token::Mod);
(Token::isCompareOp(c_op) || c_op == Token::Div || c_op == Token::Mod);
// for commutative operators, push the literal as late as possible to allow improved optimization
auto isLiteral = [](Expression const& _e)
@ -209,6 +342,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation)
bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
{
CompilerContext::LocationSetter locationSetter(m_context, &_functionCall);
using Location = FunctionType::Location;
if (_functionCall.isTypeConversion())
{
@ -426,6 +560,7 @@ bool ExpressionCompiler::visit(NewExpression const&)
void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
{
CompilerContext::LocationSetter locationSetter(m_context, &_memberAccess);
ASTString const& member = _memberAccess.getMemberName();
switch (_memberAccess.getExpression().getType()->getCategory())
{
@ -499,8 +634,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
{
StructType const& type = dynamic_cast<StructType const&>(*_memberAccess.getExpression().getType());
m_context << type.getStorageOffsetOfMember(member) << eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _memberAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
setLValueToStorageItem(_memberAccess);
break;
}
case Type::Category::Enum:
@ -546,8 +680,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
m_context << eth::Instruction::SWAP1 << eth::Instruction::POP;
break;
case ArrayType::Location::Storage:
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _memberAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_memberAccess);
setLValueToStorageItem(_memberAccess);
break;
default:
solAssert(false, "Unsupported array location.");
@ -562,6 +695,7 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
{
CompilerContext::LocationSetter locationSetter(m_context, &_indexAccess);
_indexAccess.getBaseExpression().accept(*this);
Type const& baseType = *_indexAccess.getBaseExpression().getType();
@ -576,8 +710,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
m_context << eth::Instruction::SWAP1;
appendTypeMoveToMemory(IntegerType(256));
m_context << u256(0) << eth::Instruction::SHA3;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
setLValueToStorageItem( _indexAccess);
}
else if (baseType.getCategory() == Type::Category::Array)
{
@ -609,8 +742,7 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess)
CompilerUtils(m_context).computeHashStatic();
}
m_context << eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, _indexAccess.getType());
m_currentLValue.retrieveValueIfLValueNotRequested(_indexAccess);
setLValueToStorageItem(_indexAccess);
}
else
solAssert(false, "Index access only allowed for mappings or arrays.");
@ -631,10 +763,7 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
else if (FunctionDefinition const* functionDef = dynamic_cast<FunctionDefinition const*>(declaration))
m_context << m_context.getVirtualFunctionEntryLabel(*functionDef).pushTag();
else if (dynamic_cast<VariableDeclaration const*>(declaration))
{
m_currentLValue.fromDeclaration(*declaration, _identifier.getLocation());
m_currentLValue.retrieveValueIfLValueNotRequested(_identifier);
}
setLValueFromDeclaration(*declaration, _identifier);
else if (dynamic_cast<ContractDefinition const*>(declaration))
{
// no-op
@ -791,96 +920,6 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator)
}
}
void ExpressionCompiler::appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded)
{
// For a type extension, we need to remove all higher-order bits that we might have ignored in
// previous operations.
// @todo: store in the AST whether the operand might have "dirty" higher order bits
if (_typeOnStack == _targetType && !_cleanupNeeded)
return;
Type::Category stackTypeCategory = _typeOnStack.getCategory();
Type::Category targetTypeCategory = _targetType.getCategory();
if (stackTypeCategory == Type::Category::String)
{
StaticStringType const& typeOnStack = dynamic_cast<StaticStringType const&>(_typeOnStack);
if (targetTypeCategory == Type::Category::Integer)
{
// conversion from string to hash. no need to clean the high bit
// only to shift right because of opposite alignment
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
solAssert(targetIntegerType.isHash(), "Only conversion between String and Hash is allowed.");
solAssert(targetIntegerType.getNumBits() == typeOnStack.getNumBytes() * 8, "The size should be the same.");
m_context << (u256(1) << (256 - typeOnStack.getNumBytes() * 8)) << eth::Instruction::SWAP1 << eth::Instruction::DIV;
}
else
{
// clear lower-order bytes for conversion to shorter strings - we always clean
solAssert(targetTypeCategory == Type::Category::String, "Invalid type conversion requested.");
StaticStringType const& targetType = dynamic_cast<StaticStringType const&>(_targetType);
if (targetType.getNumBytes() < typeOnStack.getNumBytes())
{
if (targetType.getNumBytes() == 0)
m_context << eth::Instruction::DUP1 << eth::Instruction::XOR;
else
m_context << (u256(1) << (256 - targetType.getNumBytes() * 8))
<< eth::Instruction::DUP1 << eth::Instruction::SWAP2
<< eth::Instruction::DIV << eth::Instruction::MUL;
}
}
}
else if (stackTypeCategory == Type::Category::Enum)
solAssert(targetTypeCategory == Type::Category::Integer ||
targetTypeCategory == Type::Category::Enum, "");
else if (stackTypeCategory == Type::Category::Integer || stackTypeCategory == Type::Category::Contract ||
stackTypeCategory == Type::Category::IntegerConstant)
{
if (targetTypeCategory == Type::Category::String && stackTypeCategory == Type::Category::Integer)
{
// conversion from hash to string. no need to clean the high bit
// only to shift left because of opposite alignment
StaticStringType const& targetStringType = dynamic_cast<StaticStringType const&>(_targetType);
IntegerType const& typeOnStack = dynamic_cast<IntegerType const&>(_typeOnStack);
solAssert(typeOnStack.isHash(), "Only conversion between String and Hash is allowed.");
solAssert(typeOnStack.getNumBits() == targetStringType.getNumBytes() * 8, "The size should be the same.");
m_context << (u256(1) << (256 - typeOnStack.getNumBits())) << eth::Instruction::MUL;
}
else if (targetTypeCategory == Type::Category::Enum)
// just clean
appendTypeConversion(_typeOnStack, *_typeOnStack.getRealType(), true);
else
{
solAssert(targetTypeCategory == Type::Category::Integer || targetTypeCategory == Type::Category::Contract, "");
IntegerType addressType(0, IntegerType::Modifier::Address);
IntegerType const& targetType = targetTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_targetType) : addressType;
if (stackTypeCategory == Type::Category::IntegerConstant)
{
IntegerConstantType const& constType = dynamic_cast<IntegerConstantType const&>(_typeOnStack);
// We know that the stack is clean, we only have to clean for a narrowing conversion
// where cleanup is forced.
if (targetType.getNumBits() < constType.getIntegerType()->getNumBits() && _cleanupNeeded)
appendHighBitsCleanup(targetType);
}
else
{
IntegerType const& typeOnStack = stackTypeCategory == Type::Category::Integer
? dynamic_cast<IntegerType const&>(_typeOnStack) : addressType;
// Widening: clean up according to source type width
// Non-widening and force: clean up according to target type bits
if (targetType.getNumBits() > typeOnStack.getNumBits())
appendHighBitsCleanup(typeOnStack);
else if (_cleanupNeeded)
appendHighBitsCleanup(targetType);
}
}
}
else if (_typeOnStack != _targetType)
// All other types should not be convertible to non-equal types.
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid type conversion requested."));
}
void ExpressionCompiler::appendHighBitsCleanup(IntegerType const& _typeOnStack)
{
if (_typeOnStack.getNumBits() == 256)
@ -991,318 +1030,21 @@ void ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType,
appendTypeMoveToMemory(_expectedType);
}
void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl)
void ExpressionCompiler::setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression)
{
FunctionType accessorType(_varDecl);
unsigned length = 0;
TypePointers const& paramTypes = accessorType.getParameterTypes();
// move arguments to memory
for (TypePointer const& paramType: boost::adaptors::reverse(paramTypes))
length += CompilerUtils(m_context).storeInMemory(length, *paramType, true);
// retrieve the position of the variable
m_context << m_context.getStorageLocationOfVariable(_varDecl);
TypePointer returnType = _varDecl.getType();
for (TypePointer const& paramType: paramTypes)
{
// move offset to memory
CompilerUtils(m_context).storeInMemory(length);
unsigned argLen = CompilerUtils::getPaddedSize(paramType->getCalldataEncodedSize());
length -= argLen;
m_context << u256(argLen + 32) << u256(length) << eth::Instruction::SHA3;
returnType = dynamic_cast<MappingType const&>(*returnType).getValueType();
}
unsigned retSizeOnStack = 0;
solAssert(accessorType.getReturnParameterTypes().size() >= 1, "");
if (StructType const* structType = dynamic_cast<StructType const*>(returnType.get()))
{
auto const& names = accessorType.getReturnParameterNames();
auto const& types = accessorType.getReturnParameterTypes();
// struct
for (size_t i = 0; i < names.size(); ++i)
{
m_context << eth::Instruction::DUP1
<< structType->getStorageOffsetOfMember(names[i])
<< eth::Instruction::ADD;
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, types[i]);
m_currentLValue.retrieveValue(Location(), true);
solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented.");
m_context << eth::Instruction::SWAP1;
retSizeOnStack += types[i]->getSizeOnStack();
}
m_context << eth::Instruction::POP;
}
if (m_context.isLocalVariable(&_declaration))
setLValue<StackVariable>(_expression, _declaration);
else if (m_context.isStateVariable(&_declaration))
setLValue<StorageItem>(_expression, _declaration);
else
{
// simple value
solAssert(accessorType.getReturnParameterTypes().size() == 1, "");
m_currentLValue = LValue(m_context, LValue::LValueType::Storage, returnType);
m_currentLValue.retrieveValue(Location(), true);
retSizeOnStack = returnType->getSizeOnStack();
}
solAssert(retSizeOnStack <= 15, "Stack too deep.");
m_context << eth::dupInstruction(retSizeOnStack + 1) << eth::Instruction::JUMP;
}
ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType _type,
TypePointer const& _dataType, unsigned _baseStackOffset):
m_context(&_compilerContext), m_type(_type), m_dataType(_dataType),
m_baseStackOffset(_baseStackOffset)
{
//@todo change the type cast for arrays
solAssert(m_dataType->getStorageSize() <= numeric_limits<unsigned>::max(),
"The storage size of " + m_dataType->toString() + " should fit in unsigned");
if (m_type == LValueType::Storage)
m_size = unsigned(m_dataType->getStorageSize());
else
m_size = unsigned(m_dataType->getSizeOnStack());
}
void ExpressionCompiler::LValue::fromDeclaration(Declaration const& _declaration, Location const& _location)
{
if (m_context->isLocalVariable(&_declaration))
{
m_type = LValueType::Stack;
m_dataType = _declaration.getType();
m_size = m_dataType->getSizeOnStack();
m_baseStackOffset = m_context->getBaseStackOffsetOfVariable(_declaration);
}
else if (m_context->isStateVariable(&_declaration))
{
*m_context << m_context->getStorageLocationOfVariable(_declaration);
m_type = LValueType::Storage;
m_dataType = _declaration.getType();
solAssert(m_dataType->getStorageSize() <= numeric_limits<unsigned>::max(),
"The storage size of " + m_dataType->toString() + " should fit in an unsigned");
m_size = unsigned(m_dataType->getStorageSize());
}
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Identifier type not supported or identifier not found."));
}
void ExpressionCompiler::LValue::retrieveValue(Location const& _location, bool _remove) const
{
switch (m_type)
{
case LValueType::Stack:
{
unsigned stackPos = m_context->baseToCurrentStackOffset(m_baseStackOffset);
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
for (unsigned i = 0; i < m_size; ++i)
*m_context << eth::dupInstruction(stackPos + 1);
break;
}
case LValueType::Storage:
retrieveValueFromStorage(_remove);
break;
case LValueType::Memory:
if (!m_dataType->isValueType())
break; // no distinction between value and reference for non-value types
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Location type not yet implemented."));
break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Unsupported location type."));
break;
}
}
void ExpressionCompiler::LValue::retrieveValueFromStorage(bool _remove) const
{
if (!m_dataType->isValueType())
return; // no distinction between value and reference for non-value types
if (!_remove)
*m_context << eth::Instruction::DUP1;
if (m_size == 1)
*m_context << eth::Instruction::SLOAD;
else
for (unsigned i = 0; i < m_size; ++i)
{
*m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD << eth::Instruction::SWAP1;
if (i + 1 < m_size)
*m_context << u256(1) << eth::Instruction::ADD;
else
*m_context << eth::Instruction::POP;
}
}
void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, Location const& _location, bool _move) const
{
switch (m_type)
{
case LValueType::Stack:
{
unsigned stackDiff = m_context->baseToCurrentStackOffset(m_baseStackOffset) - m_size + 1;
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
else if (stackDiff > 0)
for (unsigned i = 0; i < m_size; ++i)
*m_context << eth::swapInstruction(stackDiff) << eth::Instruction::POP;
if (!_move)
retrieveValue(_location);
break;
}
case LValueType::Storage:
// stack layout: value value ... value target_ref
if (m_dataType->isValueType())
{
if (!_move) // copy values
{
if (m_size + 1 > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
for (unsigned i = 0; i < m_size; ++i)
*m_context << eth::dupInstruction(m_size + 1) << eth::Instruction::SWAP1;
}
if (m_size > 0) // store high index value first
*m_context << u256(m_size - 1) << eth::Instruction::ADD;
for (unsigned i = 0; i < m_size; ++i)
{
if (i + 1 >= m_size)
*m_context << eth::Instruction::SSTORE;
else
// stack here: value value ... value value (target_ref+offset)
*m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2
<< eth::Instruction::SSTORE
<< u256(1) << eth::Instruction::SWAP1 << eth::Instruction::SUB;
}
}
else
{
solAssert(_sourceType.getCategory() == m_dataType->getCategory(), "Wrong type conversation for assignment.");
if (m_dataType->getCategory() == Type::Category::Array)
{
CompilerUtils(*m_context).copyByteArrayToStorage(
dynamic_cast<ArrayType const&>(*m_dataType),
dynamic_cast<ArrayType const&>(_sourceType));
if (_move)
*m_context << eth::Instruction::POP;
}
else if (m_dataType->getCategory() == Type::Category::Struct)
{
// stack layout: source_ref target_ref
auto const& structType = dynamic_cast<StructType const&>(*m_dataType);
solAssert(structType == _sourceType, "Struct assignment with conversion.");
for (auto const& member: structType.getMembers())
{
// assign each member that is not a mapping
TypePointer const& memberType = member.second;
if (memberType->getCategory() == Type::Category::Mapping)
continue;
*m_context << structType.getStorageOffsetOfMember(member.first)
<< eth::Instruction::DUP3 << eth::Instruction::DUP2
<< eth::Instruction::ADD;
// stack: source_ref target_ref member_offset source_member_ref
LValue rightHandSide(*m_context, LValueType::Storage, memberType);
rightHandSide.retrieveValue(_location, true);
// stack: source_ref target_ref member_offset source_value...
*m_context << eth::dupInstruction(2 + memberType->getSizeOnStack())
<< eth::dupInstruction(2 + memberType->getSizeOnStack())
<< eth::Instruction::ADD;
// stack: source_ref target_ref member_offset source_value... target_member_ref
LValue memberLValue(*m_context, LValueType::Storage, memberType);
memberLValue.storeValue(*memberType, _location, true);
*m_context << eth::Instruction::POP;
}
if (_move)
*m_context << eth::Instruction::POP;
else
*m_context << eth::Instruction::SWAP1;
*m_context << eth::Instruction::POP;
}
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Invalid non-value type for assignment."));
}
break;
case LValueType::Memory:
if (!m_dataType->isValueType())
break; // no distinction between value and reference for non-value types
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Location type not yet implemented."));
break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Unsupported location type."));
break;
}
BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_sourceLocation(_expression.getLocation())
<< errinfo_comment("Identifier type not supported or identifier not found."));
}
void ExpressionCompiler::LValue::setToZero(Location const& _location) const
void ExpressionCompiler::setLValueToStorageItem(Expression const& _expression)
{
switch (m_type)
{
case LValueType::Stack:
{
unsigned stackDiff = m_context->baseToCurrentStackOffset(m_baseStackOffset);
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Stack too deep."));
solAssert(stackDiff >= m_size - 1, "");
for (unsigned i = 0; i < m_size; ++i)
*m_context << u256(0) << eth::swapInstruction(stackDiff + 1 - i)
<< eth::Instruction::POP;
break;
}
case LValueType::Storage:
if (m_dataType->getCategory() == Type::Category::Array)
CompilerUtils(*m_context).clearByteArray(dynamic_cast<ArrayType const&>(*m_dataType));
else if (m_dataType->getCategory() == Type::Category::Struct)
{
// stack layout: ref
auto const& structType = dynamic_cast<StructType const&>(*m_dataType);
for (auto const& member: structType.getMembers())
{
// zero each member that is not a mapping
TypePointer const& memberType = member.second;
if (memberType->getCategory() == Type::Category::Mapping)
continue;
*m_context << structType.getStorageOffsetOfMember(member.first)
<< eth::Instruction::DUP2 << eth::Instruction::ADD;
LValue memberValue(*m_context, LValueType::Storage, memberType);
memberValue.setToZero();
}
*m_context << eth::Instruction::POP;
}
else
{
if (m_size == 0)
*m_context << eth::Instruction::POP;
for (unsigned i = 0; i < m_size; ++i)
if (i + 1 >= m_size)
*m_context << u256(0) << eth::Instruction::SWAP1 << eth::Instruction::SSTORE;
else
*m_context << u256(0) << eth::Instruction::DUP2 << eth::Instruction::SSTORE
<< u256(1) << eth::Instruction::ADD;
}
break;
case LValueType::Memory:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Location type not yet implemented."));
break;
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_sourceLocation(_location)
<< errinfo_comment("Unsupported location type."));
break;
}
}
void ExpressionCompiler::LValue::retrieveValueIfLValueNotRequested(Expression const& _expression)
{
if (!_expression.lvalueRequested())
{
retrieveValue(_expression.getLocation(), true);
reset();
}
setLValue<StorageItem>(_expression, _expression.getType());
}
}

126
libsolidity/ExpressionCompiler.h

@ -25,8 +25,10 @@
#include <memory>
#include <boost/noncopyable.hpp>
#include <libdevcore/Common.h>
#include <libsolidity/BaseTypes.h>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/Utils.h>
#include <libsolidity/ASTVisitor.h>
#include <libsolidity/LValue.h>
namespace dev {
namespace eth
@ -50,22 +52,28 @@ class StaticStringType;
class ExpressionCompiler: private ASTConstVisitor
{
public:
/// Compile the given @a _expression into the @a _context.
static void compileExpression(CompilerContext& _context, Expression const& _expression, bool _optimize = false);
/// Appends code to remove dirty higher order bits in case of an implicit promotion to a wider type.
static void appendTypeConversion(CompilerContext& _context, Type const& _typeOnStack,
Type const& _targetType, bool _cleanupNeeded = false);
/// Appends code for a State Variable accessor function
static void appendStateVariableAccessor(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize = false);
/// Appends code for a State Variable Initialization function
static void appendStateVariableInitialization(CompilerContext& _context, VariableDeclaration const& _varDecl, bool _optimize = false);
private:
explicit ExpressionCompiler(CompilerContext& _compilerContext, bool _optimize = false):
m_optimize(_optimize), m_context(_compilerContext), m_currentLValue(m_context) {}
m_optimize(_optimize), m_context(_compilerContext) {}
/// Compile the given @a _expression and leave its value on the stack.
void compile(Expression const& _expression);
/// Appends code to set a state variable to its initial value/expression.
void appendStateVariableInitialization(VariableDeclaration const& _varDecl);
/// Appends code for a State Variable accessor function
void appendStateVariableAccessor(VariableDeclaration const& _varDecl);
/// Appends an implicit or explicit type conversion. For now this comprises only erasing
/// higher-order bits (@see appendHighBitCleanup) when widening integer.
/// If @a _cleanupNeeded, high order bits cleanup is also done if no type conversion would be
/// necessary.
void appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded = false);
private:
virtual bool visit(Assignment const& _assignment) override;
virtual bool visit(UnaryOperation const& _unaryOperation) override;
virtual bool visit(BinaryOperation const& _binaryOperation) override;
@ -87,11 +95,6 @@ private:
void appendShiftOperatorCode(Token::Value _operator);
/// @}
/// Appends an implicit or explicit type conversion. For now this comprises only erasing
/// higher-order bits (@see appendHighBitCleanup) when widening integer.
/// If @a _cleanupNeeded, high order bits cleanup is also done if no type conversion would be
/// necessary.
void appendTypeConversion(Type const& _typeOnStack, Type const& _targetType, bool _cleanupNeeded = false);
//// Appends code that cleans higher-order bits for integer types.
void appendHighBitsCleanup(IntegerType const& _typeOnStack);
@ -111,77 +114,34 @@ private:
/// expected to be on the stack and is updated by this call.
void appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression);
/// Appends code for a State Variable accessor function
void appendStateVariableAccessor(VariableDeclaration const& _varDecl);
/// Appends code for a State Variable initialization
void appendStateVariableInitialization(VariableDeclaration const& _varDecl);
/**
* Helper class to store and retrieve lvalues to and from various locations.
* All types except STACK store a reference in a slot on the stack, STACK just
* stores the base stack offset of the variable in @a m_baseStackOffset.
*/
class LValue
{
public:
enum class LValueType { None, Stack, Memory, Storage };
explicit LValue(CompilerContext& _compilerContext): m_context(&_compilerContext) { reset(); }
LValue(CompilerContext& _compilerContext, LValueType _type,
std::shared_ptr<Type const> const& _dataType, unsigned _baseStackOffset = 0);
/// Set type according to the declaration and retrieve the reference.
/// @a _location is the current location
void fromDeclaration(Declaration const& _declaration, Location const& _location);
void reset() { m_type = LValueType::None; m_dataType.reset(); m_baseStackOffset = 0; m_size = 0; }
bool isValid() const { return m_type != LValueType::None; }
bool isInOnStack() const { return m_type == LValueType::Stack; }
bool isInMemory() const { return m_type == LValueType::Memory; }
bool isInStorage() const { return m_type == LValueType::Storage; }
/// @returns true if this lvalue reference type occupies a slot on the stack.
bool storesReferenceOnStack() const { return m_type == LValueType::Storage || m_type == LValueType::Memory; }
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,
/// also removes the reference from the stack (note that is does not reset the type to @a NONE).
/// @a _location source location of the current expression, used for error reporting.
void retrieveValue(Location const& _location, bool _remove = false) const;
/// Moves a value from the stack to the lvalue. Removes the value if @a _move is true.
/// @a _location is the source location of the expression that caused this operation.
/// Stack pre: value [lvalue_ref]
/// Stack post if !_move: value_of(lvalue_ref)
void storeValue(Type const& _sourceType, Location const& _location = Location(), bool _move = false) const;
/// Stores zero in the lvalue.
/// @a _location is the source location of the requested operation
void setToZero(Location const& _location = Location()) const;
/// Convenience function to convert the stored reference to a value and reset type to NONE if
/// the reference was not requested by @a _expression.
void retrieveValueIfLValueNotRequested(Expression const& _expression);
private:
/// Convenience function to retrieve Value from Storage. Specific version of @ref retrieveValue
void retrieveValueFromStorage(bool _remove = false) const;
/// Copies from a byte array to a byte array in storage, both references on the stack.
void copyByteArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const;
CompilerContext* m_context;
LValueType m_type = LValueType::None;
std::shared_ptr<Type const> m_dataType;
/// If m_type is STACK, this is base stack offset (@see
/// CompilerContext::getBaseStackOffsetOfVariable) of a local variable.
unsigned m_baseStackOffset = 0;
/// Size of the value of this lvalue on the stack or the storage.
unsigned m_size = 0;
};
/// Sets the current LValue to a new one (of the appropriate type) from the given declaration.
/// Also retrieves the value if it was not requested by @a _expression.
void setLValueFromDeclaration(Declaration const& _declaration, Expression const& _expression);
/// Sets the current LValue to a StorageItem holding the type of @a _expression. The reference is assumed
/// to be on the stack.
/// Also retrieves the value if it was not requested by @a _expression.
void setLValueToStorageItem(Expression const& _expression);
/// Sets the current LValue to a new LValue constructed from the arguments.
/// Also retrieves the value if it was not requested by @a _expression.
template <class _LValueType, class... _Arguments>
void setLValue(Expression const& _expression, _Arguments const&... _arguments);
bool m_optimize;
CompilerContext& m_context;
LValue m_currentLValue;
std::unique_ptr<LValue> m_currentLValue;
};
template <class _LValueType, class... _Arguments>
void ExpressionCompiler::setLValue(Expression const& _expression, _Arguments const&... _arguments)
{
solAssert(!m_currentLValue, "Current LValue not reset before trying to set new one.");
std::unique_ptr<_LValueType> lvalue(new _LValueType(m_context, _arguments...));
if (_expression.lvalueRequested())
m_currentLValue = move(lvalue);
else
lvalue->retrieveValue(_expression.getLocation(), true);
}
}
}

223
libsolidity/LValue.cpp

@ -0,0 +1,223 @@
/*
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/>.
*/
/**
* @author Christian <c@ethdev.com>
* @date 2015
* LValues for use in the expresison compiler.
*/
#include <libsolidity/LValue.h>
#include <libevmcore/Instruction.h>
#include <libsolidity/Types.h>
#include <libsolidity/AST.h>
#include <libsolidity/CompilerUtils.h>
using namespace std;
using namespace dev;
using namespace solidity;
StackVariable::StackVariable(CompilerContext& _compilerContext, Declaration const& _declaration):
LValue(_compilerContext, _declaration.getType()),
m_baseStackOffset(m_context.getBaseStackOffsetOfVariable(_declaration)),
m_size(m_dataType->getSizeOnStack())
{
}
void StackVariable::retrieveValue(SourceLocation const& _location, bool _remove) const
{
(void)_remove;
unsigned stackPos = m_context.baseToCurrentStackOffset(m_baseStackOffset);
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
for (unsigned i = 0; i < m_size; ++i)
m_context << eth::dupInstruction(stackPos + 1);
}
void StackVariable::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const
{
(void)_sourceType;
unsigned stackDiff = m_context.baseToCurrentStackOffset(m_baseStackOffset) - m_size + 1;
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
else if (stackDiff > 0)
for (unsigned i = 0; i < m_size; ++i)
m_context << eth::swapInstruction(stackDiff) << eth::Instruction::POP;
if (!_move)
retrieveValue(_location);
}
void StackVariable::setToZero(SourceLocation const& _location) const
{
unsigned stackDiff = m_context.baseToCurrentStackOffset(m_baseStackOffset);
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
solAssert(stackDiff >= m_size - 1, "");
for (unsigned i = 0; i < m_size; ++i)
m_context << u256(0) << eth::swapInstruction(stackDiff + 1 - i)
<< eth::Instruction::POP;
}
StorageItem::StorageItem(CompilerContext& _compilerContext, Declaration const& _declaration):
StorageItem(_compilerContext, _declaration.getType())
{
m_context << m_context.getStorageLocationOfVariable(_declaration);
}
StorageItem::StorageItem(CompilerContext& _compilerContext, TypePointer const& _type):
LValue(_compilerContext, _type)
{
if (m_dataType->isValueType())
{
solAssert(m_dataType->getStorageSize() == m_dataType->getSizeOnStack(), "");
solAssert(m_dataType->getStorageSize() <= numeric_limits<unsigned>::max(),
"The storage size of " + m_dataType->toString() + " should fit in an unsigned");
m_size = unsigned(m_dataType->getStorageSize());
}
else
m_size = 0; // unused
}
void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
{
if (!m_dataType->isValueType())
return; // no distinction between value and reference for non-value types
if (!_remove)
m_context << eth::Instruction::DUP1;
if (m_size == 1)
m_context << eth::Instruction::SLOAD;
else
for (unsigned i = 0; i < m_size; ++i)
{
m_context << eth::Instruction::DUP1 << eth::Instruction::SLOAD << eth::Instruction::SWAP1;
if (i + 1 < m_size)
m_context << u256(1) << eth::Instruction::ADD;
else
m_context << eth::Instruction::POP;
}
}
void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const
{
// stack layout: value value ... value target_ref
if (m_dataType->isValueType())
{
if (!_move) // copy values
{
if (m_size + 1 > 16)
BOOST_THROW_EXCEPTION(CompilerError()
<< errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
for (unsigned i = 0; i < m_size; ++i)
m_context << eth::dupInstruction(m_size + 1) << eth::Instruction::SWAP1;
}
if (m_size > 1) // store high index value first
m_context << u256(m_size - 1) << eth::Instruction::ADD;
for (unsigned i = 0; i < m_size; ++i)
{
if (i + 1 >= m_size)
m_context << eth::Instruction::SSTORE;
else
// stack here: value value ... value value (target_ref+offset)
m_context << eth::Instruction::SWAP1 << eth::Instruction::DUP2
<< eth::Instruction::SSTORE
<< u256(1) << eth::Instruction::SWAP1 << eth::Instruction::SUB;
}
}
else
{
solAssert(_sourceType.getCategory() == m_dataType->getCategory(),
"Wrong type conversation for assignment.");
if (m_dataType->getCategory() == Type::Category::Array)
{
CompilerUtils(m_context).copyByteArrayToStorage(
dynamic_cast<ArrayType const&>(*m_dataType),
dynamic_cast<ArrayType const&>(_sourceType));
if (_move)
m_context << eth::Instruction::POP;
}
else if (m_dataType->getCategory() == Type::Category::Struct)
{
// stack layout: source_ref target_ref
auto const& structType = dynamic_cast<StructType const&>(*m_dataType);
solAssert(structType == _sourceType, "Struct assignment with conversion.");
for (auto const& member: structType.getMembers())
{
// assign each member that is not a mapping
TypePointer const& memberType = member.second;
if (memberType->getCategory() == Type::Category::Mapping)
continue;
m_context << structType.getStorageOffsetOfMember(member.first)
<< eth::Instruction::DUP3 << eth::Instruction::DUP2 << eth::Instruction::ADD;
// stack: source_ref target_ref member_offset source_member_ref
StorageItem(m_context, memberType).retrieveValue(_location, true);
// stack: source_ref target_ref member_offset source_value...
m_context << eth::dupInstruction(2 + memberType->getSizeOnStack())
<< eth::dupInstruction(2 + memberType->getSizeOnStack()) << eth::Instruction::ADD;
// stack: source_ref target_ref member_offset source_value... target_member_ref
StorageItem(m_context, memberType).storeValue(*memberType, _location, true);
m_context << eth::Instruction::POP;
}
if (_move)
m_context << eth::Instruction::POP;
else
m_context << eth::Instruction::SWAP1;
m_context << eth::Instruction::POP;
}
else
BOOST_THROW_EXCEPTION(InternalCompilerError()
<< errinfo_sourceLocation(_location) << errinfo_comment("Invalid non-value type for assignment."));
}
}
void StorageItem::setToZero(SourceLocation const& _location) const
{
(void)_location;
if (m_dataType->getCategory() == Type::Category::Array)
CompilerUtils(m_context).clearByteArray(dynamic_cast<ArrayType const&>(*m_dataType));
else if (m_dataType->getCategory() == Type::Category::Struct)
{
// stack layout: ref
auto const& structType = dynamic_cast<StructType const&>(*m_dataType);
for (auto const& member: structType.getMembers())
{
// zero each member that is not a mapping
TypePointer const& memberType = member.second;
if (memberType->getCategory() == Type::Category::Mapping)
continue;
m_context << structType.getStorageOffsetOfMember(member.first)
<< eth::Instruction::DUP2 << eth::Instruction::ADD;
StorageItem(m_context, memberType).setToZero();
}
m_context << eth::Instruction::POP;
}
else
{
if (m_size == 0)
m_context << eth::Instruction::POP;
for (unsigned i = 0; i < m_size; ++i)
if (i + 1 >= m_size)
m_context << u256(0) << eth::Instruction::SWAP1 << eth::Instruction::SSTORE;
else
m_context << u256(0) << eth::Instruction::DUP2 << eth::Instruction::SSTORE
<< u256(1) << eth::Instruction::ADD;
}
}

112
libsolidity/LValue.h

@ -0,0 +1,112 @@
/*
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/>.
*/
/**
* @author Christian <c@ethdev.com>
* @date 2015
* LValues for use in the expresison compiler.
*/
#pragma once
#include <memory>
#include <libevmcore/SourceLocation.h>
namespace dev
{
namespace solidity
{
class Declaration;
class Type;
class CompilerContext;
/**
* Abstract class used to retrieve, delete and store data in lvalues/variables.
*/
class LValue
{
protected:
LValue(CompilerContext& _compilerContext, std::shared_ptr<Type const> const& _dataType):
m_context(_compilerContext), m_dataType(_dataType) {}
public:
/// @returns true if this lvalue reference type occupies a slot on the stack.
virtual bool storesReferenceOnStack() const = 0;
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,
/// also removes the reference from the stack.
/// @a _location source location of the current expression, used for error reporting.
virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const = 0;
/// Moves a value from the stack to the lvalue. Removes the value if @a _move is true.
/// @a _location is the source location of the expression that caused this operation.
/// Stack pre: value [lvalue_ref]
/// Stack post: if !_move: value_of(lvalue_ref)
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const = 0;
/// Stores zero in the lvalue.
/// @a _location is the source location of the requested operation
virtual void setToZero(SourceLocation const& _location = SourceLocation()) const = 0;
protected:
CompilerContext& m_context;
std::shared_ptr<Type const> m_dataType;
};
/**
* Local variable that is completely stored on the stack.
*/
class StackVariable: public LValue
{
public:
explicit StackVariable(CompilerContext& _compilerContext, Declaration const& _declaration);
virtual bool storesReferenceOnStack() const { return false; }
virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const override;
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const override;
virtual void setToZero(SourceLocation const& _location = SourceLocation()) const override;
private:
/// Base stack offset (@see CompilerContext::getBaseStackOffsetOfVariable) of the local variable.
unsigned m_baseStackOffset;
/// Number of stack elements occupied by the value (not the reference).
unsigned m_size;
};
/**
* Reference to some item in storage. The (starting) position of the item is stored on the stack.
*/
class StorageItem: public LValue
{
public:
/// Constructs the LValue and pushes the location of @a _declaration onto the stack.
explicit StorageItem(CompilerContext& _compilerContext, Declaration const& _declaration);
/// Constructs the LValue and assumes that the storage reference is already on the stack.
explicit StorageItem(CompilerContext& _compilerContext, std::shared_ptr<Type const> const& _type);
virtual bool storesReferenceOnStack() const { return true; }
virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const override;
virtual void storeValue(Type const& _sourceType,
SourceLocation const& _location = SourceLocation(), bool _move = false) const override;
virtual void setToZero(SourceLocation const& _location = SourceLocation()) const override;
private:
/// Number of stack elements occupied by the value (not the reference).
/// Only used for value types.
unsigned m_size;
};
}
}

16
libsolidity/Parser.cpp

@ -22,7 +22,7 @@
#include <vector>
#include <libdevcore/Log.h>
#include <libsolidity/BaseTypes.h>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/Parser.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Exceptions.h>
@ -45,7 +45,7 @@ public:
m_parser(_parser), m_location(_childNode->getLocation()) {}
void markEndPosition() { m_location.end = m_parser.getEndPosition(); }
void setLocation(Location const& _location) { m_location = _location; }
void setLocation(SourceLocation const& _location) { m_location = _location; }
void setLocationEmpty() { m_location.end = m_location.start; }
/// Set the end position to the one of the given node.
void setEndPositionFromNode(ASTPointer<ASTNode> const& _node) { m_location.end = _node->getLocation().end; }
@ -60,7 +60,7 @@ public:
private:
Parser const& m_parser;
Location m_location;
SourceLocation m_location;
};
ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
@ -646,9 +646,9 @@ ASTPointer<Statement> Parser::parseSimpleStatement()
primary = ASTNodeFactory(*this).createNode<ElementaryTypeNameExpression>(m_scanner->getCurrentToken());
m_scanner->next();
}
vector<pair<ASTPointer<Expression>, Location>> indices;
vector<pair<ASTPointer<Expression>, SourceLocation>> indices;
solAssert(m_scanner->getCurrentToken() == Token::LBrack, "");
Location indexLocation = primary->getLocation();
SourceLocation indexLocation = primary->getLocation();
do
{
expectToken(Token::LBrack);
@ -913,7 +913,7 @@ Parser::LookAheadInfo Parser::peekStatementType() const
}
ASTPointer<TypeName> Parser::typeNameIndexAccessStructure(
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, SourceLocation>> const& _indices)
{
ASTNodeFactory nodeFactory(*this, _primary);
ASTPointer<TypeName> type;
@ -932,7 +932,7 @@ ASTPointer<TypeName> Parser::typeNameIndexAccessStructure(
}
ASTPointer<Expression> Parser::expressionFromIndexAccessStructure(
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, Location>> const& _indices)
ASTPointer<PrimaryExpression> const& _primary, vector<pair<ASTPointer<Expression>, SourceLocation>> const& _indices)
{
ASTNodeFactory nodeFactory(*this, _primary);
ASTPointer<Expression> expression(_primary);
@ -983,7 +983,7 @@ ASTPointer<ParameterList> Parser::createEmptyParameterList()
ParserError Parser::createParserError(string const& _description) const
{
return ParserError() << errinfo_sourceLocation(Location(getPosition(), getPosition(), getSourceName()))
return ParserError() << errinfo_sourceLocation(SourceLocation(getPosition(), getPosition(), getSourceName()))
<< errinfo_comment(_description);
}

4
libsolidity/Parser.h

@ -114,11 +114,11 @@ private:
/// Returns a typename parsed in look-ahead fashion from something like "a[8][2**70]".
ASTPointer<TypeName> typeNameIndexAccessStructure(
ASTPointer<PrimaryExpression> const& _primary,
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices);
/// Returns an expression parsed in look-ahead fashion from something like "a[8][2**70]".
ASTPointer<Expression> expressionFromIndexAccessStructure(
ASTPointer<PrimaryExpression> const& _primary,
std::vector<std::pair<ASTPointer<Expression>, Location>> const& _indices);
std::vector<std::pair<ASTPointer<Expression>, SourceLocation>> const& _indices);
/// If current token value is not _value, throw exception otherwise advance token.
void expectToken(Token::Value _value);
Token::Value expectAssignmentOperator();

10
libsolidity/Scanner.h

@ -55,7 +55,7 @@
#include <libdevcore/Common.h>
#include <libdevcore/Log.h>
#include <libdevcore/CommonData.h>
#include <libsolidity/BaseTypes.h>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/Token.h>
namespace dev
@ -120,14 +120,14 @@ public:
return m_currentToken.token;
}
Location getCurrentLocation() const { return m_currentToken.location; }
SourceLocation getCurrentLocation() const { return m_currentToken.location; }
std::string const& getCurrentLiteral() const { return m_currentToken.literal; }
///@}
///@{
///@name Information about the current comment token
Location getCurrentCommentLocation() const { return m_skippedComment.location; }
SourceLocation getCurrentCommentLocation() const { return m_skippedComment.location; }
std::string const& getCurrentCommentLiteral() const { return m_skippedComment.literal; }
/// Called by the parser during FunctionDefinition parsing to clear the current comment
void clearCurrentCommentLiteral() { m_skippedComment.literal.clear(); }
@ -139,7 +139,7 @@ public:
/// Returns the next token without advancing input.
Token::Value peekNextToken() const { return m_nextToken.token; }
Location peekLocation() const { return m_nextToken.location; }
SourceLocation peekLocation() const { return m_nextToken.location; }
std::string const& peekLiteral() const { return m_nextToken.literal; }
///@}
@ -158,7 +158,7 @@ private:
struct TokenDesc
{
Token::Value token;
Location location;
SourceLocation location;
std::string literal;
};

4
libsolidity/SourceReferenceFormatter.cpp

@ -33,7 +33,7 @@ namespace solidity
{
void SourceReferenceFormatter::printSourceLocation(ostream& _stream,
Location const& _location,
SourceLocation const& _location,
Scanner const& _scanner)
{
int startLine;
@ -63,7 +63,7 @@ void SourceReferenceFormatter::printExceptionInformation(ostream& _stream,
string const& _name,
CompilerStack const& _compiler)
{
Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
Scanner const* scanner;
if (location)

4
libsolidity/SourceReferenceFormatter.h

@ -23,7 +23,7 @@
#pragma once
#include <ostream>
#include <libsolidity/BaseTypes.h>
#include <libevmcore/SourceLocation.h>
namespace dev
{
@ -39,7 +39,7 @@ class CompilerStack; // forward
struct SourceReferenceFormatter
{
public:
static void printSourceLocation(std::ostream& _stream, Location const& _location, Scanner const& _scanner);
static void printSourceLocation(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner);
static void printExceptionInformation(std::ostream& _stream, Exception const& _exception,
std::string const& _name, CompilerStack const& _compiler);
};

4
mix/CodeHighlighter.cpp

@ -64,7 +64,7 @@ namespace
};
}
CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, dev::solidity::Location const& _location):
CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, dev::SourceLocation const& _location):
token(_t), start(_location.start), length(_location.end - _location.start)
{}
@ -101,7 +101,7 @@ void CodeHighlighter::processAST(dev::solidity::ASTNode const& _ast)
void CodeHighlighter::processError(dev::Exception const& _exception)
{
Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
if (location)
m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location));
}

5
mix/CodeHighlighter.h

@ -32,11 +32,10 @@ namespace dev
{
struct Exception;
struct SourceLocation;
namespace solidity
{
class ASTNode;
struct Location;
}
namespace mix
@ -74,7 +73,7 @@ public:
struct FormatRange
{
FormatRange(CodeHighlighterSettings::Token _t, int _start, int _length): token(_t), start(_start), length(_length) {}
FormatRange(CodeHighlighterSettings::Token _t, solidity::Location const& _location);
FormatRange(CodeHighlighterSettings::Token _t, SourceLocation const& _location);
bool operator<(FormatRange const& _other) const { return start < _other.start || (start == _other.start && length < _other.length); }
CodeHighlighterSettings::Token token;

3
mix/CodeModel.cpp

@ -25,6 +25,7 @@
#include <QDebug>
#include <QApplication>
#include <QtQml>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/CompilerStack.h>
#include <libsolidity/SourceReferenceFormatter.h>
#include <libsolidity/InterfaceHandler.h>
@ -212,7 +213,7 @@ void CodeModel::runCompilationJob(int _jobId)
{
std::ostringstream error;
solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs);
solidity::Location const* location = boost::get_error_info<solidity::errinfo_sourceLocation>(_exception);
SourceLocation const* location = boost::get_error_info<solidity::errinfo_sourceLocation>(_exception);
QString message = QString::fromStdString(error.str());
CompiledContract* contract = nullptr;
if (location && location->sourceName.get() && (contract = contractByDocumentId(QString::fromStdString(*location->sourceName))))

47
mix/FileIo.cpp

@ -37,21 +37,34 @@ using namespace dev;
using namespace dev::crypto;
using namespace dev::mix;
void FileIo::makeDir(QString const& _url)
QString FileIo::pathFromUrl(QString const& _url)
{
QUrl url(_url);
QDir dirPath(url.path());
QString path(url.path());
if (url.scheme() == "qrc")
path = ":" + path;
#ifdef WIN32
if (url.scheme() == "file")
{
if (path.startsWith("/"))
path = path.right(path.length() - 1);
if (!url.host().isEmpty())
path = url.host() + ":/" + path;
}
#endif
return path;
}
void FileIo::makeDir(QString const& _url)
{
QDir dirPath(pathFromUrl(_url));
if (!dirPath.exists())
dirPath.mkpath(dirPath.path());
}
QString FileIo::readFile(QString const& _url)
{
QUrl url(_url);
QString path(url.path());
if (url.scheme() == "qrc")
path = ":" + path;
QFile file(path);
QFile file(pathFromUrl(_url));
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
@ -65,8 +78,7 @@ QString FileIo::readFile(QString const& _url)
void FileIo::writeFile(QString const& _url, QString const& _data)
{
QUrl url(_url);
QFile file(url.path());
QFile file(pathFromUrl(_url));
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream stream(&file);
@ -84,9 +96,7 @@ void FileIo::copyFile(QString const& _sourceUrl, QString const& _destUrl)
return;
}
QUrl sourceUrl(_sourceUrl);
QUrl destUrl(_destUrl);
if (!QFile::copy(sourceUrl.path(), destUrl.path()))
if (!QFile::copy(pathFromUrl(_sourceUrl), pathFromUrl(_destUrl)))
error(tr("Error copying file %1 to %2").arg(_sourceUrl).arg(_destUrl));
}
@ -97,29 +107,22 @@ QString FileIo::getHomePath() const
void FileIo::moveFile(QString const& _sourceUrl, QString const& _destUrl)
{
QUrl sourceUrl(_sourceUrl);
QUrl destUrl(_destUrl);
if (!QFile::rename(sourceUrl.path(), destUrl.path()))
if (!QFile::rename(pathFromUrl(_sourceUrl), pathFromUrl(_destUrl)))
error(tr("Error moving file %1 to %2").arg(_sourceUrl).arg(_destUrl));
}
bool FileIo::fileExists(QString const& _url)
{
QUrl url(_url);
QFile file(url.path());
QFile file(pathFromUrl(_url));
return file.exists();
}
QStringList FileIo::makePackage(QString const& _deploymentFolder)
{
Json::Value manifest;
Json::Value entries(Json::arrayValue);
QUrl folder(_deploymentFolder);
QString path(folder.path());
QDir deployDir = QDir(path);
QDir deployDir = QDir(pathFromUrl(_deploymentFolder));
dev::RLPStream rlpStr;
int k = 1;
std::vector<bytes> files;

1
mix/FileIo.h

@ -58,6 +58,7 @@ public:
private:
QString getHomePath() const;
QString pathFromUrl(QString const& _url);
};
}

2
mix/qml/NewProjectDialog.qml

@ -101,6 +101,8 @@ Window {
var u = createProjectFileDialog.fileUrl.toString();
if (u.indexOf("file://") == 0)
u = u.substring(7, u.length)
if (Qt.platform.os == "windows" && u.indexOf("/") == 0)
u = u.substring(1, u.length);
pathField.text = u;
}
}

129
test/Assembly.cpp

@ -0,0 +1,129 @@
/*
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/>.
*/
/**
* @author Lefteris Karapetsas <lefteris@ethdev.com>
* @date 2015
* Unit tests for Assembly Items from evmcore/Assembly.h
*/
#include <string>
#include <iostream>
#include <boost/test/unit_test.hpp>
#include <libdevcore/Log.h>
#include <libevmcore/SourceLocation.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Parser.h>
#include <libsolidity/NameAndTypeResolver.h>
#include <libsolidity/Compiler.h>
#include <libsolidity/AST.h>
#include <libevmcore/Assembly.h>
using namespace std;
using namespace dev::eth;
namespace dev
{
namespace solidity
{
namespace test
{
namespace
{
eth::AssemblyItems compileContract(const string& _sourceCode)
{
Parser parser;
ASTPointer<SourceUnit> sourceUnit;
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
NameAndTypeResolver resolver({});
resolver.registerDeclarations(*sourceUnit);
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
BOOST_REQUIRE_NO_THROW(resolver.resolveNamesAndTypes(*contract));
}
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
BOOST_REQUIRE_NO_THROW(resolver.checkTypeRequirements(*contract));
}
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{
Compiler compiler;
compiler.compileContract(*contract, map<ContractDefinition const*, bytes const*>{});
return compiler.getRuntimeAssemblyItems();
}
BOOST_FAIL("No contract found in source.");
return AssemblyItems();
}
void checkAssemblyLocations(AssemblyItems const& _items, std::vector<SourceLocation> _locations)
{
size_t i = 0;
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
for (auto const& it: _items)
{
BOOST_CHECK_MESSAGE(it.getLocation() == _locations[i],
std::string("Location mismatch for assembly item ") + std::to_string(i));
++i;
}
}
} // end anonymous namespace
BOOST_AUTO_TEST_SUITE(Assembly)
BOOST_AUTO_TEST_CASE(location_test)
{
char const* sourceCode = "contract test {\n"
" function f() returns (uint256 a)\n"
" {\n"
" return 16;\n"
" }\n"
"}\n";
std::shared_ptr<std::string const> n = make_shared<std::string>("source");
AssemblyItems items = compileContract(sourceCode);
std::vector<SourceLocation> locations {
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(), SourceLocation(),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(), SourceLocation(), SourceLocation(),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n), SourceLocation(0, 77, n),
SourceLocation(0, 77, n),
SourceLocation(18, 75, n), SourceLocation(40, 49, n),
SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n),
SourceLocation(), SourceLocation(),
SourceLocation(61, 70, n), SourceLocation(61, 70, n), SourceLocation(61, 70, n)
};
checkAssemblyLocations(items, locations);
}
BOOST_AUTO_TEST_SUITE_END()
}
}
} // end namespaces

3
test/SolidityExpressionCompiler.cpp

@ -127,6 +127,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
BOOST_REQUIRE(extractor.getExpression() != nullptr);
CompilerContext context;
context.resetVisitedNodes(contract);
context.setInheritanceHierarchy(inheritanceHierarchy);
unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack
context.adjustStackOffset(parametersSize);
@ -134,7 +135,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _
context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver)),
parametersSize--);
ExpressionCompiler::compileExpression(context, *extractor.getExpression());
ExpressionCompiler(context).compile(*extractor.getExpression());
for (vector<string> const& function: _functions)
context << context.getFunctionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver)));

2
test/SolidityInterface.cpp

@ -50,7 +50,7 @@ public:
string getSourcePart(ASTNode const& _node) const
{
Location location = _node.getLocation();
SourceLocation location = _node.getLocation();
BOOST_REQUIRE(!location.isEmpty());
return m_interface.substr(location.start, location.end - location.start);
}

50
test/TestHelper.cpp

@ -139,27 +139,35 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state)
}
void ImportTest::importTransaction(json_spirit::mObject& _o)
{
BOOST_REQUIRE(_o.count("nonce")> 0);
BOOST_REQUIRE(_o.count("gasPrice") > 0);
BOOST_REQUIRE(_o.count("gasLimit") > 0);
BOOST_REQUIRE(_o.count("to") > 0);
BOOST_REQUIRE(_o.count("value") > 0);
BOOST_REQUIRE(_o.count("secretKey") > 0);
BOOST_REQUIRE(_o.count("data") > 0);
if (bigint(_o["nonce"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'nonce' is equal or greater than 2**256") );
if (bigint(_o["gasPrice"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasPrice' is equal or greater than 2**256") );
if (bigint(_o["gasLimit"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasLimit' is equal or greater than 2**256") );
if (bigint(_o["value"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'value' is equal or greater than 2**256") );
m_transaction = _o["to"].get_str().empty() ?
Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) :
Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), Address(_o["to"].get_str()), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str()));
{
if (_o.count("secretKey") > 0)
{
BOOST_REQUIRE(_o.count("nonce") > 0);
BOOST_REQUIRE(_o.count("gasPrice") > 0);
BOOST_REQUIRE(_o.count("gasLimit") > 0);
BOOST_REQUIRE(_o.count("to") > 0);
BOOST_REQUIRE(_o.count("value") > 0);
BOOST_REQUIRE(_o.count("data") > 0);
if (bigint(_o["nonce"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'nonce' is equal or greater than 2**256") );
if (bigint(_o["gasPrice"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasPrice' is equal or greater than 2**256") );
if (bigint(_o["gasLimit"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'gasLimit' is equal or greater than 2**256") );
if (bigint(_o["value"].get_str()) >= c_max256plus1)
BOOST_THROW_EXCEPTION(ValueTooLarge() << errinfo_comment("Transaction 'value' is equal or greater than 2**256") );
m_transaction = _o["to"].get_str().empty() ?
Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) :
Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), Address(_o["to"].get_str()), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str()));
}
else
{
RLPStream transactionRLPStream = createRLPStreamFromTransactionFields(_o);
RLP transactionRLP(transactionRLPStream.out());
m_transaction = Transaction(transactionRLP.data(), CheckSignature::Sender);
}
}
void ImportTest::exportTest(bytes _output, State& _statePost)

5
test/block.cpp

@ -496,6 +496,11 @@ BOOST_AUTO_TEST_CASE(blValidBlockTest)
dev::test::executeTests("blValidBlockTest", "/BlockTests", dev::test::doBlockTests);
}
BOOST_AUTO_TEST_CASE(blInvalidTransactionRLP)
{
dev::test::executeTests("blInvalidTransactionRLP", "/BlockTests", dev::test::doBlockTests);
}
BOOST_AUTO_TEST_CASE(blInvalidHeaderTest)
{
dev::test::executeTests("blInvalidHeaderTest", "/BlockTests", dev::test::doBlockTests);

1533
test/stMemoryTestFiller.json

File diff suppressed because it is too large

352
test/stQuadraticComplexityTestFiller.json

@ -0,0 +1,352 @@
{
"QuadraticComplexitySolidity_CallDataCopy" : {
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "45678256",
"currentGasLimit" : "350000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "500000000",
"//" : "contract caller ",
"//" : "{ ",
"//" : " int value; ",
"//" : " function run(int count) ",
"//" : " { ",
"//" : " value = count; ",
"//" : " address a = 0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b; ",
"//" : " while(count > 0) ",
"//" : " { ",
"//" : " a.call('just', 'call'); ",
"//" : " count = count - 1; ",
"//" : " } ",
"//" : " } ",
"//" : "} ",
"code" : "0x60003560e060020a9004806361a4770614601557005b601e6004356024565b60006000f35b60008160008190555073b94f5374fce5edbc8e2a8697c15331677e6ebf0b90505b600082131560bf5780600160a060020a03166000600060007f6a7573740000000000000000000000000000000000000000000000000000000081526004017f63616c6c000000000000000000000000000000000000000000000000000000008152602001600060008560155a03f150506001820391506045565b505056",
"nonce" : "0",
"storage" : {
}
},
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "5000000",
"code" : "{ (CALLDATACOPY 0 0 50000) }",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"//" : "run(int256)",
"data" : "0x61a47706000000000000000000000000000000000000000000000000000000000000c350",
"gasLimit" : "904+68*x+e",
"gasLimit" : "350000000",
"gasPrice" : "1",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "1"
}
},
"Call50000" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "86000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "7000",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 1600 0xaaaf5374fce5edbc8e2a8697c15331677e6ebf0b 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "85000000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Callcode50000" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "86000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"aaaf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "7000",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALLCODE 1600 0xaaaf5374fce5edbc8e2a8697c15331677e6ebf0b 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "85000000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Create1000" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "86000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 1000) [i](+ @i 1) [[ 0 ]] (CREATE 1 0 50000) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "85000000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Call50000_ecrec" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "95000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 500 1 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "94500000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Call50000_sha256" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "3925000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 78200 2 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "3925000000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Call50000_rip160" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "3925000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 78200 3 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "3925000000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
},
"Call50000_identity" : {
"env" : {
"currentCoinbase" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty" : "45678256",
"currentGasLimit" : "88250000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xffffffffffffffffffffffffffffffff",
"code" : "",
"nonce" : "0",
"storage" : {
}
},
"bbbf5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xfffffffffffff",
"code" : "{ (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 1564 4 1 0 50000 0 0) ) [[ 1 ]] @i}",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"data" : "",
"gasLimit" : "88250000",
"gasPrice" : "1",
"nonce" : "",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "bbbf5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10"
}
}
}

55
test/stSolidityTestFiller.json

@ -525,60 +525,5 @@
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "1"
}
},
"QuadraticComplexity" : {
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "45678256",
"currentGasLimit" : "100000000",
"currentNumber" : "0",
"currentTimestamp" : 1,
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"pre" :
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "10000000",
"//" : "contract caller ",
"//" : "{ ",
"//" : " int value; ",
"//" : " function run(int count) ",
"//" : " { ",
"//" : " value = count; ",
"//" : " address a = 0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b; ",
"//" : " while(count > 0) ",
"//" : " { ",
"//" : " a.call('just', 'call'); ",
"//" : " count = count - 1; ",
"//" : " } ",
"//" : " } ",
"//" : "} ",
"code" : "0x60003560e060020a9004806361a4770614601557005b601e6004356024565b60006000f35b60008160008190555073b94f5374fce5edbc8e2a8697c15331677e6ebf0b90505b600082131560bf5780600160a060020a03166000600060007f6a7573740000000000000000000000000000000000000000000000000000000081526004017f63616c6c000000000000000000000000000000000000000000000000000000008152602001600060008560155a03f150506001820391506045565b505056",
"nonce" : "0",
"storage" : {
}
},
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "100000",
"code" : "{ (CALLDATACOPY 0 0 32) }",
"nonce" : "0",
"storage" : {
}
}
},
"transaction" :
{
"//" : "run(int256)",
"data" : "0x61a47706000000000000000000000000000000000000000000000000000000000000c350",
"gasLimit" : "904+68*x+e",
"gasLimit" : "3500000",
"gasPrice" : "1",
"nonce" : "0",
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"to" : "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "1"
}
}
}

1015
test/stSystemOperationsTestFiller.json

File diff suppressed because it is too large

10
test/stTransactionTestFiller.json

@ -547,7 +547,7 @@
"code" : "{(CALL 0 0 1 0 0 0 0) (SUICIDE 0)}",
"nonce" : "0",
"storage" : {
}
}
},
"0000000000000000000000000000000000000000" : {
@ -596,7 +596,7 @@
"code" : "{(CALL 20 0 1 0 0 0 0) (SUICIDE 0)}",
"nonce" : "0",
"storage" : {
}
}
},
"0000000000000000000000000000000000000000" : {
@ -645,7 +645,7 @@
"code" : "{(SUICIDE 0) (CALL 0 2000 0 0 0 0 0) }",
"nonce" : "0",
"storage" : {
}
}
},
"0000000000000000000000000000000000000000" : {
@ -693,7 +693,7 @@
"code" : "{(SUICIDE 0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b)}",
"nonce" : "0",
"storage" : {
}
}
}
},
@ -733,7 +733,7 @@
"code" : "{(SUICIDE 0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b)}",
"nonce" : "0",
"storage" : {
}
}
}
},

23
test/state.cpp

@ -159,11 +159,34 @@ BOOST_AUTO_TEST_CASE(stBlockHashTest)
dev::test::executeTests("stBlockHashTest", "/StateTests", dev::test::doStateTests);
}
BOOST_AUTO_TEST_CASE(stQuadraticComplexityTest)
{
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
{
string arg = boost::unit_test::framework::master_test_suite().argv[i];
if (arg == "--quadratic" || arg == "--all")
{
auto start = chrono::steady_clock::now();
dev::test::executeTests("stQuadraticComplexityTest", "/StateTests", dev::test::doStateTests);
auto end = chrono::steady_clock::now();
auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
cnote << "test duration: " << duration.count() << " milliseconds.\n";
}
}
}
BOOST_AUTO_TEST_CASE(stSolidityTest)
{
dev::test::executeTests("stSolidityTest", "/StateTests", dev::test::doStateTests);
}
BOOST_AUTO_TEST_CASE(stMemoryTest)
{
dev::test::executeTests("stMemoryTest", "/StateTests", dev::test::doStateTests);
}
BOOST_AUTO_TEST_CASE(stCreateTest)
{
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)

19
test/transaction.cpp

@ -90,8 +90,9 @@ void doTransactionTests(json_spirit::mValue& _v, bool _fillin)
o["sender"] = toString(txFromFields.sender());
}
catch(...)
catch(Exception const& _e)
{
cnote << "Transaction Exception: " << diagnostic_information(_e);
o.erase(o.find("transaction"));
}
}
@ -115,7 +116,21 @@ BOOST_AUTO_TEST_CASE(ttWrongRLPTransaction)
BOOST_AUTO_TEST_CASE(tt10mbDataField)
{
dev::test::executeTests("tt10mbDataField", "/TransactionTests", dev::test::doTransactionTests);
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
{
string arg = boost::unit_test::framework::master_test_suite().argv[i];
if (arg == "--bigdata" || arg == "--all")
{
auto start = chrono::steady_clock::now();
dev::test::executeTests("tt10mbDataField", "/TransactionTests", dev::test::doTransactionTests);
auto end = chrono::steady_clock::now();
auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
cnote << "test duration: " << duration.count() << " milliseconds.\n";
}
}
}
BOOST_AUTO_TEST_CASE(ttCreateTest)

169
test/ttTransactionTestFiller.json

@ -14,7 +14,7 @@
}
},
"WrongVRSTestVl27" : {
"WrongVRSTestVl26" : {
"transaction" :
{
"data" : "",
@ -29,6 +29,21 @@
}
},
"WrongVRSTestVl29" : {
"transaction" :
{
"data" : "",
"gasLimit" : "2000",
"gasPrice" : "1",
"nonce" : "0",
"to" : "b94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"value" : "10",
"v" : "29",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"WrongVRSTestVge31" : {
"transaction" :
{
@ -136,7 +151,22 @@
}
},
"TransactionWithSvalueOverflow" : {
"TransactionWithSvalueHigh" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e"
}
},
"TransactionWithSvalueTooHigh" : {
"transaction" :
{
"data" : "",
@ -151,7 +181,52 @@
}
},
"TransactionWithSvalueOverflow" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0000"
}
},
"TransactionWithRvalueOverflow" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641410000",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithRvalueHigh" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",
"s" : "0x8887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
}
},
"TransactionWithRvalueTooHigh" : {
"transaction" :
{
"data" : "",
@ -166,6 +241,51 @@
}
},
"TransactionWithRvalueWrongSize" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0xebaaedce6af48a03bbfd25e8cd0364141",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithSvalueWrongSize" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "11",
"v" : "27",
"r" : "0x98ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4a",
"s" : "0xef0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithHihghNonce" : {
"transaction" :
{
"data" : "",
"gasLimit" : "850",
"gasPrice" : "1",
"nonce" : "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "0",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithNonceOverflow" : {
"transaction" :
{
@ -181,6 +301,51 @@
}
},
"TransactionWithHihghGas" : {
"transaction" :
{
"data" : "",
"gasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"gasPrice" : "1",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "0",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithHihghGasPrice" : {
"transaction" :
{
"data" : "",
"gasLimit" : "1000",
"gasPrice" : "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "0",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithGasLimitxPriceOverflow" : {
"transaction" :
{
"data" : "",
"gasLimit" : "115792089237316195423570985008687907853269984665640564039457584007913129639935",
"gasPrice" : "100000000000000000",
"nonce" : "0",
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
"value" : "0",
"v" : "27",
"r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353",
"s" : "0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"
}
},
"TransactionWithGasPriceOverflow" : {
"transaction" :
{

6
test/vm.cpp

@ -518,7 +518,7 @@ BOOST_AUTO_TEST_CASE(vmPerformanceTest)
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
{
string arg = boost::unit_test::framework::master_test_suite().argv[i];
if (arg == "--performance")
if (arg == "--performance" || arg == "--all")
{
auto start = chrono::steady_clock::now();
@ -536,7 +536,7 @@ BOOST_AUTO_TEST_CASE(vmInputLimitsTest1)
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
{
string arg = boost::unit_test::framework::master_test_suite().argv[i];
if (arg == "--inputlimits")
if (arg == "--inputlimits" || arg == "--all")
{
auto start = chrono::steady_clock::now();
@ -554,7 +554,7 @@ BOOST_AUTO_TEST_CASE(vmInputLimitsTest2)
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
{
string arg = boost::unit_test::framework::master_test_suite().argv[i];
if (arg == "--inputlimits")
if (arg == "--inputlimits" || arg == "--all")
dev::test::executeTests("vmInputLimitsTest2", "/VMTests", dev::test::doVMTests);
}
}

142
test/vmArithmeticTestFiller.json

@ -897,7 +897,7 @@
}
},
"sdiv5": {
"sdiv_i256min": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
@ -925,6 +925,62 @@
}
},
"sdiv_i256min2": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SDIV (- 0 57896044618658097711785492504343953926634992332820282019728792003956564819968) (- 0 1) ) }",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"sdiv_i256min3": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SDIV 115792089237316195423570985008687907853269984665640564039457584007913129639935 (- 0 57896044618658097711785492504343953926634992332820282019728792003956564819967) ) }",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"mod0": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
@ -1205,6 +1261,90 @@
}
},
"smod5": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SMOD (- 0 57896044618658097711785492504343953926634992332820282019728792003956564819967) 57896044618658097711785492504343953926634992332820282019728792003956564819967)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"smod6": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SMOD (- 0 115792089237316195423570985008687907853269984665640564039457584007913129639935) 57896044618658097711785492504343953926634992332820282019728792003956564819967)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"smod7": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SMOD (- 0 57896044618658097711785492504343953926634992332820282019728792003956564819967) 115792089237316195423570985008687907853269984665640564039457584007913129639935)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f2947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "",
"gasPrice" : "100000000000000",
"gas" : "10000"
}
},
"addmod0": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",

168
test/vmEnvironmentalInfoTestFiller.json

@ -703,6 +703,174 @@
}
},
"calldatacopy0_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 1 2 ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"calldatacopyZeroMemExpansion_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 0 0 ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"calldatacopy_DataIndexTooHigh_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa 0xff ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"calldatacopy_DataIndexTooHigh2_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa 9 ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"calldatacopy1_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 1 1 ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"calldatacopy2_return": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"nonce" : "0",
"code" : "{ (CALLDATACOPY 0 1 0 ) (RETURN 0 (MSIZE))}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000",
"data" : "0x1234567890abcdef01234567890abcdef",
"gasPrice" : "1000000000",
"gas" : "100000000000"
}
},
"codesize": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",

238
test/vmSha3TestFiller.json

@ -201,13 +201,13 @@
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : 0,
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}",
"storage": {}
}
@ -229,13 +229,13 @@
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : 0,
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 2)}",
"storage": {}
}
@ -257,13 +257,13 @@
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : 1,
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : 0,
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 0x1000000 2)}",
"storage": {}
}
@ -277,5 +277,229 @@
"gasPrice" : "1",
"gas" : "0x100000000"
}
}
},
"sha3_memSizeNoQuadraticCost31": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 960 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost32": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 992 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost32_zeroSize": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 1024 0)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost33": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 1024 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost63": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 1984 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost64": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 2016 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost64_2": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 2016 32)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
"sha3_memSizeQuadraticCost65": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0",
"currentGasLimit" : "1000000",
"currentDifficulty" : "256",
"currentTimestamp" : "1",
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"nonce" : "0",
"code" : "{ [[ 0 ]] (SHA3 2048 1)}",
"storage": {}
}
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"data" : "",
"gasPrice" : "1",
"gas" : "0x100000000"
}
},
}

Loading…
Cancel
Save