Skip to content

Commit

Permalink
fix: prevent clone of clone (#301)
Browse files Browse the repository at this point in the history
* fix: prevent clone of clone

* fix: prettier
  • Loading branch information
Steffel authored Apr 29, 2021
1 parent 5ec436b commit 7acbb4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contracts/BaseStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ abstract contract BaseStrategy {
}

abstract contract BaseStrategyInitializable is BaseStrategy {
bool public isOriginal = true;
event Cloned(address indexed clone);

constructor(address _vault) public BaseStrategy(_vault) {}
Expand All @@ -856,6 +857,7 @@ abstract contract BaseStrategyInitializable is BaseStrategy {
}

function clone(address _vault) external returns (address) {
require(isOriginal, "!clone");
return this.clone(_vault, msg.sender, msg.sender, msg.sender);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/AffiliateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract AffiliateToken is ERC20, BaseWrapper {

function deposit(uint256 amount) public returns (uint256 deposited) {
deposited = _deposit(msg.sender, address(this), amount, true); // `true` = pull from `msg.sender`
uint256 shares = _sharesForValue(deposited); // NOTE: Must be calculated after deposit is handled
uint256 shares = _sharesForValue(deposited); // NOTE: Must be calculated after deposit is handled
_mint(msg.sender, shares);
}

Expand Down
20 changes: 20 additions & 0 deletions tests/functional/strategy/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ def other_vault(gov, Vault, other_token):
yield vault


@pytest.fixture
def strategy(gov, strategist, keeper, rewards, vault, TestStrategy):
strategy = strategist.deploy(TestStrategy, vault)

strategy.setKeeper(keeper, {"from": strategist})
vault.addStrategy(
strategy,
4_000, # 40% of Vault
0, # Minimum debt increase per harvest
2 ** 256 - 1, # maximum debt increase per harvest
1000, # 10% performance fee for Strategist
{"from": gov},
)
yield strategy


def test_clone(
Token,
token,
Expand Down Expand Up @@ -43,6 +59,10 @@ def test_clone(
address = tx.events["Cloned"]["clone"]
new_strategy = TestStrategy.at(address)

assert new_strategy.isOriginal() == False
with brownie.reverts():
new_strategy.clone(other_vault, {"from": rando})

assert new_strategy.strategist() == gov
assert new_strategy.rewards() == guardian
assert new_strategy.keeper() == strategist
Expand Down

0 comments on commit 7acbb4f

Please sign in to comment.