Skip to content

Commit c1dec49

Browse files
committed
Merge branch 'master' of github.com:ethereum/solc-js into link-bytecode-using-references
2 parents 8cc1dee + a3b7b9e commit c1dec49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3728
-1792
lines changed

.circleci/config.yml

Lines changed: 356 additions & 24 deletions
Large diffs are not rendered by default.

.eslintrc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true
6+
},
7+
extends: [
8+
'standard'
9+
],
10+
parser: '@typescript-eslint/parser',
11+
plugins: [
12+
'@typescript-eslint'
13+
],
14+
parserOptions: {
15+
ecmaVersion: 12,
16+
sourceType: 'module'
17+
},
18+
rules: {
19+
semi: ['error', 'always']
20+
},
21+
ignorePatterns: ['dist', 'soljson.js']
22+
};

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ bin
3939
out
4040
*.bin
4141
*.abi
42+
43+
dist/**
44+
45+
.nyc_output

.nycrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"exclude": [
3+
"coverage",
4+
"dist/soljson.js",
5+
"**/test/**"
6+
],
7+
"extensions": [
8+
".js"
9+
],
10+
"report-dir": "./coverage",
11+
"reporter": [
12+
"lcov",
13+
"html",
14+
"text-summary"
15+
],
16+
"temp-directory": "./coverage/.nyc_output"
17+
}

.travis.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Build Status](https://img.shields.io/travis/ethereum/solc-js.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereum/solc-js)
21
[![CircleCI](https://img.shields.io/circleci/project/github/ethereum/solc-js/master.svg?style=flat-square)](https://circleci.com/gh/ethereum/solc-js/tree/master)
32
[![Coverage Status](https://img.shields.io/coveralls/ethereum/solc-js.svg?style=flat-square)](https://coveralls.io/r/ethereum/solc-js)
43

@@ -26,12 +25,24 @@ To see all the supported features, execute:
2625
solcjs --help
2726
```
2827

28+
To compile a contract that imports other contracts via relative paths:
29+
```bash
30+
solcjs --bin --include-path node_modules/ --base-path . MainContract.sol
31+
```
32+
Use the ``--base-path`` and ``--include-path`` options to describe the layout of your project.
33+
``--base-path`` represents the root of your own source tree while ``--include-path`` allows you to
34+
specify extra locations containing external code (e.g. libraries installed with a package manager).
35+
36+
Note: ensure that all the files you specify on the command line are located inside the base path or
37+
one of the include paths.
38+
The compiler refers to files from outside of these directories using absolute paths.
39+
Having absolute paths in contract metadata will result in your bytecode being reproducible only
40+
when it's placed in these exact absolute locations.
41+
2942
Note: this commandline interface is not compatible with `solc` provided by the Solidity compiler package and thus cannot be
3043
used in combination with an Ethereum client via the `eth.compile.solidity()` RPC method. Please refer to the
3144
[Solidity compiler documentation](https://solidity.readthedocs.io/) for instructions to install `solc`.
3245
Furthermore, the commandline interface to solc-js provides fewer features than the binary release.
33-
One of the missing features is automatic loading of files from the filesystem if they are not explicitly
34-
mentioned on the command line.
3546

3647
### Usage in Projects
3748

@@ -44,13 +55,14 @@ There are two ways to use `solc`:
4455

4556
The high-level API consists of a single method, `compile`, which expects the [Compiler Standard Input and Output JSON](https://solidity.readthedocs.io/en/v0.5.0/using-the-compiler.html#compiler-input-and-output-json-description).
4657

47-
It also accepts an optional callback function to resolve unmet dependencies. This callback receives a path and must synchronously return either an error or the content of the dependency as a string.
48-
It cannot be used together with callback-based, asynchronous, filesystem access. A workaround is to collect the names of dependencies, return an error, and keep re-running the compiler until all
49-
of them are resolved.
58+
It also accepts an optional set of callback functions, which include the ``import`` and the ``smtSolver`` callbacks.
59+
Starting 0.6.0 it only accepts an object in place of the callback to supply the callbacks.
5060

51-
Starting 0.5.12 it also accepts an object in place of the callback to supply different kind of callbacks, however only file imports are supported.
52-
53-
_Note_: as an intermittent backwards compatibility feature, between versions 0.5.0 and 0.5.2, `compileStandard` and `compileStandardWrapper` also exists and behave like `compile` does.
61+
The ``import`` callback function is used to resolve unmet dependencies.
62+
This callback receives a path and must synchronously return either an error or the content of the dependency
63+
as a string. It cannot be used together with callback-based, asynchronous,
64+
filesystem access. A workaround is to collect the names of dependencies, return
65+
an error, and keep re-running the compiler until all of them are resolved.
5466

5567
#### Example usage without the import callback
5668

@@ -117,10 +129,7 @@ function findImports(path) {
117129
else return { error: 'File not found' };
118130
}
119131

120-
// Current syntax
121-
var output = JSON.parse(solc.compile(JSON.stringify(input), findImports));
122-
123-
// New syntax (supported from 0.5.12)
132+
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
124133
var output = JSON.parse(
125134
solc.compile(JSON.stringify(input), { import: findImports })
126135
);
@@ -135,6 +144,55 @@ for (var contractName in output.contracts['test.sol']) {
135144
}
136145
```
137146

147+
Since version 0.5.1, the ``smtSolver`` callback function is used to solve SMT queries generated by
148+
Solidity's SMTChecker. If you have an SMT solver installed locally, it can
149+
be used to solve the given queries, where the callback must synchronously
150+
return either an error or the result from the solver. A default
151+
``smtSolver`` callback is included in this package via the module
152+
``smtchecker.js`` which exports the ``smtCallback`` function that takes 1) a
153+
function that takes queries and returns the solving result, and 2) a solver
154+
configuration object. The module ``smtsolver.js`` has a few predefined solver
155+
configurations, and relies on Z3, Eldarica or CVC4 being installed locally. It
156+
exports the list of locally found solvers and a function that invokes a given
157+
solver.
158+
159+
The API of the SMT callback is **experimental** and can change at any time.
160+
The last change was in version 0.8.11.
161+
162+
#### Example usage with smtSolver callback
163+
164+
```javascript
165+
var solc = require('solc');
166+
const smtchecker = require('solc/smtchecker');
167+
const smtsolver = require('solc/smtsolver');
168+
// Note that this example only works via node and not in the browser.
169+
170+
var input = {
171+
language: 'Solidity',
172+
sources: {
173+
'test.sol': {
174+
content: 'contract C { function f(uint x) public { assert(x > 0); } }'
175+
}
176+
},
177+
settings: {
178+
modelChecker: {
179+
engine: "chc",
180+
solvers: [ "smtlib2" ]
181+
}
182+
}
183+
};
184+
185+
var output = JSON.parse(
186+
solc.compile(
187+
JSON.stringify(input),
188+
{ smtSolver: smtchecker.smtCallback(smtsolver.smtSolver, smtsolver.availableSolvers[0]) }
189+
)
190+
);
191+
192+
```
193+
The assertion is clearly false, and an ``assertion failure`` warning
194+
should be returned, together with a counterexample.
195+
138196
#### Low-level API
139197

140198
The low-level API is as follows:
@@ -250,11 +308,11 @@ Add the version of `solc` you want to use into `index.html`:
250308
```html
251309
<script
252310
type="text/javascript"
253-
src="https://solc-bin.ethereum.org/bin/{{ SOLC VERSION }}.js"
311+
src="https://binaries.soliditylang.org/bin/{{ SOLC VERSION }}.js"
254312
></script>
255313
```
256314

257-
(Alternatively use `https://solc-bin.ethereum.org/bin/soljson-latest.js` to get the latests version.)
315+
(Alternatively use `https://binaries.soliditylang.org/bin/soljson-latest.js` to get the latests version.)
258316

259317
This will load `solc` into the global variable `window.Module`. Then use this inside Javascript as:
260318

@@ -275,7 +333,7 @@ Alternatively, to iterate the releases, one can load `list.js` from `solc-bin`:
275333
```html
276334
<script
277335
type="text/javascript"
278-
src="https://solc-bin.ethereum.org/bin/list.js"
336+
src="https://binaries.soliditylang.org/bin/list.js"
279337
></script>
280338
```
281339

abi.js renamed to abi.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var semver = require('semver');
1+
import * as semver from 'semver';
22

33
function update (compilerVersion, abi) {
4-
var hasConstructor = false;
5-
var hasFallback = false;
4+
let hasConstructor = false;
5+
let hasFallback = false;
66

7-
for (var i = 0; i < abi.length; i++) {
8-
var item = abi[i];
7+
for (let i = 0; i < abi.length; i++) {
8+
const item = abi[i];
99

1010
if (item.type === 'constructor') {
1111
hasConstructor = true;
@@ -19,8 +19,8 @@ function update (compilerVersion, abi) {
1919
}
2020

2121
if (item.type !== 'event') {
22-
// add 'payable' to everything
23-
if (semver.lt(compilerVersion, '0.4.0')) {
22+
// add 'payable' to everything, except constant functions
23+
if (!item.constant && semver.lt(compilerVersion, '0.4.0')) {
2424
item.payable = true;
2525
}
2626

@@ -58,6 +58,6 @@ function update (compilerVersion, abi) {
5858
return abi;
5959
}
6060

61-
module.exports = {
62-
update: update
61+
export = {
62+
update
6363
};

0 commit comments

Comments
 (0)