Skip to content

Commit

Permalink
some rfks, added audit
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Dec 21, 2024
1 parent 0982072 commit 4808f41
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 346 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coverage/
!/broadcast
/broadcast/*/31337/
/broadcast/*/84532/
!/broadcast/*/84532/run-latest.json
/broadcast/**/dry-run/

# Forge files
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"editor.defaultFormatter": "JuanBlanco.solidity"
},
"solidity.formatter": "forge",
"solidity.compileUsingRemoteVersion": "v0.8.26"
"solidity.compileUsingRemoteVersion": "v0.8.26",
"solidity.defaultCompiler": "localFile"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ To interact with the contracts, you need the contract ABIs. We store the ABIs un
./export-abis.sh
```

### Upgrade Contract

Upgrading an existing contract is done as per the instructions in [openzeppelin-foundry-upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) repository.
The `--sender <ADDRESS>` field is required when deploying a contract,

## Testing & Diagnostics

Run tests on local network:
Expand Down
24 changes: 24 additions & 0 deletions abis/parseAbi.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require("fs");

if (process.argv.length < 3) {
console.error("Please provide a filename as a parameter.");
process.exit(1);
}

const filename = process.argv[2];

const data = fs.readFileSync(filename, "utf8");
try {
const jsonData = JSON.parse(data);
const abi = jsonData.abi;
if (!abi) {
console.error("No `abi` field found in the JSON data.");
process.exit(1);
}

fs.writeFileSync(filename, JSON.stringify(abi, null, 2));
console.log("ABI extracted and written to", filename);
} catch (parseErr) {
console.error(`Error parsing JSON: ${parseErr}`);
process.exit(1);
}
37 changes: 0 additions & 37 deletions abis/parseAbi.js

This file was deleted.

Binary file added audits/CodeHawks-28-11-2024.pdf
Binary file not shown.
292 changes: 0 additions & 292 deletions broadcast/Deploy.s.sol/84532/run-1733034620.json

This file was deleted.

4 changes: 2 additions & 2 deletions export-abis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
forge compile

cp ./out/LLMOracleCoordinator.sol/LLMOracleCoordinator.json ./abis/LLMOracleCoordinator.json
node ./abis/parseAbi.js ./abis/LLMOracleCoordinator.json
node ./abis/parseAbi.cjs ./abis/LLMOracleCoordinator.json

cp ./out/LLMOracleRegistry.sol/LLMOracleRegistry.json ./abis/LLMOracleRegistry.json
node ./abis/parseAbi.js ./abis/LLMOracleRegistry.json
node ./abis/parseAbi.cjs ./abis/LLMOracleRegistry.json
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 3 files
+1 −1 package.json
+16 −10 src/Vm.sol
+1 −1 test/Vm.t.sol
56 changes: 49 additions & 7 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {Upgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {Upgrades, UnsafeUpgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Script} from "forge-std/Script.sol";
import {Vm} from "forge-std/Vm.sol";
Expand Down Expand Up @@ -32,13 +32,13 @@ contract DeployLLMOracleRegistry is Script {

function run() external returns (address proxy, address impl) {
vm.startBroadcast();
(proxy, impl) = this.deployProxy();
(proxy, impl) = this.deploy();
vm.stopBroadcast();

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

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

impl = Upgrades.getImplementationAddress(proxy);
}

function deployUnsafe(address impl) external returns (address proxy) {
proxy = UnsafeUpgrades.deployUUPSProxy(
impl,
abi.encodeCall(
LLMOracleRegistry.initialize, (stakes.generator, stakes.validator, token, minRegistrationTimeSec)
)
);
}
}

contract DeployLLMOracleCoordinator is Script {
Expand All @@ -74,8 +83,6 @@ contract DeployLLMOracleCoordinator is Script {
}

function run() external returns (address proxy, address impl) {
helper = new Helper();

// read registry address
string memory deployments = helper.getDeploymentsJson();
require(vm.keyExistsJson(deployments, "$.LLMOracleRegistry"), "Please deploy LLMOracleRegistry first");
Expand All @@ -85,13 +92,13 @@ contract DeployLLMOracleCoordinator is Script {
require(registryImlp != address(0), "LLMOracleRegistry implementation address is invalid");

vm.startBroadcast();
(proxy, impl) = this.deployProxy(registryProxy);
(proxy, impl) = this.deploy(registryProxy);
vm.stopBroadcast();

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

function deployProxy(address registryAddr) external returns (address proxy, address impl) {
function deploy(address registryAddr) external returns (address proxy, address impl) {
proxy = Upgrades.deployUUPSProxy(
"LLMOracleCoordinator.sol",
abi.encodeCall(
Expand All @@ -103,3 +110,38 @@ contract DeployLLMOracleCoordinator is Script {
impl = Upgrades.getImplementationAddress(proxy);
}
}

contract UpgradeLLMOracleRegistry is Script {
Helper public helper;
Stakes public stakes;
uint256 public minRegistrationTimeSec;
address public token;

constructor() {
helper = new Helper();

// parameters
minRegistrationTimeSec = 1 days;
stakes = Stakes({generator: 0.0001 ether, validator: 0.000001 ether});
token = address(0x4200000000000000000000000000000000000006); // WETH
}

function run() external returns (address proxy, address impl) {
vm.startBroadcast();
(proxy, impl) = this.deploy();
vm.stopBroadcast();

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

function deploy() external returns (address proxy, address impl) {
proxy = Upgrades.deployUUPSProxy(
"LLMOracleRegistry.sol",
abi.encodeCall(
LLMOracleRegistry.initialize, (stakes.generator, stakes.validator, token, minRegistrationTimeSec)
)
);

impl = Upgrades.getImplementationAddress(proxy);
}
}
6 changes: 3 additions & 3 deletions test/Statistics.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ contract StatisticsTest is Test {
data[3] = number4;

uint256 average = Statistics.avg(data);
console.log("Average: ", average);
// console.log("Average: ", average);
}

function testFuzz_Variance(uint8 number1, uint8 number2, uint8 number3, uint8 number4, uint8 number5)
Expand All @@ -132,7 +132,7 @@ contract StatisticsTest is Test {
data[4] = number5;

(uint256 variance,) = Statistics.variance(data);
console.log("Variance: ", variance);
// console.log("Variance: ", variance);
}

function testFuzz_StandardDeviation(
Expand Down Expand Up @@ -171,6 +171,6 @@ contract StatisticsTest is Test {
data[9] = number10;

(uint256 stddev,) = Statistics.stddev(data);
console.log("Standard Deviation: ", stddev);
// console.log("Standard Deviation: ", stddev);
}
}
6 changes: 3 additions & 3 deletions test/script/Deploy.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {Upgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {UnsafeUpgrades} from "@openzeppelin/foundry-upgrades/Upgrades.sol";
import {Test} from "forge-std/Test.sol";
import {Vm} from "forge-std/Vm.sol";
import {Helper} from "../../script/Helper.s.sol";
Expand Down Expand Up @@ -37,8 +37,8 @@ contract DeployTest is Test {
require(llmOracleCoordinatorImpl != address(0), "LLMOracleCoordinator implementation not deployed");

// check if implementations are correct
address expectedRegistryImpl = Upgrades.getImplementationAddress(llmOracleRegistryProxy);
address expectedCoordinatorImpl = Upgrades.getImplementationAddress(llmOracleCoordinatorProxy);
address expectedRegistryImpl = UnsafeUpgrades.getImplementationAddress(llmOracleRegistryProxy);
address expectedCoordinatorImpl = UnsafeUpgrades.getImplementationAddress(llmOracleCoordinatorProxy);

require(llmOracleRegistryImpl == expectedRegistryImpl, "LLMOracleRegistry implementation mismatch");
require(llmOracleCoordinatorImpl == expectedCoordinatorImpl, "LLMOracleCoordinator implementation mismatch");
Expand Down

0 comments on commit 4808f41

Please sign in to comment.