Skip to content

Commit

Permalink
Merge pull request #119 from axieinfinity/feature/misc
Browse files Browse the repository at this point in the history
feat: add code hash check in _upgradeRaw and minor enhancement
  • Loading branch information
TuDo1403 authored Mar 1, 2024
2 parents 3ea3b21 + a1ff64c commit c4e4a14
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion script/ArtifactFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract ArtifactFactory is IArtifactFactory {
).green(),
string.concat("(nonce: ", nonce.toString(), ")")
);
if (!CONFIG.getRuntimeConfig().log || CONFIG.isPostChecking()) {
if (!CONFIG.getRuntimeConfig().generateArtifact || CONFIG.isPostChecking()) {
console.log("Skipping artifact generation for:", vm.getLabel(contractAddr), "\n");
return;
}
Expand Down
15 changes: 14 additions & 1 deletion script/BaseMigration.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import {
TransparentUpgradeableProxy
} from "../lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import { LibString } from "../lib/solady/src/utils/LibString.sol";
import { console, LibSharedAddress, StdStyle, IScriptExtended, ScriptExtended } from "./extensions/ScriptExtended.s.sol";
import {
console,
StdStyle,
stdStorage,
StdStorage,
ScriptExtended,
IScriptExtended,
LibSharedAddress
} from "./extensions/ScriptExtended.s.sol";
import { IArtifactFactory, ArtifactFactory } from "./ArtifactFactory.sol";
import { OnchainExecutor } from "./OnchainExecutor.s.sol"; // cheat to load artifact to parent `out` directory
import { IMigrationScript } from "./interfaces/IMigrationScript.sol";
Expand Down Expand Up @@ -244,6 +252,11 @@ abstract contract BaseMigration is ScriptExtended {
}

function _upgradeRaw(address proxyAdmin, address payable proxy, address logic, bytes memory args) internal virtual {
if (logic.codehash == payable(proxyAdmin).getProxyImplementation({ nullCheck: true }).codehash) {
console.log("BaseMigration: Logic is already upgraded!".yellow());
return;
}

ITransparentUpgradeableProxy iProxy = ITransparentUpgradeableProxy(proxy);
ProxyAdmin wProxyAdmin = ProxyAdmin(proxyAdmin);

Expand Down
4 changes: 4 additions & 0 deletions script/configs/NetworkConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ abstract contract NetworkConfig is INetworkConfig {
_isForkModeEnabled = shouldEnable;
}

function getNetworkData(TNetwork network) public view virtual returns (NetworkData memory) {
return _networkDataMap[network];
}

function getDeploymentDirectory(TNetwork network) public view virtual returns (string memory dirPath) {
string memory dirName = _networkDataMap[network].deploymentDir;
require(bytes(dirName).length != 0, "NetworkConfig: Deployment directory not found");
Expand Down
8 changes: 8 additions & 0 deletions script/extensions/ScriptExtended.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.19;

import { StdStyle } from "../../lib/forge-std/src/StdStyle.sol";
import { console, Script } from "../../lib/forge-std/src/Script.sol";
import { stdStorage, StdStorage } from "../../lib/forge-std/src/StdStorage.sol";
import { StdAssertions } from "../../lib/forge-std/src/StdAssertions.sol";
import { IGeneralConfig } from "../interfaces/IGeneralConfig.sol";
import { TNetwork, IScriptExtended } from "../interfaces/IScriptExtended.sol";
Expand All @@ -11,6 +12,7 @@ import { LibSharedAddress } from "../libraries/LibSharedAddress.sol";
import { TContract } from "../types/Types.sol";

abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
using StdStyle for *;
using LibErrorHandler for bool;

bytes public constant EMPTY_ARGS = "";
Expand Down Expand Up @@ -50,6 +52,12 @@ abstract contract ScriptExtended is Script, StdAssertions, IScriptExtended {
(bool success, bytes memory data) = address(this).delegatecall(callData);
success.handleRevert(msg.sig, data);

if (CONFIG.getRuntimeConfig().disablePostcheck) {
console.log("\nPostchecking is disabled.".yellow());
return;
}

console.log("\n>> Postchecking...".yellow());
CONFIG.setPostCheckingStatus({ status: true });
_postCheck();
CONFIG.setPostCheckingStatus({ status: false });
Expand Down
2 changes: 2 additions & 0 deletions script/interfaces/configs/INetworkConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface INetworkConfig {

function getExplorer(TNetwork network) external view returns (string memory link);

function getNetworkData(TNetwork network) external view returns (NetworkData memory);

function getForkId(TNetwork network) external view returns (uint256 forkId);

function getAlias(TNetwork network) external view returns (string memory networkAlias);
Expand Down

0 comments on commit c4e4a14

Please sign in to comment.