Skip to content

Commit 709b6fc

Browse files
committed
Added tx_origin check
1 parent 2f864a7 commit 709b6fc

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.6.12;
3+
4+
import "../_interfaces/IXCAmpleController.sol";
5+
6+
contract MockConstructorRebaseCallerContract {
7+
constructor(address policy) public {
8+
// Take out a flash loan.
9+
// Do something funky...
10+
IXCAmpleController(policy).rebase(); // should fail
11+
// pay back flash loan.
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.6.12;
3+
4+
import "../_interfaces/IXCAmpleController.sol";
5+
6+
contract MockRebaseCallerContract {
7+
function callRebase(address policy) public returns (bool) {
8+
// Take out a flash loan.
9+
// Do something funky...
10+
IXCAmpleController(policy).rebase(); // should fail
11+
// pay back flash loan.
12+
return true;
13+
}
14+
}

contracts/satellite-chain/xc-ampleforth/XCAmpleController.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ contract XCAmpleController is OwnableUpgradeable {
172172
* on the rebase relayer.
173173
*/
174174
function rebase() external {
175+
require(msg.sender == tx.origin, "XCAmpleController: expected caller to be eoa");
176+
175177
// recently reported epoch needs to be more than current globalEpoch in storage
176178
require(
177179
nextGlobalAmpleforthEpoch > globalAmpleforthEpoch,

test/unit/satellite-chain/xc-ampleforth/xc_controller_rebase.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,31 @@ describe('XCAmpleController:rebase:epoch', async () => {
6969
});
7070
});
7171

72+
describe('XCAmpleController:rebase:called by a contract', function () {
73+
it('should fail', async function () {
74+
await controller.connect(bridge).reportRebase(2, 1000);
75+
const rebaseCallerContract = await (
76+
await ethers.getContractFactory('MockRebaseCallerContract')
77+
)
78+
.connect(deployer)
79+
.deploy();
80+
await expect(
81+
rebaseCallerContract.callRebase(controller.address),
82+
).to.be.revertedWith('XCAmpleController: expected caller to be eoa');
83+
});
84+
});
85+
86+
describe('XCAmpleController:rebase:called by a contract which is being constructed', function () {
87+
it('should fail', async function () {
88+
await controller.connect(bridge).reportRebase(2, 1000);
89+
await expect(
90+
(await ethers.getContractFactory('MockConstructorRebaseCallerContract'))
91+
.connect(deployer)
92+
.deploy(controller.address),
93+
).to.be.revertedWith('XCAmpleController: expected caller to be eoa');
94+
});
95+
});
96+
7297
describe('XCAmpleController:rebase', async () => {
7398
beforeEach('setup XCAmpleController contract', async () => {
7499
await setupContracts();

0 commit comments

Comments
 (0)