Skip to content

Commit 5c1280c

Browse files
authored
Merge pull request #432 from ethereum/smt_readme
Add smtCallback to README
2 parents 45d0f31 + 3e16176 commit 5c1280c

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ There are two ways to use `solc`:
4444

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

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

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.
50+
The ``import`` callback function is used to resolve unmet dependencies.
51+
This callback receives a path and must synchronously return either an error or the content of the dependency
52+
as a string. It cannot be used together with callback-based, asynchronous,
53+
filesystem access. A workaround is to collect the names of dependencies, return
54+
an error, and keep re-running the compiler until all of them are resolved.
5255

5356
#### Example usage without the import callback
5457

@@ -115,10 +118,7 @@ function findImports(path) {
115118
else return { error: 'File not found' };
116119
}
117120

118-
// Current syntax
119-
var output = JSON.parse(solc.compile(JSON.stringify(input), findImports));
120-
121-
// New syntax (supported from 0.5.12)
121+
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
122122
var output = JSON.parse(
123123
solc.compile(JSON.stringify(input), { import: findImports })
124124
);
@@ -133,6 +133,37 @@ for (var contractName in output.contracts['test.sol']) {
133133
}
134134
```
135135

136+
The ``smtSolver`` callback function is used to solve SMT queries generated by
137+
Solidity's SMTChecker. If you have an SMT solver installed locally, it can
138+
be used to solve the given queries, where the callback must synchronously
139+
return either an error or the result from the solver. A default
140+
``smtSolver`` callback is distributed by ``solc-js``, which relies on either
141+
Z3 or CVC4 being installed locally.
142+
143+
#### Example usage with smtSolver callback
144+
145+
```javascript
146+
var solc = require('solc');
147+
var smt = require('smtsolver');
148+
// Note that this example only works via node and not in the browser.
149+
150+
var input = {
151+
language: 'Solidity',
152+
sources: {
153+
'test.sol': {
154+
content: 'pragma experimental SMTChecker; contract C { function f(uint x) public { assert(x > 0); } }'
155+
}
156+
}
157+
};
158+
159+
var output = JSON.parse(
160+
solc.compile(JSON.stringify(input), { smtSolver: smt.smtSolver })
161+
);
162+
163+
```
164+
The assertion is clearly false, and an ``assertion failure`` warning
165+
should be returned.
166+
136167
#### Low-level API
137168

138169
The low-level API is as follows:

0 commit comments

Comments
 (0)