Skip to content

Commit

Permalink
fix: fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikelle committed Jan 28, 2025
1 parent dac60fe commit b399491
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 71 deletions.
82 changes: 37 additions & 45 deletions contracts/contracts/core/PreconfManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -660,18 +632,38 @@ 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 {}

function _getPreConfHash(
CommitmentParams calldata params
) internal view returns (bytes32) {
return
getPreConfHash(
params.bidHash,
params.bidSignature,
params.zkProof
);
getPreConfHash(params.bidHash, params.bidSignature, params.zkProof);
}

/**
Expand All @@ -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(
Expand All @@ -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]);
}
}
19 changes: 0 additions & 19 deletions oracle/pkg/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/pkg/keysstore/keysstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
12 changes: 6 additions & 6 deletions p2p/pkg/preconfirmation/tracker/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b399491

Please sign in to comment.