Skip to content

Commit

Permalink
harmony-one#99 reduced OneBTC Contract size from 24KB to 21KB
Browse files Browse the repository at this point in the history
  • Loading branch information
hashmesan committed Apr 20, 2022
1 parent d41b561 commit 8f0ec01
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion contract/bridge/contracts/TxValidate.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.6.12;

import "@openzeppelin/contracts-upgradeable/math/MathUpgradeable.sol";
import {BTCUtils} from "@interlay/bitcoin-spv-sol/contracts/BTCUtils.sol";
import {BytesLib} from "@interlay/bitcoin-spv-sol/contracts/BytesLib.sol";
Expand All @@ -16,7 +17,7 @@ library TxValidate {
address recipientBtcAddress,
uint256 opReturnId,
uint256 outputIndex
) internal pure returns (uint256) {
) external pure returns (uint256) {
uint256 btcAmount;
address btcAddress;

Expand Down
2 changes: 1 addition & 1 deletion contract/bridge/contracts/crypto/Secp256k1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library Secp256k1 {
uint256 scale,
uint256 Px,
uint256 Py
) internal pure returns (uint256, uint256) {
) external pure returns (uint256, uint256) {
require(scale % NN != 0, "invalid scale");
return EllipticCurve.ecMul(scale, Px, Py, AA, PP);
}
Expand Down
11 changes: 10 additions & 1 deletion contract/bridge/migrations/3_deploy_onebtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const Secp256k1 = artifacts.require("Secp256k1");
const TxValidate = artifacts.require("TxValidate");

module.exports = async function(deployer) {

const IRelay = await RelayMock.deployed();
const IExchangeRateOracleWrapper = await ExchangeRateOracleWrapper.deployed();
const Secp256k1Lib = await deployer.deploy(Secp256k1);
OneBtc.link("Secp256k1", Secp256k1Lib.address);

const c = await deployProxy(OneBtc, [IRelay.address, IExchangeRateOracleWrapper.address], { deployer } );
const TxValidateLib = await deployer.deploy(TxValidate);
OneBtc.link("TxValidate", TxValidateLib.address);

const c = await deployProxy(OneBtc, [IRelay.address, IExchangeRateOracleWrapper.address],
{ deployer, unsafeAllowLinkedLibraries: true } );
console.log(c.address)
};
11 changes: 10 additions & 1 deletion contract/bridge/test/Liquidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const OneBtc = artifacts.require("OneBtc");
const RelayMock = artifacts.require("RelayMock");
const ExchangeRateOracleWrapper = artifacts.require("ExchangeRateOracleWrapper");
const { issueTxMock } = require('./mock/btcTxMock');
const Secp256k1 = artifacts.require("Secp256k1");
const TxValidate = artifacts.require("TxValidate");

const bitcoin = require('bitcoinjs-lib');
const bn=b=>BigInt(`0x${b.toString('hex')}`);
Expand Down Expand Up @@ -39,7 +41,14 @@ contract("liquidation test", accounts => {
before(async function() {
relayMock = await RelayMock.new();
exchangeRateOracleWrapper = await deployProxy(ExchangeRateOracleWrapper);
oneBtc = await deployProxy(OneBtc, [relayMock.address, exchangeRateOracleWrapper.address]);

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

// set BTC/ONE exchange rate
await exchangeRateOracleWrapper.setExchangeRate(10); // 1 OneBtc = 10 ONE
Expand Down

0 comments on commit 8f0ec01

Please sign in to comment.