Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare to solc-typed-ast v16.0.0 release #232

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,827 changes: 1,213 additions & 614 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"findup-sync": "^5.0.0",
"fs-extra": "^11.1.1",
"logplease": "^1.2.15",
"semver": "^7.5.1",
"solc-typed-ast": "^15.0.0",
"semver": "^7.5.4",
"solc-typed-ast": "^16.0.0",
"src-location": "^1.1.0",
"yaml": "^1.10.2"
},
Expand All @@ -38,15 +38,15 @@
"prepare": "npm run build"
},
"devDependencies": {
"@ethereumjs/vm": "^6.4.2",
"@ethereumjs/vm": "^6.5.0",
"@types/bn.js": "^5.1.1",
"@types/fs-extra": "^11.0.1",
"@types/mocha": "^10.0.1",
"@types/node": "^16.18.34",
"@types/node": "^16.18.38",
"@types/semver": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"eslint": "^8.41.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"ethereumjs-abi": "^0.6.8",
Expand All @@ -57,7 +57,7 @@
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"ts-pegjs": "^3.1.0",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
},
"repository": "https://github.com/ConsenSys/scribble.git",
"license": "SEE LICENSE IN <LICENSE>"
Expand Down
15 changes: 9 additions & 6 deletions src/instrumenter/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FunctionStateMutability,
FunctionType,
FunctionVisibility,
InferType,
IntType,
Literal,
LiteralKind,
Expand All @@ -32,8 +33,7 @@ import {
TypeNode,
UncheckedBlock,
VariableDeclaration,
assert,
isFunctionCallExternal
assert
} from "solc-typed-ast";
import { AnnotationType, SLetAnnotation, SNode } from "../spec-lang/ast";
import {
Expand Down Expand Up @@ -107,22 +107,25 @@ export function changesMutability(ctx: InstrumentationContext): boolean {
* Find all external calls in the `ContractDefinition`/`FunctionDefinition` `node`.
* Ignore any calls that were inserted by instrumentation (we tell those appart by their `<missing>` typeString).
*/
export function findExternalCalls(node: ContractDefinition | FunctionDefinition): FunctionCall[] {
export function findExternalCalls(
node: ContractDefinition | FunctionDefinition,
inference: InferType
): FunctionCall[] {
const interestingExternalCallBuiltins = ["call", "delegatecall", "staticcall"];

return node.getChildrenBySelector(
(node) =>
node instanceof FunctionCall &&
node.vExpression.typeString !== "<missing>" &&
isFunctionCallExternal(node) &&
inference.isFunctionCallExternal(node) &&
(node.vFunctionCallType === ExternalReferenceType.UserDefined ||
interestingExternalCallBuiltins.includes(node.vFunctionName))
);
}

/**
* Build a debug event/debug event emission statement for each of the provided `annotations`. Return
* an array of the computed tuples `[EventDefinition, `EmitStatement`].
* an array of the computed tuples `[EventDefinition, EmitStatement]`.
*
* If a given annotation doesn't have any identifiers to output for debugging purposes, return `undefined`
* in that respective index.
Expand Down Expand Up @@ -885,7 +888,7 @@ function replaceExternalCallSites(
): void {
const factory = ctx.factory;

for (const callSite of findExternalCalls(contract)) {
for (const callSite of findExternalCalls(contract, ctx.typeEnv.inference)) {
const containingFun = callSite.getClosestParentByType(FunctionDefinition);

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// This file is auto-generated by Scribble and shouldn't be edited directly.
/// Use --disarm prior to make any changes.
/// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;

interface IERC20 {
Expand Down Expand Up @@ -80,7 +81,7 @@ contract ERC20 is IERC20 {
__ScribbleUtilsLib__406.setInContract(true);
RET_0 = _original_ERC20_totalSupply();
if (!(RET_0 == balances.sum)) {
emit __ScribbleUtilsLib__406.AssertionFailed("002529:0101:001 3: Result is equal to sum of balances");
emit __ScribbleUtilsLib__406.AssertionFailed("002569:0101:001 3: Result is equal to sum of balances");
assert(false);
}
if (_v.__scribble_check_invs_at_end) __scribble_check_state_invariants();
Expand All @@ -97,7 +98,7 @@ contract ERC20 is IERC20 {
__ScribbleUtilsLib__406.setInContract(true);
RET_0 = _original_ERC20_balanceOf(account);
if (!(RET_0 == address_to_uint256_406.get(balances, account))) {
emit __ScribbleUtilsLib__406.AssertionFailed("003325:0119:001 4: Returns the balance of owner in the balances mapping");
emit __ScribbleUtilsLib__406.AssertionFailed("003365:0119:001 4: Returns the balance of owner in the balances mapping");
assert(false);
}
if (_v.__scribble_check_invs_at_end) __scribble_check_state_invariants();
Expand All @@ -119,19 +120,19 @@ contract ERC20 is IERC20 {
_v.old_5 = address_to_uint256_406.get(balances, msg.sender);
RET_0 = _original_ERC20_transfer(receiver, amount);
if (!(_v.old_1)) {
emit __ScribbleUtilsLib__406.AssertionFailed("004511:0113:001 6: The sender has sufficient balance at the start");
emit __ScribbleUtilsLib__406.AssertionFailed("004551:0113:001 6: The sender has sufficient balance at the start");
assert(false);
}
if (!((!(msg.sender != receiver)) || ((_v.old_2 - amount) == address_to_uint256_406.get(balances, msg.sender)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("004798:0100:001 7: The sender has value less balance");
emit __ScribbleUtilsLib__406.AssertionFailed("004838:0100:001 7: The sender has value less balance");
assert(false);
}
if (!((!(msg.sender != receiver)) || ((_v.old_3 + amount) == address_to_uint256_406.get(balances, receiver)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("005070:0095:001 8: The receiver receives _value");
emit __ScribbleUtilsLib__406.AssertionFailed("005110:0095:001 8: The receiver receives _value");
assert(false);
}
if (!((_v.old_4 + _v.old_5) == (address_to_uint256_406.get(balances, receiver) + address_to_uint256_406.get(balances, msg.sender)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("005359:0111:001 9: Transfer does not modify the sum of balances");
emit __ScribbleUtilsLib__406.AssertionFailed("005399:0111:001 9: Transfer does not modify the sum of balances");
assert(false);
}
if (_v.__scribble_check_invs_at_end) __scribble_check_state_invariants();
Expand All @@ -152,7 +153,7 @@ contract ERC20 is IERC20 {
__ScribbleUtilsLib__406.setInContract(true);
RET_0 = _original_ERC20_approve(delegate, amount);
if (!(allowances[msg.sender][delegate] == amount)) {
emit __ScribbleUtilsLib__406.AssertionFailed("006551:0133:001 10: spender will have an allowance of value for this sender's balance");
emit __ScribbleUtilsLib__406.AssertionFailed("006591:0133:001 10: spender will have an allowance of value for this sender's balance");
assert(false);
}
if (_v.__scribble_check_invs_at_end) __scribble_check_state_invariants();
Expand Down Expand Up @@ -182,27 +183,27 @@ contract ERC20 is IERC20 {
_v.old_12 = address_to_uint256_406.get(balances, owner);
RET_0 = _original_ERC20_transferFrom(owner, buyer, amount);
if (!(_v.old_6)) {
emit __ScribbleUtilsLib__406.AssertionFailed("008075:0114:001 11: The sender has sufficient balance at the start");
emit __ScribbleUtilsLib__406.AssertionFailed("008115:0114:001 11: The sender has sufficient balance at the start");
assert(false);
}
if (!((!(owner != buyer)) || ((_v.old_7 - amount) == address_to_uint256_406.get(balances, owner)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("008350:0101:001 12: The sender has value less balance");
emit __ScribbleUtilsLib__406.AssertionFailed("008390:0101:001 12: The sender has value less balance");
assert(false);
}
if (!((_v.old_8 - amount) == allowances[owner][msg.sender])) {
emit __ScribbleUtilsLib__406.AssertionFailed("008573:0102:001 13: The actor has value less allowance");
emit __ScribbleUtilsLib__406.AssertionFailed("008613:0102:001 13: The actor has value less allowance");
assert(false);
}
if (!(_v.old_9 >= amount)) {
emit __ScribbleUtilsLib__406.AssertionFailed("008763:0098:001 14: The actor has enough allowance");
emit __ScribbleUtilsLib__406.AssertionFailed("008803:0098:001 14: The actor has enough allowance");
assert(false);
}
if (!((!(owner != buyer)) || ((_v.old_10 + amount) == address_to_uint256_406.get(balances, buyer)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("009023:0095:001 15: The receiver receives value");
emit __ScribbleUtilsLib__406.AssertionFailed("009063:0095:001 15: The receiver receives value");
assert(false);
}
if (!((_v.old_11 + _v.old_12) == (address_to_uint256_406.get(balances, buyer) + address_to_uint256_406.get(balances, owner)))) {
emit __ScribbleUtilsLib__406.AssertionFailed("009306:0112:001 16: Transfer does not modify the sum of balances");
emit __ScribbleUtilsLib__406.AssertionFailed("009346:0112:001 16: Transfer does not modify the sum of balances");
assert(false);
}
if (_v.__scribble_check_invs_at_end) __scribble_check_state_invariants();
Expand Down
3 changes: 2 additions & 1 deletion test/multifile_samples/macros/base.sol.instrumented.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// This file is auto-generated by Scribble and shouldn't be edited directly.
/// Use --disarm prior to make any changes.
/// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

/// #macro ownable(owner);
Expand Down Expand Up @@ -36,7 +37,7 @@ contract Ownable {
RET0 = owner;
unchecked {
if (!(_v.old_0 == msg.sender)) {
emit __ScribbleUtilsLib__57.AssertionFailed("001042:0097:000 2: can only be updated by an owner");
emit __ScribbleUtilsLib__57.AssertionFailed("001082:0097:000 2: can only be updated by an owner");
assert(false);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions test/unit/interposing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,6 @@ contract Foo {
const [contract, fun] = findContractAndFun(units, contractName, funName);
const factory = new ScribbleFactory(compilerVersion, reader.context);

const callSite = single(
findExternalCalls(fun),
`Expect single external callsite per tested function`
);

const ctx = makeInstrumentationCtx(
units,
factory,
Expand All @@ -681,6 +676,11 @@ contract Foo {
compilerVersion
);

const callSite = single(
findExternalCalls(fun, ctx.typeEnv.inference),
`Expect single external callsite per tested function`
);

interposeCall(ctx, contract, callSite);

ctx.finalize();
Expand Down