Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0aa0 committed Oct 17, 2023
1 parent 94d6c70 commit f20eb2c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ via_ir = false
# Override the Solidity version (this overrides `auto_detect_solc`)
solc_version = '0.8.12'

memory_limit = 1073741824
gas_limit = "18446744073709551615"

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"

Expand Down
2 changes: 1 addition & 1 deletion src/test/ffi/BLSPubKeyCompendiumFFI.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract BLSPublicKeyCompendiumFFITests is G2Operations {
compendium = new BLSPublicKeyCompendium();
}

function testRegisterBLSPublicKey(uint256 _privKey) public {
function xtestRegisterBLSPublicKey(uint256 _privKey) public {
_setKeys(_privKey);

signedMessageHash = _signMessage(alice);
Expand Down
10 changes: 4 additions & 6 deletions src/test/ffi/BLSSignatureCheckerFFI.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ contract BLSSignatureCheckerFFITests is FFIBase {
uint256 setQuorumBitmap;

function setUp() virtual public {
defaultMaxOperatorCount = type(uint32).max;
_deployMockEigenLayerAndAVS();

blsSignatureChecker = new BLSSignatureChecker(registryCoordinator);
}

function testSingleBLSSignatureChecker() public {

uint64 pseudoRandomNumber = 0;
uint64 numOperators = 100;
uint64 numNonSigners = 5;
function xtestSingleBLSSignatureChecker() public {
uint64 pseudoRandomNumber = 1;
uint64 numOperators = 2;
uint64 numNonSigners = 1;
uint64 numQuorums = 1;
uint256 quorumBitmap = 0;

Expand Down
5 changes: 4 additions & 1 deletion src/test/ffi/FFIBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract FFIBase is MockAVSDeployer, G2Operations {
uint32 referenceBlockNumber,
BLSSignatureChecker.NonSignerStakesAndSignature memory nonSignerStakesAndSignature
) {
vm.pauseGasMetering();

nonSignerStakesAndSignature.quorumApks = new BN254.G1Point[](numQuorums);
nonSignerStakesAndSignature.nonSignerPubkeys = new BN254.G1Point[](numNonSigners);
Expand Down Expand Up @@ -49,7 +50,7 @@ contract FFIBase is MockAVSDeployer, G2Operations {
if(setQuorumBitmap > 0){
quorumBitmap = setQuorumBitmap;
} else {
quorumBitmap = privKey & (1 << numQuorums - 1) | 1;
quorumBitmap = privKey & ((1 << numQuorums) - 1) | 1;
if(i < numQuorums) {
quorumBitmap = quorumBitmap | (1 << i);
}
Expand Down Expand Up @@ -95,11 +96,13 @@ contract FFIBase is MockAVSDeployer, G2Operations {
nonSignerStakesAndSignature.totalStakeIndices = checkSignaturesIndices.totalStakeIndices;
nonSignerStakesAndSignature.nonSignerStakeIndices = checkSignaturesIndices.nonSignerStakeIndices;

vm.resumeGasMetering();
return (msgHash, allQuorums, referenceBlockNumber, nonSignerStakesAndSignature);
}

function _setNonSignerPrivKeys(uint256 numNonSigners, uint256 pseudoRandomNumber) internal {
nonSignerPrivateKeys = new uint256[](numNonSigners);

for (uint256 i = 0; i < numNonSigners; i++) {
nonSignerPrivateKeys[i] = uint256(keccak256(abi.encodePacked("nonSignerPrivateKey", pseudoRandomNumber, i))) % BN254.FR_MODULUS;
uint256 j = 0;
Expand Down
44 changes: 36 additions & 8 deletions src/test/ffi/OperatorCapAnalysisFFI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,39 @@ pragma solidity =0.8.12;
import "./FFIBase.sol";
import "./util/BLSSigCheckerExperimental.sol";

//memory_limit = 1073741824
//gas_limit = "18446744073709551615"
contract OperatorCapAnalysisFFI is FFIBase {
using BN254 for BN254.G1Point;

BLSSigCheckerExperimental blsSignatureChecker;

function testOneQuorumLinearNonSigningCost() public {
for(uint64 i = 0; i < 10; i++) {
_deployMockEigenLayerAndAVS();
defaultMaxOperatorCount = type(uint32).max;
blsSignatureChecker = new BLSSigCheckerExperimental(registryCoordinator);
_compareScalarMuls(i, 10, i, 1, 1);
}
function xtestLoopedScalarMulComparison() public {
for(uint64 i = 1; i < 193; i++) {
_compareScalarMuls(
1,
2,
1,
i,
(1 << i) - 1
);
}
}

function testSingleScalarMulComparison() public {
uint64 pseudoRandomNumber = 1;
uint64 numOperators = 100;
uint64 numNonSigners = 99;
uint64 numQuorums = 2;
uint256 quorumBitmap = (1 << numQuorums) - 1;

_compareScalarMuls(
pseudoRandomNumber,
numOperators,
numNonSigners,
numQuorums,
quorumBitmap
);
}

function _compareScalarMuls(
Expand All @@ -24,8 +45,13 @@ contract OperatorCapAnalysisFFI is FFIBase {
uint64 numNonSigners,
uint64 numQuorums,
uint256 setQuorumBitmap
) internal {
) internal returns (uint256) {
_deployMockEigenLayerAndAVS();
blsSignatureChecker = new BLSSigCheckerExperimental(registryCoordinator);

vm.pauseGasMetering();
_setNonSignerPrivKeys(numNonSigners, pseudoRandomNumber);
vm.resumeGasMetering();

(
bytes32 msgHash,
Expand Down Expand Up @@ -68,8 +94,10 @@ contract OperatorCapAnalysisFFI is FFIBase {

if(tinyCost < regCost){
emit log_named_uint("-", regCost - tinyCost);
return(tinyCost);
} else {
emit log_named_uint("+", tinyCost - regCost);
return(regCost);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/utils/MockAVSDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract MockAVSDeployer is Test {
uint96 defaultStake = 1 ether;
uint8 defaultQuorumNumber = 0;

uint32 defaultMaxOperatorCount = 10;
uint32 defaultMaxOperatorCount = type(uint32).max;
uint16 defaultKickBIPsOfOperatorStake = 15000;
uint16 defaultKickBIPsOfTotalStake = 150;
uint8 numQuorums = 192;
Expand Down

0 comments on commit f20eb2c

Please sign in to comment.