Skip to content

Commit 4808f41

Browse files
committed
some rfks, added audit
1 parent 0982072 commit 4808f41

File tree

12 files changed

+90
-346
lines changed

12 files changed

+90
-346
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ coverage/
99
!/broadcast
1010
/broadcast/*/31337/
1111
/broadcast/*/84532/
12+
!/broadcast/*/84532/run-latest.json
1213
/broadcast/**/dry-run/
1314

1415
# Forge files

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"editor.defaultFormatter": "JuanBlanco.solidity"
77
},
88
"solidity.formatter": "forge",
9-
"solidity.compileUsingRemoteVersion": "v0.8.26"
9+
"solidity.compileUsingRemoteVersion": "v0.8.26",
10+
"solidity.defaultCompiler": "localFile"
1011
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ To interact with the contracts, you need the contract ABIs. We store the ABIs un
158158
./export-abis.sh
159159
```
160160

161+
### Upgrade Contract
162+
163+
Upgrading an existing contract is done as per the instructions in [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) repository.
164+
The `--sender <ADDRESS>` field is required when deploying a contract,
165+
161166
## Testing & Diagnostics
162167

163168
Run tests on local network:

abis/parseAbi.cjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require("fs");
2+
3+
if (process.argv.length < 3) {
4+
console.error("Please provide a filename as a parameter.");
5+
process.exit(1);
6+
}
7+
8+
const filename = process.argv[2];
9+
10+
const data = fs.readFileSync(filename, "utf8");
11+
try {
12+
const jsonData = JSON.parse(data);
13+
const abi = jsonData.abi;
14+
if (!abi) {
15+
console.error("No `abi` field found in the JSON data.");
16+
process.exit(1);
17+
}
18+
19+
fs.writeFileSync(filename, JSON.stringify(abi, null, 2));
20+
console.log("ABI extracted and written to", filename);
21+
} catch (parseErr) {
22+
console.error(`Error parsing JSON: ${parseErr}`);
23+
process.exit(1);
24+
}

abis/parseAbi.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

audits/CodeHawks-28-11-2024.pdf

321 KB
Binary file not shown.

broadcast/Deploy.s.sol/84532/run-1733034620.json

Lines changed: 0 additions & 292 deletions
This file was deleted.

export-abis.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
forge compile
33

44
cp ./out/LLMOracleCoordinator.sol/LLMOracleCoordinator.json ./abis/LLMOracleCoordinator.json
5-
node ./abis/parseAbi.js ./abis/LLMOracleCoordinator.json
5+
node ./abis/parseAbi.cjs ./abis/LLMOracleCoordinator.json
66

77
cp ./out/LLMOracleRegistry.sol/LLMOracleRegistry.json ./abis/LLMOracleRegistry.json
8-
node ./abis/parseAbi.js ./abis/LLMOracleRegistry.json
8+
node ./abis/parseAbi.cjs ./abis/LLMOracleRegistry.json

lib/forge-std

script/Deploy.s.sol

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {Upgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
4+
import {Upgrades, UnsafeUpgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
55
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
66
import {Script} from "forge-std/Script.sol";
77
import {Vm} from "forge-std/Vm.sol";
@@ -32,13 +32,13 @@ contract DeployLLMOracleRegistry is Script {
3232

3333
function run() external returns (address proxy, address impl) {
3434
vm.startBroadcast();
35-
(proxy, impl) = this.deployProxy();
35+
(proxy, impl) = this.deploy();
3636
vm.stopBroadcast();
3737

3838
helper.writeProxyAddresses("LLMOracleRegistry", proxy, impl);
3939
}
4040

41-
function deployProxy() external returns (address proxy, address impl) {
41+
function deploy() external returns (address proxy, address impl) {
4242
proxy = Upgrades.deployUUPSProxy(
4343
"LLMOracleRegistry.sol",
4444
abi.encodeCall(
@@ -48,6 +48,15 @@ contract DeployLLMOracleRegistry is Script {
4848

4949
impl = Upgrades.getImplementationAddress(proxy);
5050
}
51+
52+
function deployUnsafe(address impl) external returns (address proxy) {
53+
proxy = UnsafeUpgrades.deployUUPSProxy(
54+
impl,
55+
abi.encodeCall(
56+
LLMOracleRegistry.initialize, (stakes.generator, stakes.validator, token, minRegistrationTimeSec)
57+
)
58+
);
59+
}
5160
}
5261

5362
contract DeployLLMOracleCoordinator is Script {
@@ -74,8 +83,6 @@ contract DeployLLMOracleCoordinator is Script {
7483
}
7584

7685
function run() external returns (address proxy, address impl) {
77-
helper = new Helper();
78-
7986
// read registry address
8087
string memory deployments = helper.getDeploymentsJson();
8188
require(vm.keyExistsJson(deployments, "$.LLMOracleRegistry"), "Please deploy LLMOracleRegistry first");
@@ -85,13 +92,13 @@ contract DeployLLMOracleCoordinator is Script {
8592
require(registryImlp != address(0), "LLMOracleRegistry implementation address is invalid");
8693

8794
vm.startBroadcast();
88-
(proxy, impl) = this.deployProxy(registryProxy);
95+
(proxy, impl) = this.deploy(registryProxy);
8996
vm.stopBroadcast();
9097

9198
helper.writeProxyAddresses("LLMOracleCoordinator", proxy, impl);
9299
}
93100

94-
function deployProxy(address registryAddr) external returns (address proxy, address impl) {
101+
function deploy(address registryAddr) external returns (address proxy, address impl) {
95102
proxy = Upgrades.deployUUPSProxy(
96103
"LLMOracleCoordinator.sol",
97104
abi.encodeCall(
@@ -103,3 +110,38 @@ contract DeployLLMOracleCoordinator is Script {
103110
impl = Upgrades.getImplementationAddress(proxy);
104111
}
105112
}
113+
114+
contract UpgradeLLMOracleRegistry is Script {
115+
Helper public helper;
116+
Stakes public stakes;
117+
uint256 public minRegistrationTimeSec;
118+
address public token;
119+
120+
constructor() {
121+
helper = new Helper();
122+
123+
// parameters
124+
minRegistrationTimeSec = 1 days;
125+
stakes = Stakes({generator: 0.0001 ether, validator: 0.000001 ether});
126+
token = address(0x4200000000000000000000000000000000000006); // WETH
127+
}
128+
129+
function run() external returns (address proxy, address impl) {
130+
vm.startBroadcast();
131+
(proxy, impl) = this.deploy();
132+
vm.stopBroadcast();
133+
134+
helper.writeProxyAddresses("LLMOracleRegistry", proxy, impl);
135+
}
136+
137+
function deploy() external returns (address proxy, address impl) {
138+
proxy = Upgrades.deployUUPSProxy(
139+
"LLMOracleRegistry.sol",
140+
abi.encodeCall(
141+
LLMOracleRegistry.initialize, (stakes.generator, stakes.validator, token, minRegistrationTimeSec)
142+
)
143+
);
144+
145+
impl = Upgrades.getImplementationAddress(proxy);
146+
}
147+
}

0 commit comments

Comments
 (0)