raineorshine / solgraph Goto Github PK
View Code? Open in Web Editor NEWVisualize Solidity control flow for smart contract security analysis. :dollar: ⇆ :dollar:
License: ISC License
Visualize Solidity control flow for smart contract security analysis. :dollar: ⇆ :dollar:
License: ISC License
$ sudo yarn global add solgraph
............
[4/4] Building fresh packages...
[1/5] ⠁ node-sass: node-sass build Binary found at /usr/local/share/.config/yarn/global/node_modules/node-sass/vendor/linux-x64-59/binding.node
[-/5] ⠁ waiting...
[3/5] ⠁ uws
[-/5] ⠁ waiting...
error /usr/local/share/.config/yarn/global/node_modules/solgraph: Command failed.
Exit code: 1
Command: npm run build
Arguments:
Directory: /usr/local/share/.config/yarn/global/node_modules/solgraph
Output:
> [email protected] build /usr/local/share/.config/yarn/global/node_modules/solgraph
> babel -d dist src
sh: 1: babel: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] build: `babel -d dist src`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I tried to remedy this with sudo yarn global add babel
, but when I ran sudo yarn global add solgraph
next, it complained:
[4/4] Building fresh packages...
[1/5] ⠈ node-sass: node-sass build Binary found at /usr/local/share/.config/yarn/global/node_modules/node-sass/vendor/linux-x64-59/binding.node
[-/5] ⠈ waiting...
[3/5] ⠈ uws
[-/5] ⠈ waiting...
error /usr/local/share/.config/yarn/global/node_modules/solgraph: Command failed.
Exit code: 1
Command: npm run build
Arguments:
Directory: /usr/local/share/.config/yarn/global/node_modules/solgraph
Output:
> [email protected] build /usr/local/share/.config/yarn/global/node_modules/solgraph
> babel -d dist src
You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.
npm uninstall babel
npm install --save-dev babel-cli
See http://babeljs.io/docs/usage/cli/ for setup instructions.
I then tried:
sudo yarn global remove babel && \
sudo yarn global add -D babel && \
sudo yarn global add solgraph
But received the initial error again: sh: 1: babel: not found
The same issue occurs with npm
.
The require()
function in solidity is used to check if certain conditions are met and throw if they aren't. It replaces the following pattern:
if(something is not okay){
throw;
}
The current version of solgraph takes require() as a normal function and includes it in the graph. This is wrong, as require() is just a replacement for the above pattern.
The majority of public functions in all solidity contracts which modify state use require() in some way, and as a result solgraph outputs unnecessary complicated graphs.
require()
and assert()
should not be treated as normal functions and should not be present in the solgraph graphs.
Thanks for the great work! Most of my functions are yellow, what does that stand for?
contract Sample
{
uint internal value;
}
results in
Parse error { [SyntaxError: Expected "!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/*", "//", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>", ">>=", ">>>", ">>>=", "?", "^", "^=", "in", "instanceof", "|", "|=", "||", comment, end of line or whitespace but "v" found. Line: 3, Column: 16]
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyContract {
// token
ERC20 public immutable token = new ERC20("test", "test");
}
leads to
$solgraph ./contracts/MyContract.sol
Parse error
{ SyntaxError: Expected ";", "=", comment, end of line, or whitespace but "t" found. Line: 7, Column: 28
at peg$buildStructuredError (/Users/administrator/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/Users/administrator/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/Users/administrator/.config/yarn/global/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/Users/administrator/.config/yarn/global/node_modules/solgraph/dist/index.js:91:21)
at /Users/administrator/.config/yarn/global/node_modules/solgraph/dist/bin.js:29:37
message:
'Expected ";", "=", comment, end of line, or whitespace but "t" found. Line: 7, Column: 28',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '=', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: ';', ignoreCase: false } ],
found: 't',
location:
{ start: { offset: 144, line: 7, column: 28 },
end: { offset: 145, line: 7, column: 29 } },
name: 'SyntaxError' }
$solgraph --version
0.3.3
This is due to a lack of functionality in solidity-parser
. Both constructor
and fallback
are parsed the same, for example:
{ type: 'FunctionDeclaration',
name: null,
params: null,
modifiers:
[ { type: 'ModifierArgument',
name: 'public',
params: [],
start: 62,
end: 69 } ],
returnParams: null,
body: { type: 'BlockStatement', body: [], start: 69, end: 74 },
is_abstract: false,
start: 50,
end: 74 }
Trying to install solgraph, but observe failure.
Linux oberon 4.16.12-300.fc28.x86_64 #1 SMP Fri May 25 21:13:28 UTC 2018
Fedora 28 Workstation Edition
$ npm --version
5.6.0$ sudo npm install --save -g solgraph
....
7518 info lifecycle [email protected]postinstall: [email protected]postinstall: unsafe-perm in lifecycle false
7519 verbose lifecycle [email protected]
7520 verbose lifecycle [email protected]postinstall: PATH: /usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/node-gyp-bin:/usr/postinstall: CWD: /usr/lib/node_modules/solgraph
lib/node_modules/solgraph/node_modules/.bin:/usr/lib/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
7521 verbose lifecycle [email protected]
7522 silly lifecycle [email protected]postinstall: Args: [ '-c', 'npm run build' ]postinstall: Returned: code: 243 signal: null
7523 silly lifecycle [email protected]
7524 info lifecycle [email protected]~postinstall: Failed to exec postinstall script
7525 verbose unlock done using /root/.npm/_locks/staging-a072192f34a17023.lock for /usr/lib/node_modules/.staging
7526 warn optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/solgraph/node_modules/fsevents):
7527 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"
os":"linux","arch":"x64"})
7528 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin
7528 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any
7528 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: linux
7528 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
7529 verbose stack Error: [email protected] postinstall:npm run build
7529 verbose stack Exit status 243
7529 verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/index.js:285:16)
7529 verbose stack at emitTwo (events.js:126:13)
7529 verbose stack at EventEmitter.emit (events.js:214:7)
7529 verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules.bundled/npm-lifecycle/lib/spawn.js:55:14)
7529 verbose stack at emitTwo (events.js:126:13)
7529 verbose stack at ChildProcess.emit (events.js:214:7)
7529 verbose stack at maybeClose (internal/child_process.js:925:16)
7529 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
7530 verbose pkgid [email protected]
7531 verbose cwd /home/shishkin
7532 verbose Linux 4.16.12-300.fc28.x86_64
7533 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "--save" "-g" "solgraph"
7534 verbose node v8.11.2
7535 verbose npm v5.6.0
7536 error code ELIFECYCLE
7537 error errno 243
7538 error [email protected] postinstall:npm run build
7538 error Exit status 243
7539 error Failed at the [email protected] postinstall script.
7539 error This is probably not a problem with npm. There is likely additional logging output above.
7540 verbose exit [ 243, true ]
Parse error on pragma solidity ^0.4.0;
Parse error
{ [SyntaxError: Expected comment, end of line, identifier or whitespace but "0" found. Line: 7, Column: 22]
message: 'Expected comment, end of line, identifier or whitespace but "0" found. Line: 7, Column: 22',
expected:
[ { type: 'other', description: 'comment' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'identifier' },
{ type: 'other', description: 'whitespace' } ],
found: '0',
location:
{ start: { offset: 180, line: 7, column: 22 },
end: { offset: 181, line: 7, column: 23 } },
name: 'SyntaxError' }
$ npm install --save -g solgraph
npm WARN deprecated @babel/[email protected]: 👋 We've deprecated any official yearly presets in 6.x in favor or babel-preset-env. For 7.x it would be @babel/preset-env.
/home/gauran/.nvm/versions/node/v8.10.0/bin/solgraph -> /home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/solgraph.js
[email protected] postinstall /home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph
npm run build
[email protected] build /home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph
babel -d dist src
{ Error: Cannot find module '@babel/preset-es2015' from '/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph'
at Function.module.exports [as sync] (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/resolve/lib/sync.js:43:15)
at resolveStandardizedName (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
at resolvePreset (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/files/plugins.js:58:10)
at loadPreset (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/files/plugins.js:77:20)
at createDescriptor (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/config-descriptors.js:114:9)
at items.map (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/config-descriptors.js:69:50)
at Array.map ()
at createDescriptors (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/config-descriptors.js:69:29)
at createPresetDescriptors (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/config-descriptors.js:61:10)
at presets (/home/gauran/.nvm/versions/node/v8.10.0/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/config-descriptors.js:43:19) code: 'MODULE_NOT_FOUND' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: babel -d dist src
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/gauran/.npm/_logs/2018-08-06T11_09_40_157Z-debug.log
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/solgraph/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: npm run build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/gauran/.npm/_logs/2018-08-06T11_09_40_955Z-debug.log
:~$
lorien@air:/web/token_qwerty$ sudo npm install --save -g solgraph
npm WARN deprecated [email protected]: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/usr/bin/solgraph -> /usr/lib/node_modules/solgraph/solgraph.js
> [email protected] postinstall /usr/lib/node_modules/solgraph
> npm run build
npm ERR! path /root/.npm/_logs
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall scandir
npm ERR! Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm ERR! { Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm ERR! stack: 'Error: EACCES: permission denied, scandir \'/root/.npm/_logs\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'scandir',
npm ERR! path: '/root/.npm/_logs' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
glob error { Error: EACCES: permission denied, scandir '/root/.npm/_logs'
stack: 'Error: EACCES: permission denied, scandir \'/root/.npm/_logs\'',
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs' }
> [email protected] build /usr/lib/node_modules/solgraph
> babel -d dist src
Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/solgraph/dist'
at Object.fs.mkdirSync (fs.js:892:18)
at sync (/usr/lib/node_modules/solgraph/node_modules/mkdirp/index.js:71:13)
at outputFileSync (/usr/lib/node_modules/solgraph/node_modules/output-file-sync/index.js:44:24)
at write (/usr/lib/node_modules/solgraph/node_modules/babel-cli/lib/babel/dir.js:33:5)
at handleFile (/usr/lib/node_modules/solgraph/node_modules/babel-cli/lib/babel/dir.js:43:7)
at /usr/lib/node_modules/solgraph/node_modules/babel-cli/lib/babel/dir.js:61:9
at Array.forEach (<anonymous>)
at handle (/usr/lib/node_modules/solgraph/node_modules/babel-cli/lib/babel/dir.js:59:29)
at Array.forEach (<anonymous>)
at module.exports (/usr/lib/node_modules/solgraph/node_modules/babel-cli/lib/babel/dir.js:69:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `babel -d dist src`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
┌───────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /root/.config │
└───────────────────────────────────────────────────┘
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/solgraph/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 243
npm ERR! [email protected] postinstall: `npm run build`
npm ERR! Exit status 243
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-10-08T02_05_08_724Z-debug.log
npm: 5.3.0
node: 8.6.0
os: debian stretch
Content of /root/.npm/_logs/2017-10-08T02_05_08_724Z-debug.log attached.
2017-10-08T02_05_08_724Z-debug.log
Thank you for this tool!
I'm currently testing some new contracts with them and get a SyntaxError after the calldata token
I think the parser just does not expect a calldata token between the type and the name.
The contract code (line 139):
bytes calldata _sigA, bytes calldata _sigB) external
The error:
Parse error { SyntaxError: Expected ")", ",", comment, end of line, or whitespace but "_" found. Line: 139, Column: 24 at peg$buildStructuredError (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:1376:12) at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:15723:11) at Object.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/index.js:34:23) at _default (/usr/local/lib/node_modules/solgraph/dist/index.js:83:21) at /usr/local/lib/node_modules/solgraph/dist/bin.js:29:34 at <anonymous> message: 'Expected ")", ",", comment, end of line, or whitespace but "_" found. Line: 139, Column: 24', expected: [ { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ',', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ')', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ',', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ')', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ',', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ')', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ',', ignoreCase: false }, { type: 'other', description: 'whitespace' }, { type: 'other', description: 'end of line' }, { type: 'other', description: 'comment' }, { type: 'literal', text: ')', ignoreCase: false } ], found: '_', location: { start: { offset: 5047, line: 139, column: 24 }, end: { offset: 5048, line: 139, column: 25 } }, name: 'SyntaxError' }
My ERC20 implements IERC20
, inherits Ownable
and Pausable
and uses SafeMath
. I can remove the import
statements and paste everything into one contract, but it would be much more convenient if solgraph could do that automatically.
Fails to parse multi-variable assignments where at least one is skipped (not sure what it is called)
e.g
function test() returns (uint, uint, uint);
function test2() {
(var1, ,var3) = test(); //it fails here!
}
Error trace:
Parse error
{ [SyntaxError: Expected "!", "(", "+", "++", "-", "--", "[", "delete", "false", "mapping", "new", "null", "this", "true", "typeof", "void", "{", "~", comment, end of line, identifier, number, regular expression, string or whitespace but "," found. Line: 172, Column: 41]
message: 'Expected "!", "(", "+", "++", "-", "--", "[", "delete", "false", "mapping", "new", "null", "this", "true", "typeof", "void", "{", "~", comment, end of line, identifier, number, regular expression, string or whitespace but "," found. Line: 172, Column: 41',
expected:
[ { type: 'literal', value: '!', description: '"!"' },
{ type: 'literal', value: '(', description: '"("' },
{ type: 'literal', value: '+', description: '"+"' },
{ type: 'literal', value: '++', description: '"++"' },
{ type: 'literal', value: '-', description: '"-"' },
{ type: 'literal', value: '--', description: '"--"' },
{ type: 'literal', value: '[', description: '"["' },
{ type: 'literal', value: 'delete', description: '"delete"' },
{ type: 'literal', value: 'false', description: '"false"' },
{ type: 'literal', value: 'mapping', description: '"mapping"' },
{ type: 'literal', value: 'new', description: '"new"' },
{ type: 'literal', value: 'null', description: '"null"' },
{ type: 'literal', value: 'this', description: '"this"' },
{ type: 'literal', value: 'true', description: '"true"' },
{ type: 'literal', value: 'typeof', description: '"typeof"' },
{ type: 'literal', value: 'void', description: '"void"' },
{ type: 'literal', value: '{', description: '"{"' },
{ type: 'literal', value: '~', description: '"~"' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'identifier' },
{ type: 'other', description: 'number' },
{ type: 'other', description: 'regular expression' },
{ type: 'other', description: 'string' },
{ type: 'other', description: 'whitespace' } ],
found: ',',
location:
{ start: { offset: 6084, line: 172, column: 41 },
end: { offset: 6085, line: 172, column: 42 } },
name: 'SyntaxError' }
Hello I love solgraph. I've gotten it to work.
However, I'm on a windows 10 pc. i have downloaded graphwiz and input the path variable in my system settings. I"m not sure if this changes settings for cmd or powershell(or both) but before and after inputing the PATH variable, Graphwiz still doesn't want to work. Using cmd as administrator i am receiving this error:
C:\Users\apoll_000\Documents\SoftwareDevelopmentFiles\token dot -Tpng MyFirstToken.dot > MyFirstToken.png
Error: MyFirstToken.dot: syntax error in line 1 near ' ■s'
using powershell as admin, i get this error.
PS C:\Users\apoll_000\Documents\SoftwareDevelopmentFiles\token> dot -Tpng MyFirstToken.dot > MyFirstToken_dot.png
dot : The term 'dot' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ CategoryInfo : ObjectNotFound: (dot:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any help be appreciated as this problem has been driving me crazy this weekend! I want to see the graphs i made! :-)
It seems that only one of the contracts is graphed in this case.
solgraph ./src/contracts/StakingContract.sol > diagram.png
C:\Users\milaa\AppData\Roaming\npm\node_modules\solgraph\dist\index.js:106
throw new Error(msg);
Fantastic, I have been looking for s.th. like this for a long time; really happy solgraph
was mentioned in Hudson Jameson's DevCon3 talk last week.
Small issue - I get parser errors for some contracts.
How to replicate:
git clone https://github.com/raiden-network/raiden
cd raiden/raiden/smart_contracts/
find . -type f -name "*.sol" -printf "solgraph %p > %p.dot\n" | bash
find . -type f -name "*.dot" -printf "dot -Tpng %p > %p.png\n" | bash
8 out of the 10 contracts are fine, but for two of them (ChannelManagerContract.sol & Token.sol) I get these parser errors:
Parse error
{ SyntaxError: Expected "contract", "import", "library", "pragma", comment, end of input, end of line, or whitespace but "i" found. Line: 3, Column: 1
at peg$buildStructuredError (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:1272:12)
at Object.peg$parse [as parse] (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:13858:11)
at Object.parse (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/index.js:34:23)
at exports.default (/usr/lib/node_modules/solgraph/dist/index.js:70:21)
at /usr/lib/node_modules/solgraph/dist/bin.js:37:35
message: 'Expected "contract", "import", "library", "pragma", comment, end of input, end of line, or whitespace but "i" found. Line: 3, Column: 1',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'pragma', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'contract', ignoreCase: false },
{ type: 'literal', text: 'library', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'end' } ],
found: 'i',
location:
{ start: { offset: 26, line: 3, column: 1 },
end: { offset: 27, line: 3, column: 2 } },
name: 'SyntaxError' }
Parse error
{ SyntaxError: Expected comment, end of line, identifier, or whitespace but "," found. Line: 104, Column: 28
at peg$buildStructuredError (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:1272:12)
at Object.peg$parse [as parse] (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:13858:11)
at Object.parse (/usr/lib/node_modules/solgraph/node_modules/solidity-parser/index.js:34:23)
at exports.default (/usr/lib/node_modules/solgraph/dist/index.js:70:21)
at /usr/lib/node_modules/solgraph/dist/bin.js:37:35
message: 'Expected comment, end of line, identifier, or whitespace but "," found. Line: 104, Column: 28',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'identifier' } ],
found: ',',
location:
{ start: { offset: 3407, line: 104, column: 28 },
end: { offset: 3408, line: 104, column: 29 } },
name: 'SyntaxError' }
These are all the images of those contracts which succeed getting parsed: raiden-solidity-solgraph-for-printing.pdf Really great, thanks a lot!
$ npm install -g solgraph
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/Users/mids/.node/lib
└── (empty)
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/Cellar/node/5.8.0/bin/node" "/Users/mids/.node/bin/npm" "install" "-g" "solgraph"
npm ERR! node v5.8.0
npm ERR! npm v3.4.0
npm ERR! path /Users/mids/.node/lib/node_modules/solgraph/dist/solgraph.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/Users/mids/.node/lib/node_modules/solgraph/dist/solgraph.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /Users/mids/npm-debug.log
npm ERR! code 1
It seems like new keyword "emit"added for event does not seem to be handled so require to accommodate this at code level along with all the new keywords added recently...e.g. assert, require & revert
I'm filing an issue, that issue: why didn't I see this earlier. Awesome work. We should talk, I'm working on a linting system, would love your thoughts and help: https://github.com/weifund/solint
Hi, i am having some issues with use solgraph. Can you help us? Its seems to be in the function sendvalue (address payable recipient,)
Thank you
.sol (including line with function with error).
**
*Submitted for verification at BscScan.com on 2021-10-15
*/
pragma solidity 0.8.7;
// SPDX-License-Identifier: UNLICENSED
function sendValue(address payable recipient, uint256 amount) internal {
Error:
Parse error
peg$SyntaxError: Expected "!=", "%", "%=", "&", "&&", "&=", "(", "", "=", "+", "++", "+=", ",", "-", "--", "-=", ".", "/", "/", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", ">", ">=", ">>", ">>=", ">>>", "?", "[", "^", "^=", "memory", "storage", "|", "|=", "||", comment, end of line, identifier, or whitespace but "{" found. Line: 265, Column: 34
at peg$buildStructuredError (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/usr/local/lib/node_modules/solgraph/dist/index.js:91:21)
at /usr/local/lib/node_modules/solgraph/dist/bin.js:29:37 {
expected: [
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'storage', ignoreCase: false },
{ type: 'literal', text: 'memory', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'identifier' },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '=', ignoreCase: false },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'storage', ignoreCase: false },
{ type: 'literal', text: 'memory', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'identifier' },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'literal', text: '(', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '=', ignoreCase: false },
{ type: 'literal', text: '/=', ignoreCase: false },
{ type: 'literal', text: '%=', ignoreCase: false },
{ type: 'literal', text: '+=', ignoreCase: false },
{ type: 'literal', text: '-=', ignoreCase: false },
{ type: 'literal', text: '<<=', ignoreCase: false },
{ type: 'literal', text: '>>=', ignoreCase: false },
{ type: 'literal', text: '&=', ignoreCase: false },
{ type: 'literal', text: '^=', ignoreCase: false },
{ type: 'literal', text: '|=', ignoreCase: false },
{ type: 'literal', text: '.', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '[', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'storage', ignoreCase: false },
{ type: 'literal', text: 'memory', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
... 258 more items
],
found: '{',
location: {
start: { offset: 7775, line: 265, column: 34 },
end: { offset: 7776, line: 265, column: 35 }
}
}
It seems that this enhancement has been implemented through #22.
However, I can't figure out how to run solgraph to graph multiple .sol files and output a png file with all the functions in all the contracts mapped.
Some guidance or documentation in README would be greatly appreciated. Thanks!
I tried to install solgraph through "npm install --save -g solgraph" on ubuntu 16.04. However, I failed with some errors:
root@ubuntu:# npm install --save -g solgraph
/usr/local/bin/solgraph -> /usr/local/lib/node_modules/solgraph/solgraph.js
[email protected] postinstall /usr/local/lib/node_modules/solgraph
npm run build
[email protected] build /usr/local/lib/node_modules/solgraph
babel -d dist src
Error: [BABEL] /usr/local/lib/node_modules/solgraph/src/bin.js: The pipeline operator requires a proposal set. You must pass 'pipelineProposal' option to @babel/preset-stage-1 (While processing: "/usr/local/lib/node_modules/solgraph/node_modules/@babel/preset-stage-1/lib/index.js")
at _default (/usr/local/lib/node_modules/solgraph/node_modules/@babel/preset-stage-1/lib/index.js:116:11)
at /usr/local/lib/node_modules/solgraph/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
at loadDescriptor (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/full.js:157:14)
at cachedFunction (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/caching.js:32:19)
at loadPresetDescriptor (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/full.js:227:63)
at config.presets.map.descriptor (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/full.js:72:19)
at Array.map ()
at recurseDescriptors (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/full.js:70:38)
at loadFullConfig (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/config/full.js:100:6)
at process.nextTick (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/transform-file.js:48:33)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: babel -d dist src
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/solgraph/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: npm run build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-07-06T17_44_46_341Z-debug.log
The code that causes the error:
pragma solidity ^0.6.6 || >=0.7.5 || ^0.8.0;
The error:
peg$SyntaxError: Expected "!=", "0", ";", "<", "<=", "==", ">", ">=", "^", "v", [1-9], comment, end of line, or whitespace but "|" found. Line: 2, Column: 24
at peg$buildStructuredError (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/usr/local/lib/node_modules/solgraph/dist/index.js:91:21)
at /usr/local/lib/node_modules/solgraph/dist/bin.js:29:37 {
expected: [
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '<=', ignoreCase: false },
{ type: 'literal', text: '>=', ignoreCase: false },
{ type: 'literal', text: '<', ignoreCase: false },
{ type: 'literal', text: '>', ignoreCase: false },
{ type: 'literal', text: '==', ignoreCase: false },
{ type: 'literal', text: '!=', ignoreCase: false },
{ type: 'literal', text: '^', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'v', ignoreCase: false },
{ type: 'literal', text: '0', ignoreCase: false },
{
type: 'class',
parts: [Array],
inverted: false,
ignoreCase: false
},
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: ';', ignoreCase: false }
],
found: '|',
location: {
start: { offset: 55, line: 2, column: 24 },
end: { offset: 56, line: 2, column: 25 }
}
}
It's possible that this error is restricted to smart contracts developed using Hardhat, specifically when multiple Solidity versions are required within one contract (such as two different dependencies needing say 0.6.0 and ^0.8.0 which can't be satisfied without ||).
I'm having trouble running solgraph.
Running the following in zsh:
node ~/.yarn/bin/solgraph Resonate.sol > Resonate.dot
Parse error
peg$SyntaxError: Expected ";", "=", comment, end of line, or whitespace but "D" found. Line: 56, Column: 31
at peg$buildStructuredError (/Users/jonassota/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/Users/jonassota/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/Users/jonassota/.config/yarn/global/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/Users/jonassota/.config/yarn/global/node_modules/solgraph/dist/index.js:69:21)
at /Users/jonassota/.config/yarn/global/node_modules/solgraph/dist/bin.js:23:37 {
expected: [
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '=', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: ';', ignoreCase: false }
],
found: 'D',
location: {
start: { offset: 1643, line: 56, column: 31 },
end: { offset: 1644, line: 56, column: 32 }
}
}
2.node ~/.yarn/bin/solgraph Resonate.sol > Resonate.dot strict digraph { Resonate } zsh: parse error near
}'`
In both cases, an empty Resonate.dot
file is created.
I work in windows
is there a way to combine many .sol sourcefiles into one solgraph PNG?
e.g. could these 20 contracts, and their interdependencies, be shown in one large PNG image?
Hey there Raine,
A real issue this time.
I have been able (after some trouble with npm install) to install solgraph.
Also for some reason the link has not been made and I have to start it with
sudo node /usr/local/lib/node_modules/solgraph/dist/solgraph.js mycontract.sol > graph.dot
Anyways, no big deal, I have been able to generate the graph from the example contract and it works fine.
But my real issue is that when I turn to a more complex contract, it returns (silently) a blank .dot file.
Any idea as to why and how to proceed ?
(I'm on gitter solidity we can speak there if you prefer)
Thanks again !!
Hi,
I am referring [https://github.com/raineorshine/solgraph]
sudo npm install -g solgraph --unsafe-perm=true --allow-root is producing am following error:
| |---------------------------------------------------------------------------------------------------------------------------------------|
WARN engine [email protected]: wanted: {"node":">=6"} (current: {"node":"4.2.6","npm":"3.5.2"})
loadDep:solidity-parser-s / |#######################--------------------------------------------------------------------------------------|
loadDep:chokidar -> addNa | |#######################--------------------------------------------------------------------------------------|
loadDep:urix -> afterAdd \ |#######################--------------------------------------------------------------------------------------|
loadDep:semver -> get - |#########################------------------------------------------------------------------------------------|
loadDep:source-map-suppor - |#############################--------------------------------------------------------------------------------|
/usr/local/bin/solgraph -> /usr/local/lib/node_modules/solgraph/solgraph.js
[email protected] postinstall /usr/local/lib/node_modules/solgraph
npm run build
[email protected] build /usr/local/lib/node_modules/solgraph
babel -d dist src
/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/transformation/file/file.js:75
constructor(options, {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/usr/local/lib/node_modules/solgraph/node_modules/@babel/core/lib/index.js:147:36)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
npm ERR! Linux 4.10.0-35-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] build: babel -d dist src
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script 'babel -d dist src'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the solgraph package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel -d dist src
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs solgraph
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls solgraph
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/lib/node_modules/solgraph/npm-debug.log
npm WARN optional Skipping failed optional dependency /solgraph/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm ERR! Linux 4.10.0-35-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "solgraph" "--unsafe-perm=true" "--allow-root"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: npm run build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'npm run build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the solgraph package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs solgraph
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls solgraph
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/sharadsharma/work/solgraph/npm-debug.log
I tried many times, but facing same issue.
Please suggest.
Thanks
This is a suggestion and not a bug report.
It'd be nice to get a success message when the execution is successful.
some discussion here: #6 (comment)
Error parsing this line: pragma solidity =0.6.11;
>> solgraph contracts/Auctions.sol > graphics/Auctions.dot
Parse error
{ peg$SyntaxError: Expected "!=", "0", "<", "<=", "==", ">", ">=", "^", "v", [1-9], comment, end of line, or whitespace but "=" found. Line: 4, Column: 17
at peg$buildStructuredError (/Users/milesminton/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/Users/milesminton/.config/yarn/global/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/Users/milesminton/.config/yarn/global/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/Users/milesminton/.config/yarn/global/node_modules/solgraph/dist/index.js:91:21)
at /Users/milesminton/.config/yarn/global/node_modules/solgraph/dist/bin.js:29:37
message:
'Expected "!=", "0", "<", "<=", "==", ">", ">=", "^", "v", [1-9], comment, end of line, or whitespace but "=" found. Line: 4, Column: 17',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: '<=', ignoreCase: false },
{ type: 'literal', text: '>=', ignoreCase: false },
{ type: 'literal', text: '<', ignoreCase: false },
{ type: 'literal', text: '>', ignoreCase: false },
{ type: 'literal', text: '==', ignoreCase: false },
{ type: 'literal', text: '!=', ignoreCase: false },
{ type: 'literal', text: '^', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'v', ignoreCase: false },
{ type: 'literal', text: '0', ignoreCase: false },
{ type: 'class',
parts: [Array],
inverted: false,
ignoreCase: false } ],
found: '=',
location:
{ start: { offset: 99, line: 4, column: 17 },
end: { offset: 100, line: 4, column: 18 } },
name: 'SyntaxError' }
`
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
`
Parse error
{ SyntaxError: Expected "contract", "import", "interface", "library", "pragma", comment, end of input, end of line, or whitespace but "a" found. Line: 20, Column: 1
at peg$buildStructuredError (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:1376:12)
at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/build/parser.js:15723:11)
at Object.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser-sc/index.js:34:23)
at _default (/usr/local/lib/node_modules/solgraph/dist/index.js:91:21)
at /usr/local/lib/node_modules/solgraph/dist/bin.js:29:37
message:
'Expected "contract", "import", "interface", "library", "pragma", comment, end of input, end of line, or whitespace but "a" found. Line: 20, Column: 1',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: 'pragma', ignoreCase: false },
{ type: 'literal', text: 'pragma', ignoreCase: false },
{ type: 'literal', text: 'pragma', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'import', ignoreCase: false },
{ type: 'literal', text: 'contract', ignoreCase: false },
{ type: 'literal', text: 'interface', ignoreCase: false },
{ type: 'literal', text: 'library', ignoreCase: false },
{ type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'end' } ],
found: 'a',
location:
{ start: { offset: 290, line: 20, column: 1 },
end: { offset: 291, line: 20, column: 2 } },
name: 'SyntaxError' }
Valid whitespaces after (
or before )
in multi-variable assignments cause an exception:
contract test {
function f2() returns (uint256 val1, uint256 val2) {
// does not work
//var ( r1, r2 ) = (23,15);
// does not work
//var (r1, r2 ) = (23,15);
// does not work
//var ( r1, r2) = (23,15);
//works
var (r1, r2) = (23,15);
return (r1, r2);
}
}
The exception is:
Parse error
{ SyntaxError: Expected ",", comment, end of line, or whitespace but ")" found. Line: 10, Column: 15
at peg$buildStructuredError ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:1272:12)
at Object.peg$parse [as parse] ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\build\parser.js:13858:11)
at Object.parse ((...)\npm\node_modules\solgraph\node_modules\solidity-parser\index.js:34:23)
at exports.default ((...)\npm\node_modules\solgraph\dist\index.js:70:21)
at (...)\npm\node_modules\solgraph\dist\bin.js:37:35
message: 'Expected ",", comment, end of line, or whitespace but ")" found. Line: 10, Column: 15',
expected:
[ { type: 'other', description: 'whitespace' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'comment' },
{ type: 'literal', text: ',', ignoreCase: false } ],
found: ')',
location:
{ start: { offset: 192, line: 10, column: 15 },
end: { offset: 193, line: 10, column: 16 } },
name: 'SyntaxError' }
Here is my code:
contract MyContract {
uint balance;
struct User {
address addr;
bytes32 name;
uint id;
}
User owner;
function MyContract(bytes32 _name, uint _id) {
owner = User({addr:msg.sender, name:_name, id:_id});
Mint(1000000);
}
function Mint(uint amount) internal {
balance = amount;
}
function Withdraw() {
msg.sender.send(balance);
}
function GetBalance() constant returns(uint) {
return balance;
}
}
Error output:
found: '{',
location:
{ start: { offset: 202, line: 10, column: 18 },
end: { offset: 203, line: 10, column: 19 } },
name: 'SyntaxError' }
Solgraph will work if i change the contract code line 10 to
owner = User(msg.sender, _name, _id);
Error:
$ solgraph SimpleDataMarket.sol > SimpleDataMarket.dot
Parse error
{ SyntaxError: Expected "!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/*", "//", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>", ">>=", ">>>", ">>>=", "?", "^", "^=", "in", "instanceof", "|", "|=", "||", comment, end of line or whitespace but "k" found. Line: 32, Column: 20
at peg$buildException (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:1081:14)
at Object.peg$parse [as parse] (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser/build/parser.js:15237:13)
at Object.module.exports.parse (/usr/local/lib/node_modules/solgraph/node_modules/solidity-parser/index.js:34:23)
at exports.default (/usr/local/lib/node_modules/solgraph/dist/index.js:70:21)
at /usr/local/lib/node_modules/solgraph/dist/bin.js:37:35
message: 'Expected "!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/*", "//", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>", ">>=", ">>>", ">>>=", "?", "^", "^=", "in", "instanceof", "|", "|=", "||", comment, end of line or whitespace but "k" found. Line: 32, Column: 20',
expected:
[ { type: 'literal', value: '!=', description: '"!="' },
{ type: 'literal', value: '!==', description: '"!=="' },
{ type: 'literal', value: '%', description: '"%"' },
{ type: 'literal', value: '%=', description: '"%="' },
{ type: 'literal', value: '&', description: '"&"' },
{ type: 'literal', value: '&&', description: '"&&"' },
{ type: 'literal', value: '&=', description: '"&="' },
{ type: 'literal', value: '*', description: '"*"' },
{ type: 'literal', value: '*=', description: '"*="' },
{ type: 'literal', value: '+', description: '"+"' },
{ type: 'literal', value: '++', description: '"++"' },
{ type: 'literal', value: '+=', description: '"+="' },
{ type: 'literal', value: ',', description: '","' },
{ type: 'literal', value: '-', description: '"-"' },
{ type: 'literal', value: '--', description: '"--"' },
{ type: 'literal', value: '-=', description: '"-="' },
{ type: 'literal', value: '/', description: '"/"' },
{ type: 'literal', value: '/*', description: '"/*"' },
{ type: 'literal', value: '//', description: '"//"' },
{ type: 'literal', value: '/=', description: '"/="' },
{ type: 'literal', value: ';', description: '";"' },
{ type: 'literal', value: '<', description: '"<"' },
{ type: 'literal', value: '<<', description: '"<<"' },
{ type: 'literal', value: '<<=', description: '"<<="' },
{ type: 'literal', value: '<=', description: '"<="' },
{ type: 'literal', value: '=', description: '"="' },
{ type: 'literal', value: '==', description: '"=="' },
{ type: 'literal', value: '===', description: '"==="' },
{ type: 'literal', value: '>', description: '">"' },
{ type: 'literal', value: '>=', description: '">="' },
{ type: 'literal', value: '>>', description: '">>"' },
{ type: 'literal', value: '>>=', description: '">>="' },
{ type: 'literal', value: '>>>', description: '">>>"' },
{ type: 'literal', value: '>>>=', description: '">>>="' },
{ type: 'literal', value: '?', description: '"?"' },
{ type: 'literal', value: '^', description: '"^"' },
{ type: 'literal', value: '^=', description: '"^="' },
{ type: 'literal', value: 'in', description: '"in"' },
{ type: 'literal',
value: 'instanceof',
description: '"instanceof"' },
{ type: 'literal', value: '|', description: '"|"' },
{ type: 'literal', value: '|=', description: '"|="' },
{ type: 'literal', value: '||', description: '"||"' },
{ type: 'other', description: 'comment' },
{ type: 'other', description: 'end of line' },
{ type: 'other', description: 'whitespace' } ],
found: 'k',
location:
{ start: { offset: 780, line: 32, column: 20 },
end: { offset: 781, line: 32, column: 21 } },
name: 'SyntaxError' }
Source:
contract SimpleDataMarket {
struct Purchase {
uint startTime;
}
// This struct keeps all data for a Record.
struct Record {
// Keeps the address of this record creator.
address owner;
// Keeps the time when this record was created.
uint time;
// Keeps the index of the keys array for fast lookup
uint keysIndex;
string desc;
bool active;
string help;
address payTo;
uint secondsLength;
uint256 price;
mapping (address => Purchase) purchases;
uint vault;
}
// This mapping keeps the records of this Registry.
mapping(string => Record) records;
// Keeps the total numbers of records in this Registry.
uint public numRecords;
// Keeps a list of all keys to interate the records.
string[] private keys;
event NewSensor(string key, string desc, string help, uint secondsLength, uint price);
// This is the function that actually insert a record.
function register(string key, string desc, bool active, string help, address payTo, uint secondsLength, uint price) {
if (records[key].time == 0) {
records[key].time = now;
records[key].owner = msg.sender;
records[key].keysIndex = keys.length;
keys.length++;
keys[keys.length - 1] = key;
records[key].desc = desc;
records[key].active = active;
records[key].help = help;
records[key].payTo = payTo;
records[key].secondsLength = secondsLength;
records[key].price = price;
records[key].purchases[msg.sender] = Purchase(99999999999 ether); // unlimited access to owner
numRecords++;
NewSensor(key, desc, help, secondsLength, price);
}
}
// Updates the values of the given record.
function update(string key, string desc, bool active, string help, address payTo, uint secondsLength, uint256 price) {
// Only the owner can update his record.
if (records[key].owner == msg.sender) {
records[key].desc = desc;
records[key].active = active;
records[key].help = help;
records[key].payTo = payTo;
records[key].secondsLength = secondsLength;
records[key].price = price;
}
}
// Unregister a given record
function toggleActive(string key) {
Record r = records[key];
if (r.owner == msg.sender)
r.active = !r.active;
}
// Tells whether a given key is registered.
function isRegistered(string key) constant returns(bool) {
if (records[key].time == 0) {
return false;
}
return true;
}
function getRecordAtIndex(uint rindex) constant returns(string key, address owner, uint time, string desc, bool active, string help, address payTo, uint secondsLength, uint256 price) {
Record record = records[keys[rindex]];
key = keys[rindex];
owner = record.owner;
time = record.time;
desc = record.desc;
active = record.active;
help = record.help;
payTo = record.payTo;
secondsLength = record.secondsLength;
price = record.price;
}
function getRecord(string key) constant returns(address owner, uint time, string desc, bool active, string help, address payTo, uint secondsLength, uint256 price) {
Record record = records[key];
owner = record.owner;
time = record.time;
desc = record.desc;
active = record.active;
help = record.help;
payTo = record.payTo;
secondsLength = record.secondsLength;
price = record.price;
}
// Returns the owner of the given record. The owner could also be get
// by using the function getRecord but in that case all record attributes
// are returned.
function getOwner(string key) constant returns(address) {
return records[key].owner;
}
// Returns the registration time of the given record. The time could also
// be get by using the function getRecord but in that case all record attributes
// are returned.
function getTime(string key) constant returns(uint) {
return records[key].time;
}
// Returns the total number of records in this registry.
function getTotalRecords() constant returns(uint) {
return numRecords;
}
// Deposits money into the contract to buy access to sensor data
// New data can only be added when previous purchase is ended
// TODO Avoids overwriting already purchased sensordata.
// TODO only take the needed amount
function buyAccess(string key) {
Record r = records[key];
if (r.price == msg.value) {
r.purchases[msg.sender] = Purchase(now);
r.vault += msg.value;
} else {
if (!msg.sender.call.value(msg.value)())
throw;
}
}
function checkAccess(string key, address _buyer) constant returns (bool access) {
Record r = records[key];
uint start = r.purchases[_buyer].startTime;
if (start == 0) return false; // No purchase exists
if ((start + r.secondsLength) > now)
return true;
return false;
}
function withdraw(string key) returns (uint balance) {
if (msg.sender == records[key].owner) {
uint earnings = records[key].vault;
records[key].vault = 0; // In this order to be sure ledger is set to 0 BEFORE transfering the money. DAO bug
if (!msg.sender.call.value(earnings)())
throw;
}
}
function balance(string key) constant returns (uint balance) {
if (msg.sender == records[key].owner) {
return records[key].vault;
}
}
function() {}
}
Hey!
Kudos again, a very useful tool.
I want to get an overview of this set of contracts.
From 10 *.sol files I could make nonempty PNG images, but ~ 7 are throwing Parse errors.
what to do?
get all 20 contracts:
git clone https://github.com/energywebfoundation/bond.git
cd bond
git checkout ricmm-work-multicon-resin
git pull
cd bond/certificate_of_origin/contracts/
create a little helper, called solgrapher.sh
:
solgraph $1 > $1.dot && dot -Tpng $1.dot > $1.dot.png && echo success: $1.dot.png
rm $1.dot
make executable
chmod 755 solgrapher.sh
call on all .sol
files:
find . -name "*.sol" -exec ./solgrapher.sh {} \;
If contract Parent defines an event, and contract Child triggers the event, the event is not listed in the graph for contract Child.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.