Skip to content

Contract size optimization #99

Description

@hashmesan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions