Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Feb 3, 2025
1 parent d7e1bff commit 338ccf0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions test/utils/BN256G2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ library BN256G2 {

function _modInv(uint256 a, uint256 n) internal view returns (uint256 result) {
bool success;
assembly ("memory-safe") {
assembly ("memory-safe") {
let freemem := mload(0x40)
mstore(freemem, 0x20)
mstore(add(freemem, 0x20), 0x20)
Expand Down Expand Up @@ -334,4 +334,4 @@ library BN256G2 {
d = d / 2;
}
}
}
}
14 changes: 10 additions & 4 deletions test/utils/MockAVSDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {BLSApkRegistryHarness} from "../harnesses/BLSApkRegistryHarness.sol";
import {EmptyContract} from "eigenlayer-contracts/src/test/mocks/EmptyContract.sol";

import {StakeRegistryHarness} from "../harnesses/StakeRegistryHarness.sol";
import {OperatorLib} from "../utils/OperatorLib.sol";
import {OperatorWalletLib} from "../utils/OperatorWalletLib.sol";

import "forge-std/Test.sol";

Expand Down Expand Up @@ -549,10 +549,16 @@ contract MockAVSDeployer is Test {
});
}

function _createOperators(uint256 numOperators, uint256 startIndex) internal returns (OperatorLib.Operator[] memory) {
OperatorLib.Operator[] memory operators = new OperatorLib.Operator[](numOperators);
function _createOperators(
uint256 numOperators,
uint256 startIndex
) internal returns (OperatorWalletLib.Operator[] memory) {
OperatorWalletLib.Operator[] memory operators =
new OperatorWalletLib.Operator[](numOperators);
for (uint256 i = 0; i < numOperators; i++) {
operators[i] = OperatorLib.createOperator(string(abi.encodePacked("operator-", i + startIndex)));
operators[i] = OperatorWalletLib.createOperator(
string(abi.encodePacked("operator-", i + startIndex))
);
}
return operators;
}
Expand Down
42 changes: 20 additions & 22 deletions test/utils/OperatorLib.sol → test/utils/OperatorWalletLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {BN254} from "src/libraries/BN254.sol";
import {BN256G2} from "./BN256G2.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

library OperatorLib {
library OperatorWalletLib {
using BN254 for *;
using Strings for uint256;

Expand All @@ -21,47 +21,46 @@ library OperatorLib {
BN254.G1Point publicKeyG1;
}

Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

struct Operator {
Wallet key;
BLSWallet signingKey;
}

function createBLSWallet(uint256 salt) internal returns (BLSWallet memory) {
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

function createBLSWallet(
uint256 salt
) internal returns (BLSWallet memory) {
uint256 privateKey = uint256(keccak256(abi.encodePacked(salt)));
BN254.G1Point memory publicKeyG1 = BN254.generatorG1().scalar_mul(privateKey);
BN254.G2Point memory publicKeyG2 = mul(privateKey);

return BLSWallet({
privateKey: privateKey,
publicKeyG2: publicKeyG2,
publicKeyG1: publicKeyG1
});
return
BLSWallet({privateKey: privateKey, publicKeyG2: publicKeyG2, publicKeyG1: publicKeyG1});
}

function createWallet(uint256 salt) internal pure returns (Wallet memory) {
function createWallet(
uint256 salt
) internal pure returns (Wallet memory) {
uint256 privateKey = uint256(keccak256(abi.encodePacked(salt)));
address addr = vm.addr(privateKey);

return Wallet({
privateKey: privateKey,
addr: addr
});
return Wallet({privateKey: privateKey, addr: addr});
}

function createOperator(string memory name) internal returns (Operator memory) {
function createOperator(
string memory name
) internal returns (Operator memory) {
uint256 salt = uint256(keccak256(abi.encodePacked(name)));
Wallet memory vmWallet = createWallet(salt);
BLSWallet memory blsWallet = createBLSWallet(salt);

return Operator({
key: vmWallet,
signingKey: blsWallet
});
return Operator({key: vmWallet, signingKey: blsWallet});
}

function mul(uint256 x) internal returns (BN254.G2Point memory g2Point) {
function mul(
uint256 x
) internal returns (BN254.G2Point memory g2Point) {
string[] memory inputs = new string[](5);
inputs[0] = "go";
inputs[1] = "run";
Expand All @@ -84,5 +83,4 @@ library OperatorLib {
res = vm.ffi(inputs);
g2Point.Y[0] = abi.decode(res, (uint256));
}

}
}

0 comments on commit 338ccf0

Please sign in to comment.