Created
August 8, 2024 07:23
-
-
Save m-waqas88/74495ad5f649020981b0a70cc813ccdf to your computer and use it in GitHub Desktop.
Implementation of Dual Proxy Chain call, mocking Minimal Proxy and UUPS Proxy. This is just for testing and understanding the logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
import {Test, console} from "forge-std/Test.sol"; | |
contract MinimalProxyClone { | |
uint256 public a = 10; | |
UUPSProxy public uupsProxy; | |
address public immutable uupsProxyAsImplementation; | |
constructor() { | |
uupsProxy = new UUPSProxy(); | |
uupsProxyAsImplementation = address(uupsProxy); | |
} | |
fallback() external { | |
console.log("Value of a in Minial Proxy before delegatecall", a); | |
(bool success, bytes memory result) = uupsProxyAsImplementation.delegatecall(msg.data); | |
require(success, "Call failed in proxy 1"); | |
console.log("Value of a in Minimal Proxy after delegatecall", a); | |
} | |
} | |
contract UUPSProxy { | |
uint256 public a = 20; | |
Implementation public implementation; | |
address public immutable implementationAddress; | |
constructor() { | |
implementation = new Implementation(); | |
implementationAddress = address(implementation); | |
} | |
fallback() external { | |
console.log("Value of a in UUPS Proxy before delegatecall", a); | |
(bool success, bytes memory result) = implementationAddress.delegatecall(msg.data); | |
require(success, "Call failed in proxy 2"); | |
console.log("Value of a in UUPS Proxy after delegatecall", a); | |
} | |
} | |
contract Implementation { | |
uint256 public a = 40; | |
function setA() public { | |
console.log("Value of a in Implementation before setting", a); | |
a = 30; | |
console.log("Value of a in Implementation after setting", a); | |
} | |
} | |
contract Test2LevelDelegateCalls is Test { | |
MinimalProxyClone public minimalProxyClone; | |
function setUp() public { | |
minimalProxyClone = new MinimalProxyClone(); | |
} | |
function test_analyzeDelegateCall() public { | |
address user = makeAddr("user"); | |
vm.startPrank(user); | |
bytes memory data = abi.encodeWithSignature("setA()"); | |
(bool success, bytes memory result) = address(minimalProxyClone).call(data); | |
require(success, "Call failed"); | |
vm.stopPrank(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment