From b399491b7313e9b45dc32a4c6486a668346f3896 Mon Sep 17 00:00:00 2001 From: Mikhail Wall Date: Tue, 28 Jan 2025 22:04:53 +0100 Subject: [PATCH] fix: fixed lint --- contracts/contracts/core/PreconfManager.sol | 82 +++++++++---------- oracle/pkg/updater/updater_test.go | 19 ----- p2p/pkg/keysstore/keysstore.go | 2 +- .../preconfirmation/tracker/tracker_test.go | 12 +-- 4 files changed, 44 insertions(+), 71 deletions(-) diff --git a/contracts/contracts/core/PreconfManager.sol b/contracts/contracts/core/PreconfManager.sol index 078cf9180..5c7e1579b 100644 --- a/contracts/contracts/core/PreconfManager.sol +++ b/contracts/contracts/core/PreconfManager.sol @@ -49,9 +49,9 @@ contract PreconfManager is // zk proof related contstants bytes32 public constant ZK_CONTEXT_HASH = keccak256("mev-commit opening, mainnet, v1.0"); - uint256 constant GX = 1; - uint256 constant GY = 2; - uint256 constant BN254_MASK_253 = (1 << 253) - 1; + uint256 private constant _GX = 1; + uint256 private constant _GY = 2; + uint256 private constant _BN254_MASK_253 = (1 << 253) - 1; /** * @dev Makes sure transaction sender is oracle contract @@ -246,11 +246,7 @@ contract PreconfManager is TxnHashAlreadyProcessed(txnHash, bidderAddress) ); - bytes32 commitmentDigest = getPreConfHash( - bHash, - bidSignature, - zkProof - ); + bytes32 commitmentDigest = getPreConfHash(bHash, bidSignature, zkProof); UnopenedCommitment storage unopenedCommitment = unopenedCommitments[ unopenedCommitmentIndex @@ -327,34 +323,10 @@ contract PreconfManager is processedTxnHashes[txnHashBidderBlockNumber] = true; - emitOpenedCommitmentStored(commitmentIndex, newCommitment); + _emitOpenedCommitmentStored(commitmentIndex, newCommitment); return commitmentIndex; } - /** - * @dev Emit OpenedCommitmentStored event - * @param commitmentIndex The index of the stored commitment - * @param newCommitment The commitment to be stored - */ - function emitOpenedCommitmentStored( - bytes32 commitmentIndex, - OpenedCommitment memory newCommitment - ) internal { - emit OpenedCommitmentStored( - commitmentIndex, - newCommitment.bidder, - newCommitment.committer, - newCommitment.bidAmt, - newCommitment.blockNumber, - newCommitment.decayStartTimeStamp, - newCommitment.decayEndTimeStamp, - newCommitment.txnHash, - newCommitment.revertingTxHashes, - newCommitment.commitmentDigest, - newCommitment.dispatchTimestamp - ); - } - /** * @dev Store an unopened commitment. * @param commitmentDigest The digest of the commitment. @@ -660,6 +632,30 @@ contract PreconfManager is ); } + /** + * @dev Emit OpenedCommitmentStored event + * @param commitmentIndex The index of the stored commitment + * @param newCommitment The commitment to be stored + */ + function _emitOpenedCommitmentStored( + bytes32 commitmentIndex, + OpenedCommitment memory newCommitment + ) internal { + emit OpenedCommitmentStored( + commitmentIndex, + newCommitment.bidder, + newCommitment.committer, + newCommitment.bidAmt, + newCommitment.blockNumber, + newCommitment.decayStartTimeStamp, + newCommitment.decayEndTimeStamp, + newCommitment.txnHash, + newCommitment.revertingTxHashes, + newCommitment.commitmentDigest, + newCommitment.dispatchTimestamp + ); + } + // solhint-disable-next-line no-empty-blocks function _authorizeUpgrade(address) internal override onlyOwner {} @@ -667,11 +663,7 @@ contract PreconfManager is CommitmentParams calldata params ) internal view returns (bytes32) { return - getPreConfHash( - params.bidHash, - params.bidSignature, - params.zkProof - ); + getPreConfHash(params.bidHash, params.bidSignature, params.zkProof); } /** @@ -686,26 +678,26 @@ contract PreconfManager is uint256[] calldata zkProof ) internal view returns (bool) { // 1. Recompute a = g^z * (providerPub)^c - (uint256 gzX, uint256 gzY) = BN128._ecMul(GX, GY, zkProof[7]); - (uint256 AcX, uint256 AcY) = BN128._ecMul( + (uint256 gzX, uint256 gzY) = BN128._ecMul(_GX, _GY, zkProof[7]); + (uint256 acX, uint256 acY) = BN128._ecMul( zkProof[0], zkProof[1], zkProof[6] ); - (uint256 aX, uint256 aY) = BN128._ecAdd(gzX, gzY, AcX, AcY); + (uint256 aX, uint256 aY) = BN128._ecAdd(gzX, gzY, acX, acY); // 2. Recompute a' = B^z * C^c - (uint256 BzX, uint256 BzY) = BN128._ecMul( + (uint256 bzX, uint256 bzY) = BN128._ecMul( zkProof[2], zkProof[3], zkProof[7] ); - (uint256 CcX, uint256 CcY) = BN128._ecMul( + (uint256 ccX, uint256 ccY) = BN128._ecMul( zkProof[4], zkProof[5], zkProof[6] ); - (uint256 aX2, uint256 aY2) = BN128._ecAdd(BzX, BzY, CcX, CcY); + (uint256 aX2, uint256 aY2) = BN128._ecAdd(bzX, bzY, ccX, ccY); // 3. Recompute c' by hashing the context + all relevant points bytes32 computedChallenge = keccak256( @@ -726,7 +718,7 @@ contract PreconfManager is // Compare the numeric value of computedChallenge vs the given c uint256 computedChallengeInt = uint256(computedChallenge) & - BN254_MASK_253; + _BN254_MASK_253; return (computedChallengeInt == zkProof[6]); } } diff --git a/oracle/pkg/updater/updater_test.go b/oracle/pkg/updater/updater_test.go index b640c0db6..89673fa94 100644 --- a/oracle/pkg/updater/updater_test.go +++ b/oracle/pkg/updater/updater_test.go @@ -128,12 +128,10 @@ func TestUpdater(t *testing.T) { BidAmt: big.NewInt(10), BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: "", - // SharedSecretKey: []byte("shared_secret_key"), } if i%2 == 0 { @@ -172,12 +170,10 @@ func TestUpdater(t *testing.T) { TxnHash: bundle, BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: "", - // SharedSecretKey: []byte("shared_secret_key"), } unopenedCommitments = append(unopenedCommitments, unopenedCommitment) commitments = append(commitments, commitment) @@ -394,12 +390,10 @@ func TestUpdaterRevertedTxns(t *testing.T) { BidAmt: big.NewInt(10), BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: "", - // SharedSecretKey: []byte("shared_secret_key"), } if i%2 == 0 { @@ -438,12 +432,10 @@ func TestUpdaterRevertedTxns(t *testing.T) { TxnHash: bundle, BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: "", - // SharedSecretKey: []byte("shared_secret_key"), } unopenedCommitments = append(unopenedCommitments, unopenedCommitment) commitments = append(commitments, commitment) @@ -667,12 +659,10 @@ func TestUpdaterRevertedTxnsWithRevertingHashes(t *testing.T) { BidAmt: big.NewInt(10), BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: strings.TrimPrefix(txn.Hash().Hex(), "0x"), - // SharedSecretKey: []byte("shared_secret_key"), } if i%2 == 0 { @@ -711,12 +701,10 @@ func TestUpdaterRevertedTxnsWithRevertingHashes(t *testing.T) { TxnHash: bundle, BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: bundle, - // SharedSecretKey: []byte("shared_secret_key"), } unopenedCommitments = append(unopenedCommitments, unopenedCommitment) commitments = append(commitments, commitment) @@ -937,12 +925,10 @@ func TestUpdaterBundlesFailure(t *testing.T) { TxnHash: bundle, BlockNumber: 5, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), RevertingTxHashes: "", - // SharedSecretKey: []byte("shared_secret_key"), } commitments = append(commitments, commitment) @@ -1132,7 +1118,6 @@ func TestUpdaterIgnoreCommitments(t *testing.T) { RevertingTxHashes: "", BlockNumber: blockNum, CommitmentDigest: common.HexToHash(fmt.Sprintf("0x%02d", i)), - // CommitmentSignature: []byte("signature"), DecayStartTimeStamp: uint64(startTimestamp.UnixMilli()), DecayEndTimeStamp: uint64(endTimestamp.UnixMilli()), DispatchTimestamp: uint64(midTimestamp.UnixMilli()), @@ -1490,16 +1475,12 @@ func publishOpenedCommitment( c.Committer, c.BidAmt, c.BlockNumber, - // c.BidHash, c.DecayStartTimeStamp, c.DecayEndTimeStamp, c.TxnHash, c.RevertingTxHashes, c.CommitmentDigest, - // c.BidSignature, - // c.CommitmentSignature, c.DispatchTimestamp, - // c.SharedSecretKey, ) if err != nil { return err diff --git a/p2p/pkg/keysstore/keysstore.go b/p2p/pkg/keysstore/keysstore.go index 66308ea8a..94e5670ff 100644 --- a/p2p/pkg/keysstore/keysstore.go +++ b/p2p/pkg/keysstore/keysstore.go @@ -12,8 +12,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/ecies" - "github.com/primev/mev-commit/p2p/pkg/storage" p2pcrypto "github.com/primev/mev-commit/p2p/pkg/crypto" + "github.com/primev/mev-commit/p2p/pkg/storage" ) const ( diff --git a/p2p/pkg/preconfirmation/tracker/tracker_test.go b/p2p/pkg/preconfirmation/tracker/tracker_test.go index 9ad6f62b9..7b66ec564 100644 --- a/p2p/pkg/preconfirmation/tracker/tracker_test.go +++ b/p2p/pkg/preconfirmation/tracker/tracker_test.go @@ -156,17 +156,17 @@ func TestTracker(t *testing.T) { } // this commitment should not be opened again err = publishOpenedCommitment(evtMgr, &pcABI, preconf.PreconfmanagerOpenedCommitmentStored{ - CommitmentIndex: common.HexToHash(fmt.Sprintf("0x%x", 5)), - Bidder: common.HexToAddress("0x1234"), - Committer: common.BytesToAddress(commitments[4].PreConfirmation.ProviderAddress), - BidAmt: amount, - BlockNumber: uint64(commitments[4].PreConfirmation.Bid.BlockNumber), + CommitmentIndex: common.HexToHash(fmt.Sprintf("0x%x", 5)), + Bidder: common.HexToAddress("0x1234"), + Committer: common.BytesToAddress(commitments[4].PreConfirmation.ProviderAddress), + BidAmt: amount, + BlockNumber: uint64(commitments[4].PreConfirmation.Bid.BlockNumber), DecayStartTimeStamp: uint64(commitments[4].PreConfirmation.Bid.DecayStartTimestamp), DecayEndTimeStamp: uint64(commitments[4].PreConfirmation.Bid.DecayEndTimestamp), TxnHash: commitments[4].PreConfirmation.Bid.TxHash, RevertingTxHashes: commitments[4].PreConfirmation.Bid.RevertingTxHashes, CommitmentDigest: common.BytesToHash(commitments[4].PreConfirmation.Digest), - DispatchTimestamp: uint64(1), + DispatchTimestamp: uint64(1), }) if err != nil {