Skip to content

Commit

Permalink
Merge pull request #126 from ConsenSys/support-solidity-0815
Browse files Browse the repository at this point in the history
Support for Solidity 0.8.15
  • Loading branch information
cd1m0 authored Jul 7, 2022
2 parents 3ce30d1 + 944b78a commit 9d64433
Show file tree
Hide file tree
Showing 22 changed files with 14,530 additions and 12,658 deletions.
1,251 changes: 594 additions & 657 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@
},
"dependencies": {
"axios": "^0.27.2",
"commander": "^9.2.0",
"commander": "^9.3.0",
"findup-sync": "^5.0.0",
"fs-extra": "^10.1.0",
"jsel": "^1.1.6",
"semver": "^7.3.7",
"solc": "0.8.14-fixed",
"solc": "^0.8.15",
"src-location": "^1.1.0",
"web3-eth-abi": "^1.7.3"
"web3-eth-abi": "^1.7.4"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^9.1.1",
"@types/node": "^16.11.36",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@types/node": "^16.11.43",
"@types/semver": "^7.3.10",
"@typescript-eslint/eslint-plugin": "^5.30.4",
"@typescript-eslint/parser": "^5.30.4",
"codecov": "^3.8.3",
"eslint": "^8.16.0",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"expect": "^28.1.0",
"eslint-plugin-prettier": "^4.2.1",
"expect": "^28.1.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"peggy": "^1.2.0",
"prettier": "2.6.2",
"ts-node": "^10.8.0",
"prettier": "2.7.1",
"ts-node": "^10.8.2",
"ts-pegjs": "^1.2.2",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"typedoc": "^0.23.5",
"typescript": "^4.7.4"
},
"homepage": "https://consensys.github.io/solc-typed-ast",
"bugs": "https://github.com/ConsenSys/solc-typed-ast/issues",
Expand Down
4 changes: 2 additions & 2 deletions src/ast/implementation/declaration/error_definition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ABIEncoderVersion } from "../../../types/abi";
import { ASTNode } from "../../ast_node";
import { encodeSignature } from "../../utils";
import { encodeFuncSignature } from "../../utils";
import { SourceUnit } from "../meta";
import { ParameterList } from "../meta/parameter_list";
import { StructuredDocumentation } from "../meta/structured_documentation";
Expand Down Expand Up @@ -78,6 +78,6 @@ export class ErrorDefinition extends ASTNode {
* applied to the canonical representation of the error signature.
*/
canonicalSignatureHash(encoderVersion: ABIEncoderVersion): string {
return encodeSignature(this.canonicalSignature(encoderVersion));
return encodeFuncSignature(this.canonicalSignature(encoderVersion));
}
}
13 changes: 10 additions & 3 deletions src/ast/implementation/declaration/event_definition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ABIEncoderVersion } from "../../../types/abi";
import { ASTNode } from "../../ast_node";
import { encodeSignature } from "../../utils";
import { encodeEventSignature } from "../../utils";
import { ParameterList } from "../meta/parameter_list";
import { StructuredDocumentation } from "../meta/structured_documentation";
import { ContractDefinition } from "./contract_definition";
Expand Down Expand Up @@ -80,10 +80,17 @@ export class EventDefinition extends ASTNode {
}

/**
* Returns HEX string containing first 4 bytes of Keccak256 hash function
* Returns HEX string containing first 32 bytes of Keccak256 hash function
* applied to the canonical representation of the event signature.
*/
canonicalSignatureHash(encoderVersion: ABIEncoderVersion): string {
return encodeSignature(this.canonicalSignature(encoderVersion));
return encodeEventSignature(this.canonicalSignature(encoderVersion));
}

/**
* Returns 32 bytes of event topic hash or `undefined` if event is declared as anonymous.
*/
eventTopic(encoderVersion: ABIEncoderVersion): string | undefined {
return this.anonymous ? undefined : this.canonicalSignatureHash(encoderVersion);
}
}
4 changes: 2 additions & 2 deletions src/ast/implementation/declaration/function_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FunctionStateMutability,
FunctionVisibility
} from "../../constants";
import { encodeSignature } from "../../utils";
import { encodeFuncSignature } from "../../utils";
import { ModifierInvocation } from "../meta/modifier_invocation";
import { OverrideSpecifier } from "../meta/override_specifier";
import { ParameterList } from "../meta/parameter_list";
Expand Down Expand Up @@ -209,6 +209,6 @@ export class FunctionDefinition extends ASTNode {
canonicalSignatureHash(encoderVersion: ABIEncoderVersion): string {
const signature = this.canonicalSignature(encoderVersion);

return signature ? encodeSignature(signature) : "";
return signature ? encodeFuncSignature(signature) : "";
}
}
4 changes: 2 additions & 2 deletions src/ast/implementation/declaration/modifier_definition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ABIEncoderVersion } from "../../../types/abi";
import { ASTNode } from "../../ast_node";
import { encodeSignature } from "../../utils";
import { encodeFuncSignature } from "../../utils";
import { OverrideSpecifier } from "../meta/override_specifier";
import { ParameterList } from "../meta/parameter_list";
import { StructuredDocumentation } from "../meta/structured_documentation";
Expand Down Expand Up @@ -114,6 +114,6 @@ export class ModifierDefinition extends ASTNode {
* applied to the canonical representation of the modifier signature.
*/
canonicalSignatureHash(encoderVersion: ABIEncoderVersion): string {
return encodeSignature(this.canonicalSignature(encoderVersion));
return encodeFuncSignature(this.canonicalSignature(encoderVersion));
}
}
4 changes: 2 additions & 2 deletions src/ast/implementation/declaration/variable_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Mutability,
StateVariableVisibility
} from "../../constants";
import { encodeSignature } from "../../utils";
import { encodeFuncSignature } from "../../utils";
import { Expression } from "../expression/expression";
import { OverrideSpecifier } from "../meta/override_specifier";
import { StructuredDocumentation } from "../meta/structured_documentation";
Expand Down Expand Up @@ -268,6 +268,6 @@ export class VariableDeclaration extends ASTNode {
* corresponding to this state variable.
*/
getterCanonicalSignatureHash(encoderVersion: ABIEncoderVersion): string {
return encodeSignature(this.getterCanonicalSignature(encoderVersion));
return encodeFuncSignature(this.getterCanonicalSignature(encoderVersion));
}
}
72 changes: 40 additions & 32 deletions src/ast/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function checkVFieldCtx<T extends ASTNode, K extends keyof T>(
if (val instanceof ASTNode) {
if (!inCtx(val, ctx)) {
throw new Error(
`Node ${pp(node)} property ${prop} ${pp(val)} not in expected context ${pp(
`Node ${pp(node)} property ${String(prop)} ${pp(val)} not in expected context ${pp(
ctx
)}. Instead in ${pp(val.context)}`
);
Expand All @@ -109,20 +109,24 @@ function checkVFieldCtx<T extends ASTNode, K extends keyof T>(

if (!(el instanceof ASTNode)) {
throw new Error(
`Expected property ${prop}[${idx}] of ${pp(node)} to be an ASTNode not ${el}`
`Expected property ${String(prop)}[${idx}] of ${pp(
node
)} to be an ASTNode not ${el}`
);
}

if (!inCtx(val, ctx)) {
throw new Error(
`Node ${pp(node)} property ${prop}[${idx}] ${pp(
`Node ${pp(node)} property ${String(prop)}[${idx}] ${pp(
el
)} not in expected context ${pp(ctx)}. Instead in ${pp(el.context)}`
);
}
}
} else {
throw new Error(`Expected property ${prop} of ${pp(node)} to be an ASTNode, not ${val}`);
throw new Error(
`Expected property ${String(prop)} of ${pp(node)} to be an ASTNode, not ${val}`
);
}
}

Expand All @@ -148,31 +152,33 @@ function checkFieldAndVFieldMatch<T extends ASTNode, K1 extends keyof T, K2 exte
if (typeof val1 === "number") {
if (!(val2 instanceof ASTNode)) {
throw new Error(
`Expected property ${vField} of ${pp(
node
)} to be an ASTNode when ${field} is a number, not ${val2}`
`Expected property ${String(vField)} of ${pp(node)} to be an ASTNode when ${String(
field
)} is a number, not ${val2}`
);
}

if (val1 != val2.id) {
throw new InsaneASTError(
`Node ${pp(node)} property ${field} ${val1} differs from ${vField}.id ${pp(val2)}`
`Node ${pp(node)} property ${String(field)} ${val1} differs from ${String(
vField
)}.id ${pp(val2)}`
);
}
} else if (val1 instanceof Array) {
if (!(val2 instanceof Array)) {
throw new Error(
`Expected property ${vField} of ${pp(
node
)} to be an array when ${vField} is an array, not ${val2}`
`Expected property ${String(vField)} of ${pp(node)} to be an array when ${String(
vField
)} is an array, not ${val2}`
);
}

if (val1.length !== val2.length) {
throw new InsaneASTError(
`Node ${pp(node)} array properties ${field} and ${vField} have different lengths ${
val1.length
} != ${val2.length}`
`Node ${pp(node)} array properties ${String(field)} and ${String(
vField
)} have different lengths ${val1.length} != ${val2.length}`
);
}

Expand All @@ -182,29 +188,31 @@ function checkFieldAndVFieldMatch<T extends ASTNode, K1 extends keyof T, K2 exte

if (typeof el1 !== "number") {
throw new Error(
`Expected property ${field}[${idx}] of ${pp(node)} to be a number not ${el1}`
`Expected property ${String(field)}[${idx}] of ${pp(
node
)} to be a number not ${el1}`
);
}

if (!(el2 instanceof ASTNode)) {
throw new Error(
`Expected property ${vField}[${idx}] of ${pp(node)} to be a number not ${el2}`
`Expected property ${String(vField)}[${idx}] of ${pp(
node
)} to be a number not ${el2}`
);
}

if (el1 != el2.id) {
throw new InsaneASTError(
`Node ${pp(
node
)} property ${field}[${idx}] ${el1} differs from ${vField}[${idx}].id ${pp(
el2
)}`
`Node ${pp(node)} property ${String(
field
)}[${idx}] ${el1} differs from ${String(vField)}[${idx}].id ${pp(el2)}`
);
}
}
} else {
throw new Error(
`Expected property ${field} of ${pp(
`Expected property ${String(field)} of ${pp(
node
)} to be a number or array of numbers not ${val1}`
);
Expand All @@ -231,7 +239,7 @@ function checkDirectChildren<T extends ASTNode>(node: T, ...fields: Array<keyof
if (val instanceof ASTNode) {
if (!directChildren.has(val)) {
throw new InsaneASTError(
`Field ${field} of node ${pp(node)} is not a direct child: ${pp(
`Field ${String(field)} of node ${pp(node)} is not a direct child: ${pp(
val
)} child of ${pp(val.parent)}`
);
Expand All @@ -248,17 +256,17 @@ function checkDirectChildren<T extends ASTNode>(node: T, ...fields: Array<keyof

if (!(el instanceof ASTNode)) {
throw new Error(
`Field ${field} of ${pp(
`Field ${String(field)} of ${pp(
node
)} is expected to be ASTNode, array or map with ASTNodes - instead array containing ${el}`
);
}

if (!directChildren.has(el)) {
throw new InsaneASTError(
`Field ${field}[${i}] of node ${pp(node)} is not a direct child: ${pp(
el
)} child of ${pp(el.parent)}`
`Field ${String(field)}[${i}] of node ${pp(
node
)} is not a direct child: ${pp(el)} child of ${pp(el.parent)}`
);
}

Expand All @@ -272,25 +280,25 @@ function checkDirectChildren<T extends ASTNode>(node: T, ...fields: Array<keyof

if (!(v instanceof ASTNode)) {
throw new Error(
`Field ${field} of ${pp(
`Field ${String(field)} of ${pp(
node
)} is expected to be ASTNode, array or map with ASTNodes - instead map containing ${v}`
);
}

if (!directChildren.has(v)) {
throw new InsaneASTError(
`Field ${field}[${k}] of node ${pp(node)} is not a direct child: ${pp(
v
)} child of ${pp(v.parent)}`
`Field ${String(field)}[${k}] of node ${pp(
node
)} is not a direct child: ${pp(v)} child of ${pp(v.parent)}`
);
}

computedChildren.add(v);
}
} else {
throw new Error(
`Field ${field} of ${pp(
`Field ${String(field)} of ${pp(
node
)} is neither an ASTNode nor an array of ASTNode or nulls: ${val}`
);
Expand Down
14 changes: 10 additions & 4 deletions src/ast/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const AbiCoder = require("web3-eth-abi");
import coder from "web3-eth-abi";

export type SourceLocation = { offset: number; length: number; sourceIndex: number };

Expand Down Expand Up @@ -68,10 +68,16 @@ export function split(
return result;
}

export function encodeSignature(signature: string, hexPrefix = false): string {
const selector = AbiCoder.encodeFunctionSignature(signature);
export function encodeFuncSignature(signature: string, hexPrefix = false): string {
const selector = coder.encodeFunctionSignature(signature);

return hexPrefix ? selector : selector.substr(2);
return hexPrefix ? selector : selector.slice(2);
}

export function encodeEventSignature(signature: string, hexPrefix = false): string {
const selector = coder.encodeEventSignature(signature);

return hexPrefix ? selector : selector.slice(2);
}

export function* sequence(start = 0, step = 1): Generator<number, number, number> {
Expand Down
Loading

0 comments on commit 9d64433

Please sign in to comment.