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

Gas limit tweaks and EMP bytecode optimization #1356

Merged
merged 3 commits into from
May 5, 2020
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
docker:
- image: circleci/node:lts
- image: trufflesuite/ganache-cli
command: ganache-cli -i 1234 -l 6720000
command: ganache-cli -i 1234 -l 9000000
working_directory: ~/protocol
steps:
- restore_cache:
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
docker:
- image: circleci/node:lts
- image: trufflesuite/ganache-cli
command: ganache-cli -i 1234 -l 6720000 -p 9545 -m "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"
command: ganache-cli -i 1234 -l 9000000 -p 9545 -m "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat"
working_directory: ~/protocol
steps:
- restore_cache:
Expand Down
4 changes: 2 additions & 2 deletions common/globalTruffleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const infuraApiKey = process.env.INFURA_API_KEY ? process.env.INFURA_API_KEY : "

// Default options
const gasPx = 20000000000; // 20 gwei
const gas = 6720000; // Conservative estimate of the block gas limit.
const gas = 9000000; // Conservative estimate of the block gas limit.

// Adds a public network.
// Note: All public networks can be accessed using keys from GCS using the ManagedSecretProvider or using a mnemonic in the
Expand Down Expand Up @@ -143,7 +143,7 @@ module.exports = {
settings: {
optimizer: {
enabled: true,
runs: 500
runs: 200
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma experimental ABIEncoderV2;
import "../../oracle/implementation/ContractCreator.sol";
import "../../common/implementation/Testable.sol";
import "../../common/implementation/AddressWhitelist.sol";
import "./ExpiringMultiParty.sol";
import "./ExpiringMultiPartyLib.sol";


/**
Expand Down Expand Up @@ -115,7 +115,7 @@ contract ExpiringMultiPartyCreator is ContractCreator, Testable {
* @return address of the deployed ExpiringMultiParty contract
*/
function createExpiringMultiParty(Params memory params) public returns (address) {
ExpiringMultiParty derivative = new ExpiringMultiParty(_convertParams(params));
address derivative = ExpiringMultiPartyLib.deploy(_convertParams(params));

address[] memory parties = new address[](1);
parties[0] = msg.sender;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;

import "./ExpiringMultiParty.sol";


/**
* @title Provides convenient Expiring Multi Party contract utilities.
* @dev Using this library to deploy EMP's allows calling contracts to avoid importing the full EMP bytecode.
*/
library ExpiringMultiPartyLib {
/**
* @notice Returns address of new EMP deployed with given `params` configuration.
* @dev Caller will need to register new EMP with the Registry to begin requesting prices. Caller is also
* responsible for enforcing constraints on `params`.
* @param params is a `ConstructorParams` object from ExpiringMultiParty.
* @return address of the deployed ExpiringMultiParty contract
*/
function deploy(ExpiringMultiParty.ConstructorParams memory params) public returns (address) {
ExpiringMultiParty derivative = new ExpiringMultiParty(params);
return address(derivative);
}
}
5 changes: 5 additions & 0 deletions core/migrations/14_deploy_expiring_multi_party_creator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Finder = artifacts.require("Finder");
const ExpiringMultiPartyCreator = artifacts.require("ExpiringMultiPartyCreator");
const ExpiringMultiPartyLib = artifacts.require("ExpiringMultiPartyLib");
const AddressWhitelist = artifacts.require("AddressWhitelist");
const TokenFactory = artifacts.require("TokenFactory");
const { getKeysForNetwork, deploy, enableControllableTiming } = require("../../common/MigrationUtils.js");
Expand All @@ -17,6 +18,10 @@ module.exports = async function(deployer, network, accounts) {
const finder = await Finder.deployed();
const tokenFactory = await TokenFactory.deployed();

// Deploy EMPLib and link to EMPCreator.
await deploy(deployer, network, ExpiringMultiPartyLib);
await deployer.link(ExpiringMultiPartyLib, ExpiringMultiPartyCreator);
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there another example in the repo of linking libraries with contracts before deploying? I couldn't find one so I did it explicitly here.

Copy link
Member

Choose a reason for hiding this comment

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

If you look at the TokenizedDerivativeUtils library from before we removed it from the repo, we did the same thing there.


await deploy(
deployer,
network,
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/local/CalculateContractBytecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = async function(callback) {
// Load contracts into script and output info.
console.log("loading", argv.contract + ".json");
let obj = require("./../../build/contracts/" + argv.contract + ".json");
const byteCodeSize = (obj.bytecode.length - 2) / 2;
const byteCodeSize = (obj.deployedBytecode.length - 2) / 2;
const remainingSize = 2 ** 14 + 2 ** 13 - byteCodeSize;
console.log("Contract is", byteCodeSize, "bytes in size.");
console.log("This leaves a total of", remainingSize, "bytes within the EIP170 limit.");
Expand Down