Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ethereum/solc-js into link-byteco…
Browse files Browse the repository at this point in the history
…de-using-references
  • Loading branch information
r0qs committed Oct 4, 2022
2 parents 8cc1dee + a3b7b9e commit c1dec49
Show file tree
Hide file tree
Showing 60 changed files with 3,728 additions and 1,792 deletions.
380 changes: 356 additions & 24 deletions .circleci/config.yml

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: [
'standard'
],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint'
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
rules: {
semi: ['error', 'always']
},
ignorePatterns: ['dist', 'soljson.js']
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ bin
out
*.bin
*.abi

dist/**

.nyc_output
17 changes: 17 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"exclude": [
"coverage",
"dist/soljson.js",
"**/test/**"
],
"extensions": [
".js"
],
"report-dir": "./coverage",
"reporter": [
"lcov",
"html",
"text-summary"
],
"temp-directory": "./coverage/.nyc_output"
}
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

90 changes: 74 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Build Status](https://img.shields.io/travis/ethereum/solc-js.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereum/solc-js)
[![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)
[![Coverage Status](https://img.shields.io/coveralls/ethereum/solc-js.svg?style=flat-square)](https://coveralls.io/r/ethereum/solc-js)

Expand Down Expand Up @@ -26,12 +25,24 @@ To see all the supported features, execute:
solcjs --help
```

To compile a contract that imports other contracts via relative paths:
```bash
solcjs --bin --include-path node_modules/ --base-path . MainContract.sol
```
Use the ``--base-path`` and ``--include-path`` options to describe the layout of your project.
``--base-path`` represents the root of your own source tree while ``--include-path`` allows you to
specify extra locations containing external code (e.g. libraries installed with a package manager).

Note: ensure that all the files you specify on the command line are located inside the base path or
one of the include paths.
The compiler refers to files from outside of these directories using absolute paths.
Having absolute paths in contract metadata will result in your bytecode being reproducible only
when it's placed in these exact absolute locations.

Note: this commandline interface is not compatible with `solc` provided by the Solidity compiler package and thus cannot be
used in combination with an Ethereum client via the `eth.compile.solidity()` RPC method. Please refer to the
[Solidity compiler documentation](https://solidity.readthedocs.io/) for instructions to install `solc`.
Furthermore, the commandline interface to solc-js provides fewer features than the binary release.
One of the missing features is automatic loading of files from the filesystem if they are not explicitly
mentioned on the command line.

### Usage in Projects

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

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).

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.
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
of them are resolved.
It also accepts an optional set of callback functions, which include the ``import`` and the ``smtSolver`` callbacks.
Starting 0.6.0 it only accepts an object in place of the callback to supply the callbacks.

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.

_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.
The ``import`` callback function is used 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. 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 of them are resolved.

#### Example usage without the import callback

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

// Current syntax
var output = JSON.parse(solc.compile(JSON.stringify(input), findImports));

// New syntax (supported from 0.5.12)
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
var output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
Expand All @@ -135,6 +144,55 @@ for (var contractName in output.contracts['test.sol']) {
}
```

Since version 0.5.1, the ``smtSolver`` callback function is used to solve SMT queries generated by
Solidity's SMTChecker. If you have an SMT solver installed locally, it can
be used to solve the given queries, where the callback must synchronously
return either an error or the result from the solver. A default
``smtSolver`` callback is included in this package via the module
``smtchecker.js`` which exports the ``smtCallback`` function that takes 1) a
function that takes queries and returns the solving result, and 2) a solver
configuration object. The module ``smtsolver.js`` has a few predefined solver
configurations, and relies on Z3, Eldarica or CVC4 being installed locally. It
exports the list of locally found solvers and a function that invokes a given
solver.

The API of the SMT callback is **experimental** and can change at any time.
The last change was in version 0.8.11.

#### Example usage with smtSolver callback

```javascript
var solc = require('solc');
const smtchecker = require('solc/smtchecker');
const smtsolver = require('solc/smtsolver');
// Note that this example only works via node and not in the browser.

var input = {
language: 'Solidity',
sources: {
'test.sol': {
content: 'contract C { function f(uint x) public { assert(x > 0); } }'
}
},
settings: {
modelChecker: {
engine: "chc",
solvers: [ "smtlib2" ]
}
}
};

var output = JSON.parse(
solc.compile(
JSON.stringify(input),
{ smtSolver: smtchecker.smtCallback(smtsolver.smtSolver, smtsolver.availableSolvers[0]) }
)
);

```
The assertion is clearly false, and an ``assertion failure`` warning
should be returned, together with a counterexample.

#### Low-level API

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

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

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

Expand All @@ -275,7 +333,7 @@ Alternatively, to iterate the releases, one can load `list.js` from `solc-bin`:
```html
<script
type="text/javascript"
src="https://solc-bin.ethereum.org/bin/list.js"
src="https://binaries.soliditylang.org/bin/list.js"
></script>
```

Expand Down
18 changes: 9 additions & 9 deletions abi.js → abi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var semver = require('semver');
import * as semver from 'semver';

function update (compilerVersion, abi) {
var hasConstructor = false;
var hasFallback = false;
let hasConstructor = false;
let hasFallback = false;

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

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

if (item.type !== 'event') {
// add 'payable' to everything
if (semver.lt(compilerVersion, '0.4.0')) {
// add 'payable' to everything, except constant functions
if (!item.constant && semver.lt(compilerVersion, '0.4.0')) {
item.payable = true;
}

Expand Down Expand Up @@ -58,6 +58,6 @@ function update (compilerVersion, abi) {
return abi;
}

module.exports = {
update: update
export = {
update
};
Loading

0 comments on commit c1dec49

Please sign in to comment.