Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

[sol-meta] Solidity meta compiler #1127

Open
wants to merge 78 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
5a06e56
Add sol-meta project
recmo Oct 10, 2018
f156ebf
Improved typings for solidity-parser-antlr
recmo Oct 10, 2018
02382c1
Parser and Unparser
recmo Oct 10, 2018
3667fdd
Don't use calldata as a variable name
recmo Oct 10, 2018
9787b36
Add exposer transform
recmo Oct 11, 2018
62c0699
Test exposer
recmo Oct 11, 2018
fd9d44b
Add returns to function declaration
recmo Oct 11, 2018
d3a6094
children is an array not a tuple
recmo Oct 12, 2018
6ccb906
variables can be internal or have default visibility
recmo Oct 12, 2018
7e3592f
Add FunctionCall node type, remove FunctionCallArguments
recmo Oct 12, 2018
2cee9c2
add EmitStatement node type
recmo Oct 12, 2018
048155b
add BooleanLiteral node type
recmo Oct 12, 2018
17d002e
make Visitor generic
recmo Oct 12, 2018
120d872
FunctionDeclaration has body
recmo Oct 12, 2018
36bdbec
typeify some grammar
recmo Oct 12, 2018
3843019
Add StringLiteral and UnaryOperation
recmo Oct 12, 2018
557f059
stricter types
recmo Oct 12, 2018
fa2925a
move utils to separate file
recmo Oct 12, 2018
fb0b1a8
typesafe storage location, contract kind and more
recmo Oct 13, 2018
d4b8898
stricter types
recmo Oct 13, 2018
2805a5c
add mocker
recmo Oct 13, 2018
b7a5e18
cleanup
recmo Oct 13, 2018
de0e443
add missing typing for unparser
recmo Oct 13, 2018
6b2ce88
start with source mapper
recmo Oct 15, 2018
d999642
utils for parameter lists
recmo Oct 15, 2018
88e2ed5
typesafety in unparser
recmo Oct 15, 2018
75696e3
storage location in variable declaration
recmo Oct 15, 2018
74efc84
support parenthesis based tuples
recmo Oct 15, 2018
5eca80d
more typeings
recmo Oct 15, 2018
8d02db9
more typesafety in exposer
recmo Oct 15, 2018
ef64e8c
mock actions and functions
recmo Oct 15, 2018
fe4cc6e
Add C3 Linearization function
recmo Oct 16, 2018
24bc4dd
Merge remote-tracking branch 'origin/development' into HEAD
recmo Nov 9, 2018
2c91d80
[WIP] Flattener
recmo Nov 8, 2018
612fe7e
[WIP] Test files
recmo Nov 8, 2018
e4527ba
[WIP] tsconfig
recmo Nov 8, 2018
081e104
Remove ast typings from sol-cov
recmo Nov 9, 2018
b1aac19
declare local typings as module
recmo Nov 9, 2018
41ccf53
update sol-cov to new grammar
recmo Nov 9, 2018
69b26b7
clean up ts config
recmo Nov 9, 2018
1bab108
type correctness
recmo Nov 9, 2018
135d9e5
Resolve imports and compile
recmo Nov 12, 2018
5d9ab19
Refactor to SourceReader
recmo Nov 14, 2018
12a8ffd
Add missing ABIv2 pragmas
recmo Nov 15, 2018
1e8688e
Add documentation in readme
recmo Nov 15, 2018
5352a53
Globbbing and separate local from scoped
recmo Nov 15, 2018
7f72146
Rename mocker to stubber
recmo Nov 15, 2018
ef50229
Refactor CLI
recmo Nov 15, 2018
a8dab3d
Export getSolcAsync
recmo Nov 15, 2018
6835719
Update package.json
recmo Nov 15, 2018
79e7f7d
Generate constructors and force non-abstractness
recmo Nov 15, 2018
ddf32d7
Parameterize strings
recmo Nov 15, 2018
eb7a98f
Solc wrapper for test compiles
recmo Nov 15, 2018
d2192fc
Main contract exposing / stubbing logic
recmo Nov 15, 2018
d0188a5
Handle modifiers in flattener
recmo Nov 15, 2018
6b98ba6
Lint linearization
recmo Nov 15, 2018
d989c2c
Compile-time script certain functions
recmo Nov 15, 2018
733bced
Various utilities
recmo Nov 15, 2018
f18f13f
Add version to Solc instance type
recmo Nov 15, 2018
b18d9bd
Improve typings
recmo Nov 15, 2018
cc6b064
Add to readme
recmo Nov 16, 2018
724ade1
Merge branch 'development' into feature/sol-meta
recmo Nov 30, 2018
ec9f18a
name can be null for fallback and constructor
recmo Nov 30, 2018
27a1eb6
rename to callData
recmo Nov 30, 2018
3af23ea
Improve readme
recmo Nov 30, 2018
b15f26a
number all enum entries
recmo Nov 30, 2018
25b3349
add Deferred to utils
recmo Nov 30, 2018
5d7fc0c
fix version
recmo Nov 30, 2018
56c8544
review improvements
recmo Nov 30, 2018
15cd924
remove console log from compiler
recmo Nov 30, 2018
ba6603d
remove temp files
recmo Nov 30, 2018
f00ae95
test mock generator
recmo Nov 30, 2018
7e59676
tsling-config is in @0x/
recmo Dec 12, 2018
3f81ed4
Update yarn.lock
recmo Dec 12, 2018
5a6da6f
ts-lint fix sol-compiler
recmo Dec 12, 2018
8731a06
Satisfy linter
recmo Dec 13, 2018
fe3761e
Tag todos
recmo Dec 13, 2018
ad3b0b0
Set codeowner on sol-meta
recmo Dec 13, 2018
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 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ packages/monorepo-scripts/ @fabioberger
packages/order-utils/ @fabioberger @LogvinovLeon
packages/sol-compiler/ @LogvinovLeon
packages/sol-cov/ @LogvinovLeon
packages/sol-meta/ @recmo
packages/sol-resolver/ @LogvinovLeon
packages/subproviders/ @fabioberger @dekz
packages/verdaccio/ @albrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;

import "../../utils/LibBytes/LibBytes.sol";
import "../../utils/ReentrancyGuard/ReentrancyGuard.sol";
Expand Down Expand Up @@ -239,18 +240,18 @@ contract MixinSignatureValidator is
view
returns (bool isValid)
{
bytes memory calldata = abi.encodeWithSelector(
bytes memory callData = abi.encodeWithSelector(
IWallet(walletAddress).isValidSignature.selector,
hash,
signature
);
assembly {
let cdStart := add(calldata, 32)
let cdStart := add(callData, 32)
let success := staticcall(
gas, // forward all gas
walletAddress, // address of Wallet contract
cdStart, // pointer to start of input
mload(calldata), // length of input
mload(callData), // length of input
cdStart, // write output over input
32 // output size is 32 bytes
)
Expand Down Expand Up @@ -288,19 +289,19 @@ contract MixinSignatureValidator is
view
returns (bool isValid)
{
bytes memory calldata = abi.encodeWithSelector(
bytes memory callData = abi.encodeWithSelector(
IValidator(signerAddress).isValidSignature.selector,
hash,
signerAddress,
signature
);
assembly {
let cdStart := add(calldata, 32)
let cdStart := add(callData, 32)
let success := staticcall(
gas, // forward all gas
validatorAddress, // address of Validator contract
cdStart, // pointer to start of input
mload(calldata), // length of input
mload(callData), // length of input
cdStart, // write output over input
32 // output size is 32 bytes
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

*/
pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will actually change the bytecode of this contract and we purposely removed pragma experimental ABIEncoderV2; when not necessary because it reduced gas costs. What is the reason for adding this back in?

Edit: I see why we need this to generate public wrappers for all of these internal functions. Is there a better way to do this that doesn't require us altering the underlying contract?

Copy link
Contributor Author

@recmo recmo Nov 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the final Exchange contract has ABIv2 enabled, doesn't that automatically enable it for all parent contracts?

There are ways around it, I just thought it was incorrectly missing here since everything will be compiled with ABIv2 anyway. In the same way that we want the solidity version the same everywhere, we also want the compiler flags the same.


import "./libs/LibExchangeErrors.sol";
import "./mixins/MSignatureValidator.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above :)


import "../../../utils/SafeMath/SafeMath.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


import "./LibEIP712.sol";

Expand Down Expand Up @@ -45,13 +46,13 @@ contract LibOrder is
// A valid order remains fillable until it is expired, fully filled, or cancelled.
// An order's state is unaffected by external factors, like account balances.
enum OrderStatus {
INVALID, // Default value
INVALID_MAKER_ASSET_AMOUNT, // Order does not have a valid maker asset amount
INVALID_TAKER_ASSET_AMOUNT, // Order does not have a valid taker asset amount
FILLABLE, // Order is fillable
EXPIRED, // Order has already expired
FULLY_FILLED, // Order is fully filled
CANCELLED // Order has been cancelled
INVALID, // 0 Default value
INVALID_MAKER_ASSET_AMOUNT, // 1 Order does not have a valid maker asset amount
INVALID_TAKER_ASSET_AMOUNT, // 2 Order does not have a valid taker asset amount
FILLABLE, // 3 Order is fillable
EXPIRED, // 4 Order has already expired
FULLY_FILLED, // 5 Order is fully filled
CANCELLED // 6 Order has been cancelled
}

// solhint-disable max-line-length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,84 +92,84 @@ contract ReentrantERC20Token is
LibOrder.Order[] memory orders;
uint256[] memory takerAssetFillAmounts;
bytes[] memory signatures;
bytes memory calldata;
bytes memory cdata;

// Create calldata for function that corresponds to currentFunctionId
// Create cdata for function that corresponds to currentFunctionId
if (currentFunctionId == uint8(ExchangeFunction.FILL_ORDER)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.fillOrder.selector,
order,
0,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.FILL_OR_KILL_ORDER)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.fillOrKillOrder.selector,
order,
0,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_FILL_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.batchFillOrders.selector,
orders,
takerAssetFillAmounts,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_FILL_OR_KILL_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.batchFillOrKillOrders.selector,
orders,
takerAssetFillAmounts,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MARKET_BUY_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.marketBuyOrders.selector,
orders,
0,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MARKET_SELL_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.marketSellOrders.selector,
orders,
0,
signatures
);
} else if (currentFunctionId == uint8(ExchangeFunction.MATCH_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.matchOrders.selector,
order,
order,
signature,
signature
);
} else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDER)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.cancelOrder.selector,
order
);
} else if (currentFunctionId == uint8(ExchangeFunction.BATCH_CANCEL_ORDERS)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.batchCancelOrders.selector,
orders
);
} else if (currentFunctionId == uint8(ExchangeFunction.CANCEL_ORDERS_UP_TO)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.cancelOrdersUpTo.selector,
0
);
} else if (currentFunctionId == uint8(ExchangeFunction.SET_SIGNATURE_VALIDATOR_APPROVAL)) {
calldata = abi.encodeWithSelector(
cdata = abi.encodeWithSelector(
EXCHANGE.setSignatureValidatorApproval.selector,
address(0),
false
);
}

// Call Exchange function, swallow error
address(EXCHANGE).call(calldata);
address(EXCHANGE).call(cdata);

// Revert reason is 100 bytes
bytes memory returnData = new bytes(100);
Expand All @@ -185,4 +185,4 @@ contract ReentrantERC20Token is
// Transfer will return true if function failed for any other reason
return true;
}
}
}
4 changes: 4 additions & 0 deletions packages/sol-compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export class Compiler {
private readonly _artifactsDir: string;
private readonly _solcVersionIfExists: string | undefined;
private readonly _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER;
public static async getSolcAsync(solcVersion: string): Promise<solc.SolcInstance> {
const solcInstance = (await this._getSolcAsync(solcVersion)).solcInstance;
return solcInstance;
}
private static async _getSolcAsync(
solcVersion: string,
): Promise<{ solcInstance: solc.SolcInstance; fullSolcVersion: string }> {
Expand Down
5 changes: 1 addition & 4 deletions packages/sol-cov/src/ast_visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ export class ASTVisitor {
public WhileStatement(ast: Parser.WhileStatement): void {
this._visitStatement(ast);
}
public SimpleStatement(ast: Parser.SimpleStatement): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, there's no such node. The solidity-parser-antlr typing where missing a some of node types, and also had some types that did not correspond to nodes. I think the package was updated.

this._visitStatement(ast);
}
public ThrowStatement(ast: Parser.ThrowStatement): void {
this._visitStatement(ast);
}
Expand Down Expand Up @@ -159,7 +156,7 @@ export class ASTVisitor {
}
const loc = this._getExpressionRange(ast);
this._fnMap[this._entryId++] = {
name: ast.name,
name: ast.name || '',
line: loc.start.line,
loc,
};
Expand Down
3 changes: 0 additions & 3 deletions packages/sol-cov/src/get_source_range_snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class ASTInfoVisitor {
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);
}
Expand Down
Loading