Skip to content

Commit 1c8b8fa

Browse files
committed
poc works
1 parent 188e5a5 commit 1c8b8fa

38 files changed

+1397
-303
lines changed

abi/src/IVictim.sol/IVictim.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "drainedMethod",
5+
"outputs": [],
6+
"stateMutability": "nonpayable",
7+
"type": "function"
8+
}
9+
]

abi/src/LayeredProxy.sol/LayeredProxy.json

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"internalType": "struct LibAccessLayers.LayerStruct[]",
3333
"name": "layers",
3434
"type": "tuple[]"
35+
},
36+
{
37+
"internalType": "address",
38+
"name": "initialImplementation",
39+
"type": "address"
3540
}
3641
],
3742
"stateMutability": "nonpayable",
@@ -104,6 +109,19 @@
104109
"name": "AdminChanged",
105110
"type": "event"
106111
},
112+
{
113+
"anonymous": false,
114+
"inputs": [
115+
{
116+
"indexed": true,
117+
"internalType": "uint256",
118+
"name": "newBalance",
119+
"type": "uint256"
120+
}
121+
],
122+
"name": "BalanceReduced",
123+
"type": "event"
124+
},
107125
{
108126
"anonymous": false,
109127
"inputs": [
@@ -120,5 +138,9 @@
120138
{
121139
"stateMutability": "payable",
122140
"type": "fallback"
141+
},
142+
{
143+
"stateMutability": "payable",
144+
"type": "receive"
123145
}
124146
]

abi/src/SampleLayer.sol/SampleLayer.json abi/src/SampleLayer.sol/RecoverableFuse.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"inputs": [
44
{
55
"internalType": "bytes",
6-
"name": "",
6+
"name": "layerConfig",
77
"type": "bytes"
88
},
99
{
1010
"internalType": "bytes4",
11-
"name": "",
11+
"name": "messageSig",
1212
"type": "bytes4"
1313
},
1414
{
@@ -34,7 +34,7 @@
3434
],
3535
"name": "afterCallValidation",
3636
"outputs": [],
37-
"stateMutability": "nonpayable",
37+
"stateMutability": "view",
3838
"type": "function"
3939
},
4040
{
@@ -46,7 +46,7 @@
4646
},
4747
{
4848
"internalType": "bytes4",
49-
"name": "",
49+
"name": "messageSig",
5050
"type": "bytes4"
5151
},
5252
{

abi/src/mocks/MockERC20.sol/MockERC20.json

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
[
22
{
3-
"inputs": [
4-
{
5-
"internalType": "string",
6-
"name": "name_",
7-
"type": "string"
8-
},
9-
{
10-
"internalType": "string",
11-
"name": "symbol_",
12-
"type": "string"
13-
},
14-
{
15-
"internalType": "address",
16-
"name": "owner",
17-
"type": "address"
18-
}
19-
],
3+
"inputs": [],
204
"stateMutability": "nonpayable",
215
"type": "constructor"
226
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"inputs": [],
4+
"stateMutability": "nonpayable",
5+
"type": "constructor"
6+
},
7+
{
8+
"inputs": [
9+
{
10+
"internalType": "address payable",
11+
"name": "victim",
12+
"type": "address"
13+
},
14+
{
15+
"internalType": "uint256",
16+
"name": "cycles",
17+
"type": "uint256"
18+
}
19+
],
20+
"name": "drain",
21+
"outputs": [],
22+
"stateMutability": "nonpayable",
23+
"type": "function"
24+
}
25+
]

deploy/drainer.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
4+
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
5+
const { deployments, getNamedAccounts } = hre;
6+
const { deploy } = deployments;
7+
8+
const { deployer, owner } = await getNamedAccounts();
9+
10+
await deploy("Drainer", {
11+
from: deployer,
12+
args: [],
13+
skipIfAlreadyDeployed: true,
14+
});
15+
};
16+
17+
export default func;
18+
func.dependencies = ["layer_proxy"];
19+
func.tags = ["poc", "drainer"];

deploy/layered_proxy.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import { LayeredProxy, SampleLayer } from "../types";
3+
import { LayeredProxy, RecoverableFuse } from "../types";
44
import { ethers } from "hardhat";
55
import { LibAccessLayers } from "../types/src/LayeredProxy";
66

@@ -10,11 +10,11 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1010

1111
const { deployer, owner } = await getNamedAccounts();
1212

13-
const simpleLayer = await deployments.get("SampleLayer");
13+
const simpleLayer = await deployments.get("RecoverableFuse");
1414
const simpleLayerContract = (await ethers.getContractAt(
1515
simpleLayer.abi,
1616
simpleLayer.address,
17-
)) as SampleLayer;
17+
)) as RecoverableFuse;
1818

1919
let layer: LibAccessLayers.LayerStructStruct = {
2020
layerAddess: simpleLayer.address,
@@ -28,15 +28,20 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
2828
"afterCallValidation(bytes,bytes4,address,uint256,bytes,bytes)"
2929
],
3030
),
31-
layerConfigData: "",
31+
layerConfigData: ethers.utils.defaultAbiCoder.encode(["uint256"], [10]),
3232
};
3333

34-
const result = await deploy("LayeredProxy", {
34+
const result = await deploy("MockERC20", {
3535
from: deployer,
36-
args: [owner, [layer]],
36+
args: [],
37+
skipIfAlreadyDeployed: true,
38+
});
39+
40+
const lp = await deploy("LayeredProxy", {
41+
from: deployer,
42+
args: [owner, [layer], result.address],
3743
skipIfAlreadyDeployed: true,
3844
});
39-
console.log("deployed at", result.address);
4045
};
4146

4247
export default func;

deploy/simple_layer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
77

88
const { deployer } = await getNamedAccounts();
99

10-
const result = await deploy("SampleLayer", {
10+
await deploy("RecoverableFuse", {
1111
from: deployer,
1212
args: [],
1313
skipIfAlreadyDeployed: true,
1414
});
15-
console.log("deployed at", result.address);
1615
};
1716

1817
export default func;

hardhat.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
token: "MATIC",
2929
gasPriceApi:
3030
"https://api.polygonscan.com/api?module=proxy&action=eth_gasPrice",
31-
enabled: false,
31+
enabled: true,
3232
coinmarketcap: process.env.COINMARKETCAP_KEY,
3333
},
3434
namedAccounts: {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@types/node": "^17.0.36",
7575
"chalk": "^4.1.2",
7676
"cli-table": "^0.3.11",
77-
"hardhat-gas-reporter": "^1.0.9",
77+
"hardhat-gas-reporter": "^2.0.2",
7878
"ts-node": "^10.9.1",
7979
"typescript": "^5.2.2"
8080
}

0 commit comments

Comments
 (0)