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

Contract size optimization #99

Open
hashmesan opened this issue Apr 20, 2022 · 0 comments
Open

Contract size optimization #99

hashmesan opened this issue Apr 20, 2022 · 0 comments

Comments

@hashmesan
Copy link

hashmesan commented Apr 20, 2022

OneBTC contract size is currently over the 24KB limit. There are a couple strategies to reducing the size.

Current change

The least disruptive method, without changing the architecture significantly is moving any shared library (static linked) into dynamically linked libraries.

In hashmesan@8f0ec01 , the SecP256K1Lib and TXValidate libraries were identified to convert to linked library.

  1. The library interface must be changed from internal to external
  2. The libraries deployed separately and linked... see below
const Secp256k1Lib = await Secp256k1.new();
OneBtc.link("Secp256k1", Secp256k1Lib.address);

const TxValidateLib = await TxValidate.new();
OneBtc.link("TxValidate", TxValidateLib.address);

oneBtc = await deployProxy(OneBtc, [RelayMock.address, ExchangeRateOracleWrapper.address],{unsafeAllowLinkedLibraries: true});

As per warning

Warning: Potentially unsafe deployment of OneBtc

    You are using the `unsafeAllow.external-library-linking` flag to include external libraries.
    Make sure you have manually checked that the linked libraries are upgrade safe.

We must be cautious of using any shared datastructure that might change in the upgraded library OR interfaces change that may break the dependencies. We can always deploy brand new library every time which avoid this issue altogether.

Future change

Later on if we hit the 24k again, we may have to separate Issue , Redeem, and Replace as libraries and isolate storage into OneBTC. This is a huge architecture change we need to avoid as much as we can.

hashmesan pushed a commit to hashmesan/onebtc that referenced this issue Apr 20, 2022
hashmesan pushed a commit to hashmesan/onebtc that referenced this issue Apr 25, 2022
hashmesan pushed a commit to hashmesan/onebtc that referenced this issue Apr 25, 2022
hashmesan pushed a commit to hashmesan/onebtc that referenced this issue Apr 25, 2022
hashmesan pushed a commit to hashmesan/onebtc that referenced this issue Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant