Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kaiax/auction: Introduce auction module #288

Open
wants to merge 14 commits into
base: feat/gasless-auction
Choose a base branch
from

Conversation

hyeonLewis
Copy link
Contributor

Proposed changes

This PR introduces kaiax/auction module for the implementation of KIP-249.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@hyeonLewis hyeonLewis self-assigned this Mar 18, 2025
@hyeonLewis hyeonLewis force-pushed the feat/auction branch 9 times, most recently from 58e8bb8 to 8c98bed Compare March 20, 2025 03:45
@hyeonLewis
Copy link
Contributor Author

@hyunsooda As this PR becomes too large, I think merging this first would be better. If it's ok, please let me know. Thanks.

@hyeonLewis hyeonLewis changed the title [WIP] kaiax/auction: Implement auction module [WIP] kaiax/auction: Introduce auction module Mar 20, 2025
@hyeonLewis hyeonLewis force-pushed the feat/auction branch 2 times, most recently from 496b11b to 7dc1490 Compare March 20, 2025 12:26
@hyeonLewis hyeonLewis marked this pull request as ready for review March 21, 2025 08:42
@hyeonLewis hyeonLewis changed the title [WIP] kaiax/auction: Introduce auction module kaiax/auction: Introduce auction module Mar 21, 2025
@hyeonLewis hyeonLewis requested a review from hyunsooda March 21, 2025 08:43
@hyeonLewis hyeonLewis changed the base branch from feat/auction to feat/gasless-auction March 24, 2025 01:58
Comment on lines 34 to 39
ret, err := caller.Auctioneer(opts)
if err != nil {
return common.Address{}, err
}

return ret, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret, err := caller.Auctioneer(opts)
if err != nil {
return common.Address{}, err
}
return ret, nil
return caller.Auctioneer(opts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. fb4a6d1

@@ -293,6 +293,10 @@ func (tx *Transaction) setDecoded(inner TxInternalData, size int) {
}
}

func (tx *Transaction) UpdateTime() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would SetTime be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. fb4a6d1

@@ -0,0 +1,220 @@
// Copyright 2025 The Kaia Authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think separating the EIP712 logic and bid functionality into two files would make it more concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. e0d2854

Comment on lines 170 to 220
func (b *Bid) ValidateSearcherSig(chainId *big.Int, verifyingContract common.Address) error {
if chainId == nil {
return errors.New("chainId is nil")
}

if verifyingContract == (common.Address{}) {
return errors.New("verifyingContract is empty")
}

digest := b.GetHashTypedData(chainId, verifyingContract)

// Manually convert V from 27/28 to 0/1
sig := slices.Clone(b.SearcherSig)
if sig[crypto.RecoveryIDOffset] == 27 || sig[crypto.RecoveryIDOffset] == 28 {
sig[crypto.RecoveryIDOffset] -= 27
}

pub, err := crypto.SigToPub(digest, sig)
if err != nil {
return fmt.Errorf("failed to recover searcher sig: %v", err)
}

recoveredSender := crypto.PubkeyToAddress(*pub)
if recoveredSender != b.Sender {
return fmt.Errorf("invalid searcher sig: expected %v, calculated %v", b.Sender, recoveredSender)
}

return nil
}

func (b *Bid) ValidateAuctioneerSig(auctioneer common.Address) error {
digest := b.GetEthSignedMessageHash()

// Manually convert V from 27/28 to 0/1
sig := slices.Clone(b.AuctioneerSig)
if sig[crypto.RecoveryIDOffset] == 27 || sig[crypto.RecoveryIDOffset] == 28 {
sig[crypto.RecoveryIDOffset] -= 27
}

pub, err := crypto.SigToPub(digest, sig)
if err != nil {
return fmt.Errorf("failed to recover auctioneer sig: %v", err)
}

recoveredAuctioneer := crypto.PubkeyToAddress(*pub)
if recoveredAuctioneer != auctioneer {
return fmt.Errorf("invalid auctioneer sig: expected %v, calculated %v", auctioneer, recoveredAuctioneer)
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract recovering the sender's address into another function and call it to make it more concise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect function like CheckRecoveredAddress(pubKey, expectedAddr) bool?

Comment on lines 172 to 176
return errors.New("chainId is nil")
}

if verifyingContract == (common.Address{}) {
return errors.New("verifyingContract is empty")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two errors can be moved to errors.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. fb4a6d1

return bp
}

func (bp *BidPool) SubscribeNewBid(sink chan<- *auction.Bid) event.Subscription {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you expect where this function is utilized in future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be used in protocol manger to broadcast new bids.


if i == 0 {
// if first transaction exceeds deadline, remove the address
delete(txs, addr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we remove it after all iteration?
Q: Is it assumed that txs are ordered in time ascending? TransactionsByPriceAndNonce may not guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the time-ordered one, but enough with nonce-ordered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants