CRYPTO NEWS

Stumped by contract size limit

I have cut as much as I can think of from the following contract yet it is still reported by hardhat size-contract as 24.08 and when I try to compile it says contract over limit.

I have set optimize: true, run: 2, still no help. There are lot of imports obviously, but I did that because that seemed to be path to keeping the size of this one small. The contract itself is only 11K as an .rtf text file, not sure how it turns into 24K bytes as a program. Ive read the taken the obvious steps I could think of to reduce the size, but seems like something must be taking up a lot more bytes than it looks like in code.

One thing that occurs to me that there are a lot of enums and struct definitions in the import "EnumsLibrary" which appear at the top of the file before the library statement. Are those enum and struct definitions counting against me because they aren’t inside the library?

EDIT: Having done some more investigation, I have determined that putting all the definition inside ratehr than outside the library makes no difference to contract size.

I have also found that cutting just one function is reducing the size of the contract from 24K to just 4K.

 function createContract(BKLiteMeta memory meta)                public        payable       returns(address)  {     require(meta.publisherAddress == msg.sender, "only pub");     return(address(new BKopyLite(meta))); } 

In particular, it’s the last statement in the function with calls new BKopyLite(meta);. Why would that one statement add 20K to the size of this contract? There’s a lot going on in the constructor of BKopyLite that is being called here, but why is it adding so much size to this contract? Is there a better way to create a new contract from within another contract then the way I’m doing it here that doesn’t take up so much space?

//SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.6;  import "./BKopyStrings.sol"; import "./9_BindingTemplate.sol"; import "./10_BindingManager.sol"; import "./BKopyAccessControl.sol"; import "./BKopyLite.sol"; import "./EnumsLibrary.sol";    contract BKopyRoot  {      struct PriceList {         uint32 publishPriceLite;         uint32 mintPriceLite;         uint32 transferPriceLite;         uint32 royaltyTransferBasisPts;     }          BKAccessControl private secure;     address private bindingManager;     address public immutable rootOwner;       address public immutable rootAddress;     PriceList private priceList;     uint private _feesReceived;      constructor(address failSafeAddr) {         rootOwner = msg.sender;         rootAddress = address(this);         secure = new BKAccessControl(msg.sender, failSafeAddr );         bindingManager = address(new BindingManager());         priceList.mintPriceLite = 350000;         priceList.publishPriceLite = 7000000;         priceList.transferPriceLite = 175000;         priceList.royaltyTransferBasisPts = 350;     }      modifier onlyBindingManager {         bool qualified = secure.isSenderInRole(Role.BindingManagerRole);         require(qualified, "nsf BM");         _;     }      modifier onlyFinanceManager {         bool qualified = secure.isSenderInRole(Role.FinanceManagerRole);         require(qualified, "nsf FM");         _;     }     //bytes private constant CONTRACT_VERSION = bytes("0.0.1");        using BKopyStrings for string;       function ownerAddress() public view returns(address) {          return rootOwner;      }           function makeTemplate(TemplateFactoryMeta memory factoryMeta) public onlyBindingManager {       // console.log("starting make template");         TemplateMeta memory tempMeta = factoryMeta.templateMeta;                string memory bindingName = tempMeta.bindingName;         BindingManager(bindingManager).makeTemplate(tempMeta.bindingName,                       tempMeta.templateText,                      tempMeta.plainText,                      tempMeta.bindingType                      );                  for(uint i=0; i<factoryMeta.paramsMeta.length; i++) {             ParamMeta memory p = factoryMeta.paramsMeta[i];             BindingManager(bindingManager).addBindingParameter(                 tempMeta.bindingName,                 p.name,                 p.isNumeric             );             if (!p.required) {                 BindingManager(bindingManager).markParamOptionalForBinding(                     tempMeta.bindingName,                     p.name                 );             }         }        BindingManager(bindingManager).publish(bindingName);     }      function getBindingNameList() public view returns(string[] memory) {        return BindingManager(bindingManager).getBindingNameList();     }     function getBindingText(string memory bindingName) public view returns(string memory) {        return BindingManager(bindingManager).getTemplate(bindingName).templateText();     }       function createContract(BKLiteMeta memory meta)                    public            payable           returns(address)      {         require(meta.publisherAddress == msg.sender, "only pub");         return(address(new BKopyLite(meta)));     }        function setPricingStruct(PriceList memory newPricing) public onlyFinanceManager {         priceList = newPricing;     }     function getPriceList() public view returns(PriceList memory) {         return priceList;     }     function payFee() public payable {                _feesReceived += msg.value;       }     function getBindingManager() public view returns(address) {         return address(bindingManager);     } 

}

Stumped by contract size limit

Shopping cart
There are no products in the cart!
Continue shopping
0