Hello everyone, I have one question regarding OpenZeppelin Clones library, so I am planning to make staking factory contract, and use there clones to save gas on deploying new pools, but I have question. What will happen if someone will find master contract and call some functions there? ( for example stake or something else ) would it affect anyway cloned contracts? or cloned contracts are using just functions using delegate call?
Dec 17, 2022, 6:06 PM
if you using the clone library, what happens on the implementation is irrilevant (as long you don't have a public selfDestruct on it, i think it won't work anymore if you call it)
storage will be on the small contract created and all the functions will be taken from the implementation
yep, just tested the self destruct part
also chatGpt says the exact opposite ._.
so i tested it too just to be safu and nope, you can play on the implementation, it won't affect the clones
so i tested it too just to be safu and nope, you can play on the implementation, it won't affect the clones
made a little example if you wanna test it too
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/proxy/Clones.sol";
import "hardhat/console.sol";
interface getNum {
function number() external returns(uint);
}
contract fact {
address implementation;
function setImple(address impl) external {
implementation = impl;
}
function spwanCa() external returns(uint) {
address newCa = Clones.clone(implementation);
console.log(getNum(newCa).number());
console.log(newCa);
return getNum(newCa).number();
}
}
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
pragma solidity ^0.8.7;
contract daprox is Initializable {
uint public number;
function initialize() public initializer {
number = 10;
}
function raiseNumber() external {
require(number<=20,"no");
number += 10;
}
function explode() external {
selfdestruct(payable(msg.sender));
}
}
import "@openzeppelin/contracts/proxy/Clones.sol";
import "hardhat/console.sol";
interface getNum {
function number() external returns(uint);
}
contract fact {
address implementation;
function setImple(address impl) external {
implementation = impl;
}
function spwanCa() external returns(uint) {
address newCa = Clones.clone(implementation);
console.log(getNum(newCa).number());
console.log(newCa);
return getNum(newCa).number();
}
}
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
pragma solidity ^0.8.7;
contract daprox is Initializable {
uint public number;
function initialize() public initializer {
number = 10;
}
function raiseNumber() external {
require(number<=20,"no");
number += 10;
}
function explode() external {
selfdestruct(payable(msg.sender));
}
}
Dec 18, 2022, 12:41 AM