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

Stake locks extracted out of TokenStaking into a library #1888

Merged
merged 2 commits into from
Jul 3, 2020
Merged

Conversation

pdyraga
Copy link
Member

@pdyraga pdyraga commented Jul 3, 2020

This change allows us to save some bytecode space in TokenStaking for top-ups implementation. The contract size went down from 24926 to 22409 (-2517 bytes).

I have also introduced initTokenStaking function in initContracts.js to keep the details about TokenStaking library linking and deployment there and not pollute every unit test with the same logic.

Last but not least, LockUtils library has been moved to sit next to Locks library.

This change allows to save some bytecode space in TokenStaking for top
ups implementation. The contract size went down from 24926 to 22409
(-2517 bytes).

I have also introduced initTokenStaking function in initContracts.js to
keep the details about TokenStaking library linking and deployment there
and not pollute every unit test with the same logic.

Last but not least, LockUtils library has been moved to sit next to
Locks library.
@pdyraga
Copy link
Member Author

pdyraga commented Jul 3, 2020

const TokenStaking = artifacts.require("TokenStaking.sol");

module.exports = async function() {
    let instance = await TokenStaking.deployed();

    let bytecode = instance.constructor._json.bytecode;
    let deployedBytecode = instance.constructor._json.deployedBytecode;
    
    let bytecodeSize = bytecode.length / 2; // size in bytes
    let deployedBytecodeSize = deployedBytecode.length / 2; // size in bytes

    console.log(
      "TokenStaking size of bytecode in bytes = ", 
      bytecodeSize
    );
    console.log(
      "TokenStaking size of deployed bytecode in bytes = ", 
      deployedBytecodeSize
    );
    console.log(
      "TokenStaking initialization and constructor code in bytes = ", 
      bytecodeSize - deployedBytecodeSize
    );
}

Before:

TokenStaking size of bytecode in bytes =  24926
TokenStaking size of deployed bytecode in bytes =  24434
TokenStaking initialization and constructor code in bytes =  492

After:

TokenStaking size of bytecode in bytes =  22409
TokenStaking size of deployed bytecode in bytes =  21919
TokenStaking initialization and constructor code in bytes =  490

@nkuba nkuba merged commit e93c914 into master Jul 3, 2020
@nkuba nkuba deleted the locks-library branch July 3, 2020 13:20
nkuba added a commit that referenced this pull request Jul 14, 2020
Reduce bytecode size of TokenStaking contract

Extracting stake locks to a separate library (#1888) provided some space in `TokenStaking` bytecode but we quickly used all of that space for the implementation of top-ups (#1893). In this PR, we are doing small changes, one by one, to reduce the bytecode size to allow for stake bridge implementation (#1883). This PR reduces the bytecode from `24596` to `24270` (`-326` bytes) and will let us add just a few lines of code, an absolute minimum needed for the stake bridge implementation.
@pdyraga pdyraga added this to the v1.3.0 milestone Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants