Skip to content

Commit

Permalink
Gas limit tweaks and EMP bytecode optimization (#1356)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
  • Loading branch information
nicholaspai authored May 5, 2020
1 parent ed62317 commit 3eba0cf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
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 @@ -114,7 +114,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));

_registerContract(new address[](0), address(derivative));

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);

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

0 comments on commit 3eba0cf

Please sign in to comment.