diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-17 22:59:00 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-17 22:59:00 +0800 |
commit | 293e93729176b06f7e3cf78c798f48ddf360e311 (patch) | |
tree | e47909d281ae7da6b7c9e6af76757373ad485705 /packages/sol-tracing-utils | |
parent | fe2f97dabd1511918051161c882c57bcc1d41ac2 (diff) | |
parent | 0b23aaca2619b888dd4e15774d5c543f79f4588d (diff) | |
download | dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar.gz dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar.bz2 dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar.lz dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar.xz dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.tar.zst dexon-0x-contracts-293e93729176b06f7e3cf78c798f48ddf360e311.zip |
Merge branch 'development' into fix/dev-tools-pages/finalTouches
* development: (22 commits)
Fix linter
Update packages/sol-tracing-utils/src/trace_collection_subprovider.ts
Update packages/sol-tracing-utils/CHANGELOG.json
Update packages/sol-tracing-utils/CHANGELOG.json
Add PR numbers
Fix/simplify handling of revert trace snippets
Fix a bug when TraceCollectionSubprovider was hanging on the fake Geth snapshot transaction
Fix a bug when a custom Geth tracer didn't return stack entries for DELEGATECALL
Revert devnet mining period from 1 to 0
update team info, add brent
Publish
Updated CHANGELOGS
Add commented-out pre-publish checks
Add additional check to make sure user was added to our DockerHub org
Update test for required amountAvailableToFill
Add actual error message thrown
Flag order-watcher as having a Docker image to publish
Add publish to DockerHub step to publish flow
Flesh out postpublish configs in packageJSON type
Add pre-publish check to ensure publisher is logged in to docker cmdline
...
Diffstat (limited to 'packages/sol-tracing-utils')
-rw-r--r-- | packages/sol-tracing-utils/CHANGELOG.json | 20 | ||||
-rw-r--r-- | packages/sol-tracing-utils/CHANGELOG.md | 8 | ||||
-rw-r--r-- | packages/sol-tracing-utils/package.json | 18 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/get_source_range_snippet.ts | 175 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/trace_collection_subprovider.ts | 2 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/trace_info_subprovider.ts | 2 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/types.ts | 4 | ||||
-rw-r--r-- | packages/sol-tracing-utils/src/utils.ts | 16 |
8 files changed, 53 insertions, 192 deletions
diff --git a/packages/sol-tracing-utils/CHANGELOG.json b/packages/sol-tracing-utils/CHANGELOG.json index 5992016b1..4a855d031 100644 --- a/packages/sol-tracing-utils/CHANGELOG.json +++ b/packages/sol-tracing-utils/CHANGELOG.json @@ -1,5 +1,22 @@ [ { + "version": "4.0.1", + "changes": [ + { + "note": "Fix a bug where a custom `Geth` tracer didn't return stack entries for `DELEGATECALL`", + "pr": 1521 + }, + { + "note": "Fix a bug where `TraceCollectionSubprovider` was hanging on the fake `Geth` snapshot transaction", + "pr": 1521 + }, + { + "note": "Fix/simplify handling of revert trace snippets", + "pr": 1521 + } + ] + }, + { "version": "4.0.0", "changes": [ { @@ -22,7 +39,8 @@ "note": "Add support for assembly statements", "pr": 1498 } - ] + ], + "timestamp": 1547561734 }, { "version": "3.0.0", diff --git a/packages/sol-tracing-utils/CHANGELOG.md b/packages/sol-tracing-utils/CHANGELOG.md index da998f905..00d36844c 100644 --- a/packages/sol-tracing-utils/CHANGELOG.md +++ b/packages/sol-tracing-utils/CHANGELOG.md @@ -5,6 +5,14 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v4.0.0 - _January 15, 2019_ + + * Fix a bug with incorrect parsing of `sourceMaps` due to sources being in an array instead of a map (#1498) + * Change the types of `ContractData.sources` and `ContractData.sourceCodes` to be objects instead of arrays (#1498) + * Use custom JS tracer to speed up tracing on clients that support it (e.g., Geth) (#1498) + * Log errors encountered in `TraceCollectionSubprovider` (#1498) + * Add support for assembly statements (#1498) + ## v3.0.0 - _January 11, 2019_ * Move out specific tools and leave just the shared parts of the codebase (#1492) diff --git a/packages/sol-tracing-utils/package.json b/packages/sol-tracing-utils/package.json index 5021342fa..e3e52f42c 100644 --- a/packages/sol-tracing-utils/package.json +++ b/packages/sol-tracing-utils/package.json @@ -1,6 +1,6 @@ { "name": "@0x/sol-tracing-utils", - "version": "3.0.0", + "version": "4.0.0", "engines": { "node": ">=6.12" }, @@ -42,14 +42,14 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-tracing-utils/README.md", "dependencies": { - "@0x/dev-utils": "^1.0.23", - "@0x/sol-compiler": "^2.0.1", - "@0x/subproviders": "^2.1.10", - "@0x/typescript-typings": "^3.0.7", - "@0x/utils": "^3.0.0", - "@0x/web3-wrapper": "^3.2.3", + "@0x/dev-utils": "^1.0.24", + "@0x/sol-compiler": "^2.0.2", + "@0x/subproviders": "^2.1.11", + "@0x/typescript-typings": "^3.0.8", + "@0x/utils": "^3.0.1", + "@0x/web3-wrapper": "^3.2.4", "@types/solidity-parser-antlr": "^0.2.0", - "ethereum-types": "^1.1.5", + "ethereum-types": "^1.1.6", "ethereumjs-util": "^5.1.1", "glob": "^7.1.2", "istanbul": "^0.4.5", @@ -61,7 +61,7 @@ "solidity-parser-antlr": "^0.2.12" }, "devDependencies": { - "@0x/tslint-config": "^2.0.1", + "@0x/tslint-config": "^2.0.2", "@types/istanbul": "^0.4.30", "@types/loglevel": "^1.5.3", "@types/mkdirp": "^0.5.1", diff --git a/packages/sol-tracing-utils/src/get_source_range_snippet.ts b/packages/sol-tracing-utils/src/get_source_range_snippet.ts index 7aef00fee..c1f6e3a4e 100644 --- a/packages/sol-tracing-utils/src/get_source_range_snippet.ts +++ b/packages/sol-tracing-utils/src/get_source_range_snippet.ts @@ -1,185 +1,16 @@ -import * as ethUtil from 'ethereumjs-util'; -import * as _ from 'lodash'; -import * as Parser from 'solidity-parser-antlr'; - -import { SingleFileSourceRange, SourceRange, SourceSnippet } from './types'; +import { SourceRange, SourceSnippet } from './types'; import { utils } from './utils'; -interface ASTInfo { - type: string; - node: Parser.ASTNode; - name: string | null; - range?: SingleFileSourceRange; -} - -// Parsing source code for each transaction/code is slow and therefore we cache it -const hashToParsedSource: { [sourceHash: string]: Parser.ASTNode } = {}; - /** * Gets the source range snippet by source range to be used by revert trace. * @param sourceRange source range * @param sourceCode source code */ -export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: string): SourceSnippet | null { - const sourceHash = ethUtil.sha3(sourceCode).toString('hex'); - if (_.isUndefined(hashToParsedSource[sourceHash])) { - hashToParsedSource[sourceHash] = Parser.parse(sourceCode, { loc: true }); - } - const astNode = hashToParsedSource[sourceHash]; - const visitor = new ASTInfoVisitor(); - Parser.visit(astNode, visitor); - const astInfo = visitor.getASTInfoForRange(sourceRange); - if (astInfo === null) { - return null; - } +export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: string): SourceSnippet { const sourceCodeInRange = utils.getRange(sourceCode, sourceRange.location); return { - ...astInfo, - range: astInfo.range as SingleFileSourceRange, + range: sourceRange.location, source: sourceCodeInRange, fileName: sourceRange.fileName, }; } - -// A visitor which collects ASTInfo for most nodes in the AST. -class ASTInfoVisitor { - private readonly _astInfos: ASTInfo[] = []; - public getASTInfoForRange(sourceRange: SourceRange): ASTInfo | null { - // HACK(albrow): Sometimes the source range doesn't exactly match that - // of astInfo. To work around that we try with a +/-1 offset on - // end.column. If nothing matches even with the offset, we return null. - const offset = { - start: { - line: 0, - column: 0, - }, - end: { - line: 0, - column: 0, - }, - }; - let astInfo = this._getASTInfoForRange(sourceRange, offset); - if (astInfo !== null) { - return astInfo; - } - offset.end.column += 1; - astInfo = this._getASTInfoForRange(sourceRange, offset); - if (astInfo !== null) { - return astInfo; - } - offset.end.column -= 2; - astInfo = this._getASTInfoForRange(sourceRange, offset); - if (astInfo !== null) { - return astInfo; - } - return null; - } - public ContractDefinition(ast: Parser.ContractDefinition): void { - this._visitContractDefinition(ast); - } - public IfStatement(ast: Parser.IfStatement): void { - this._visitStatement(ast); - } - public FunctionDefinition(ast: Parser.FunctionDefinition): void { - this._visitFunctionLikeDefinition(ast); - } - public ModifierDefinition(ast: Parser.ModifierDefinition): void { - this._visitFunctionLikeDefinition(ast); - } - public ForStatement(ast: Parser.ForStatement): void { - this._visitStatement(ast); - } - public ReturnStatement(ast: Parser.ReturnStatement): void { - this._visitStatement(ast); - } - public BreakStatement(ast: Parser.BreakStatement): void { - this._visitStatement(ast); - } - public ContinueStatement(ast: Parser.ContinueStatement): void { - this._visitStatement(ast); - } - public EmitStatement(ast: any /* TODO: Parser.EmitStatement */): void { - this._visitStatement(ast); - } - public VariableDeclarationStatement(ast: Parser.VariableDeclarationStatement): void { - this._visitStatement(ast); - } - public Statement(ast: Parser.Statement): void { - this._visitStatement(ast); - } - public WhileStatement(ast: Parser.WhileStatement): void { - this._visitStatement(ast); - } - public SimpleStatement(ast: Parser.SimpleStatement): void { - this._visitStatement(ast); - } - public ThrowStatement(ast: Parser.ThrowStatement): void { - this._visitStatement(ast); - } - public DoWhileStatement(ast: Parser.DoWhileStatement): void { - this._visitStatement(ast); - } - public ExpressionStatement(ast: Parser.ExpressionStatement): void { - this._visitStatement(ast.expression); - } - public InlineAssemblyStatement(ast: Parser.InlineAssemblyStatement): void { - this._visitStatement(ast); - } - public ModifierInvocation(ast: Parser.ModifierInvocation): void { - const BUILTIN_MODIFIERS = ['public', 'view', 'payable', 'external', 'internal', 'pure', 'constant']; - if (!_.includes(BUILTIN_MODIFIERS, ast.name)) { - this._visitStatement(ast); - } - } - private _visitStatement(ast: Parser.ASTNode): void { - this._astInfos.push({ - type: ast.type, - node: ast, - name: null, - range: ast.loc, - }); - } - private _visitFunctionLikeDefinition(ast: Parser.ModifierDefinition | Parser.FunctionDefinition): void { - this._astInfos.push({ - type: ast.type, - node: ast, - name: ast.name, - range: ast.loc, - }); - } - private _visitContractDefinition(ast: Parser.ContractDefinition): void { - this._astInfos.push({ - type: ast.type, - node: ast, - name: ast.name, - range: ast.loc, - }); - } - private _getASTInfoForRange(sourceRange: SourceRange, offset: SingleFileSourceRange): ASTInfo | null { - const offsetSourceRange = { - ...sourceRange, - location: { - start: { - line: sourceRange.location.start.line + offset.start.line, - column: sourceRange.location.start.column + offset.start.column, - }, - end: { - line: sourceRange.location.end.line + offset.end.line, - column: sourceRange.location.end.column + offset.end.column, - }, - }, - }; - for (const astInfo of this._astInfos) { - const astInfoRange = astInfo.range as SingleFileSourceRange; - if ( - astInfoRange.start.column === offsetSourceRange.location.start.column && - astInfoRange.start.line === offsetSourceRange.location.start.line && - astInfoRange.end.column === offsetSourceRange.location.end.column && - astInfoRange.end.line === offsetSourceRange.location.end.line - ) { - return astInfo; - } - } - return null; - } -} diff --git a/packages/sol-tracing-utils/src/trace_collection_subprovider.ts b/packages/sol-tracing-utils/src/trace_collection_subprovider.ts index 323e1523c..5118921fa 100644 --- a/packages/sol-tracing-utils/src/trace_collection_subprovider.ts +++ b/packages/sol-tracing-utils/src/trace_collection_subprovider.ts @@ -144,7 +144,7 @@ export abstract class TraceCollectionSubprovider extends Subprovider { txHash: string | undefined, cb: Callback, ): Promise<void> { - if (!txData.isFakeTransaction) { + if (!(txData.isFakeTransaction || txData.from === txData.to)) { // This transaction is a usual transaction. Not a call executed as one. // And we don't want it to be executed within a snapshotting period await this._lock.acquire(); diff --git a/packages/sol-tracing-utils/src/trace_info_subprovider.ts b/packages/sol-tracing-utils/src/trace_info_subprovider.ts index b75fc7bf7..de42e1862 100644 --- a/packages/sol-tracing-utils/src/trace_info_subprovider.ts +++ b/packages/sol-tracing-utils/src/trace_info_subprovider.ts @@ -31,7 +31,7 @@ export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider { const depth = 0 | log.getDepth(); const gasCost = 0 | log.getCost(); const gas = 0 | log.getGas(); - const isCall = opn == 0xf1 || opn == 0xf2 || opn == 0xf4 || opn == 0xf5; + const isCall = opn == 0xf1 || opn == 0xf2 || opn == 0xf4 || opn == 0xf5 || opn == 0xfa; const stack = isCall ? ['0x'+log.stack.peek(1).toString(16), null] : null; this.data.push({ pc, gasCost, depth, op, stack, gas }); }, diff --git a/packages/sol-tracing-utils/src/types.ts b/packages/sol-tracing-utils/src/types.ts index 27568ae03..97b5e6b37 100644 --- a/packages/sol-tracing-utils/src/types.ts +++ b/packages/sol-tracing-utils/src/types.ts @@ -1,5 +1,4 @@ import { StructLog } from 'ethereum-types'; -import * as Parser from 'solidity-parser-antlr'; export interface LineColumn { line: number; @@ -126,8 +125,5 @@ export type EvmCallStack = EvmCallStackEntry[]; export interface SourceSnippet { source: string; fileName: string; - type: string; - node: Parser.ASTNode; - name: string | null; range: SingleFileSourceRange; } diff --git a/packages/sol-tracing-utils/src/utils.ts b/packages/sol-tracing-utils/src/utils.ts index 644321f32..89c158ee7 100644 --- a/packages/sol-tracing-utils/src/utils.ts +++ b/packages/sol-tracing-utils/src/utils.ts @@ -8,6 +8,7 @@ import { ContractData, LineColumn, SingleFileSourceRange } from './types'; // This is the minimum length of valid contract bytecode. The Solidity compiler // metadata is 86 bytes. If you add the '0x' prefix, we get 88. const MIN_CONTRACT_BYTECODE_LENGTH = 88; +const STATICCALL_GAS_COST = 40; export const utils = { compareLineColumn(lhs: LineColumn, rhs: LineColumn): number { @@ -76,10 +77,17 @@ export const utils = { normalizeStructLogs(structLogs: StructLog[]): StructLog[] { if (structLogs[0].depth === 1) { // Geth uses 1-indexed depth counter whilst ganache starts from 0 - const newStructLogs = _.map(structLogs, structLog => ({ - ...structLog, - depth: structLog.depth - 1, - })); + const newStructLogs = _.map(structLogs, structLog => { + const newStructLog = { + ...structLog, + depth: structLog.depth - 1, + }; + if (newStructLog.op === 'STATICCALL') { + // HACK(leo): Geth traces sometimes returns those gas costs incorrectly as very big numbers so we manually fix them. + newStructLog.gasCost = STATICCALL_GAS_COST; + } + return newStructLog; + }); return newStructLogs; } return structLogs; |