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

Add tests for UUPS proxy. #2087

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contracts/config/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f1"
]
},
"localObscuro": {
"localDebugNetworkFull": {
"chainId": 443,
"url": "http://127.0.0.1:11180/v1/",
"useGateway": true,
Expand All @@ -30,7 +30,7 @@
"4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8"
]
},
"testObscuro": {
"localDebugNetwork": {
"chainId": 443,
"url": "http://127.0.0.1:11180/v1/",
"useGateway": true,
Expand Down Expand Up @@ -132,7 +132,7 @@
"layer1" : "localTestnetGeth"
},
"deploy": [
"deployment_scripts/testing"
"deployment_scripts/testing/004_upgrade_uups.ts"
],
"accounts": [
"8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function waitForRootPublished(management, msg, proof, root, provider: Ethe


const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
return;
const l2Network = hre;
const {deployer} = await hre.getNamedAccounts();

Expand Down
25 changes: 25 additions & 0 deletions contracts/deployment_scripts/testing/004_upgrade_uups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DeployFunction} from 'hardhat-deploy/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const UUPSTestV1 = await hre.ethers.getContractFactory("UUPSTestV1");
const uupsTestv1 = await hre.upgrades.deployProxy(UUPSTestV1, [], {
initializer: 'initialize',
kind: 'uups',
txOverrides: {
}
})

await uupsTestv1.waitForDeployment();
const address = await uupsTestv1.getAddress()
console.log("Proxy deployed at", address);

const UUPSTestV2 = await hre.ethers.getContractFactory("UUPSTestV2");
const uuupsTestV2 = await hre.upgrades.upgradeProxy(address, UUPSTestV2);
console.log("UUPS Test V2 deployed to:", await uuupsTestV2.getAddress());

};


export default func;
func.tags = ['GasDebug'];
22 changes: 11 additions & 11 deletions contracts/generated/ManagementContract/ManagementContract.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'ten-hardhat-plugin';
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import '@openzeppelin/hardhat-upgrades';

import "hardhat-abi-exporter";
import "@solidstate/hardhat-bytecode-exporter";
Expand Down Expand Up @@ -59,7 +60,7 @@ const config: HardhatUserConfig = {
// For help configuring - https://www.npmjs.com/package/hardhat-ignore-warnings
warnings : {
'*' : {
default: 'error'
default: 'warn'
},
'src/testing/**/*': {
default: 'off'
Expand Down
10 changes: 5 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@openzeppelin/hardhat-upgrades": "^3.0.0",
"@openzeppelin/hardhat-upgrades": "^3.5.0",
"@solidstate/hardhat-bytecode-exporter": "^1.1.1",
"hardhat": "~2.19.3",
"hardhat-abi-exporter": "^2.10.1",
Expand All @@ -25,11 +25,11 @@
"@openzeppelin/contracts-upgradeable": "^5.0.1",
"@openzeppelin/merkle-tree": "^1.0.7",
"ethers": "^6.6.0",
"hardhat-ignore-warnings": "^0.2.6",
"hardhat-ignore-warnings": "^0.2.11",
"ten-hardhat-plugin": "^0.0.9"
},
"peerDependencies": {
"@nomicfoundation/hardhat-verify" : "2.0.8",
"@nomicfoundation/hardhat-ethers":"3.0.5"
"@nomicfoundation/hardhat-ethers": "3.0.5",
"@nomicfoundation/hardhat-verify": "2.0.8"
}
}
}
6 changes: 3 additions & 3 deletions contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
}
}

// solc-ignore-next-line unused-param
//solc-ignore-next-line unused-param
function AddRollup(Structs.MetaRollup calldata r, string calldata _rollupData, Structs.HeaderCrossChainData calldata) public {
address enclaveID = ECDSA.recover(r.Hash, r.Signature);
// revert if the EnclaveID is not attested
Expand All @@ -162,8 +162,8 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
}

// InitializeNetworkSecret kickstarts the network secret, can only be called once
// solc-ignore-next-line unused-param
function InitializeNetworkSecret(address _enclaveID, bytes calldata _initSecret, string calldata _genesisAttestation) public {
//solc-ignore-next-line unused-param
function InitializeNetworkSecret(address _enclaveID, bytes calldata, string calldata _genesisAttestation) public {
require(!networkSecretInitialized, "network secret already initialized");

// network can no longer be initialized
Expand Down
43 changes: 43 additions & 0 deletions contracts/src/testing/UUPSTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract UUPSTestV1 is Initializable, UUPSUpgradeable, OwnableUpgradeable {
string public message;

function initialize() public initializer {
__Ownable_init(msg.sender);
message = "This is version 1";
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function setMessage(string memory newMessage) public {
message = newMessage;
}

function getVersion() public pure returns (uint256) {
return 1;
}
}

contract UUPSTestV2 is Initializable, UUPSUpgradeable, OwnableUpgradeable {
string public message;

function initialize() public reinitializer(2) {
message = "This is version 2";
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function setMessage(string memory newMessage) public {
message = newMessage;
}

function getVersion() public pure returns (uint256) {
return 2;
}
}
21 changes: 18 additions & 3 deletions go/enclave/rpc/EstimateGas.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func (rpc *EncryptionManager) doEstimateGas(ctx context.Context, args *gethapi.T
}
cap = hi //nolint: revive

isFailedAtMax, _, err := rpc.isGasEnough(ctx, args, hi, blkNumber)
//TODO: Workaround for the weird conensus nil statement down, which gets interwined with evm errors.
// Here if there is a consensus error - we'd bail. If the tx fails at max gas - we'd bail (probably bad)
if err != nil {
return 0, gethcommon.Big0, err
}
if isFailedAtMax {
return 0, gethcommon.Big0, fmt.Errorf("gas required exceeds allowance (%d)", cap)
}

// Execute the binary search and hone in on an isGasEnough gas limit
for lo+1 < hi {
mid := (hi + lo) / 2
Expand All @@ -208,13 +218,18 @@ func (rpc *EncryptionManager) doEstimateGas(ctx context.Context, args *gethapi.T
// range here is skewed to favor the low side.
mid = lo * 2
}
failed, _, err := rpc.isGasEnough(ctx, args, mid, blkNumber)
failed, _, _ := rpc.isGasEnough(ctx, args, mid, blkNumber)
// TODO @siliev: The following statement is bullshit. I dont know why its here.
// We might have masked our internal workings, or mixed up with how geth works.
// Either way transaction reverted is counted as a consensus error, rather than
// EVM failure.

// If the error is not nil(consensus error), it means the provided message
// call or transaction will never be accepted no matter how much gas it is
// assigned. Return the error directly, don't struggle any more.
if err != nil {
/*if err != nil && isFailedAtMax {
return 0, gethcommon.Big0, err
}
}*/
if failed {
lo = mid
} else {
Expand Down
Loading