-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: feat/gasless-auction
Are you sure you want to change the base?
kaiax/auction: Introduce auction module #288
Conversation
58e8bb8
to
8c98bed
Compare
@hyunsooda As this PR becomes too large, I think merging this first would be better. If it's ok, please let me know. Thanks. |
496b11b
to
7dc1490
Compare
760c5ed
to
0bd99f0
Compare
3ab9364
to
96910c4
Compare
96910c4
to
a704f5f
Compare
blockchain/system/auction.go
Outdated
ret, err := caller.Auctioneer(opts) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
|
||
return ret, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret, err := caller.Auctioneer(opts) | |
if err != nil { | |
return common.Address{}, err | |
} | |
return ret, nil | |
return caller.Auctioneer(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. fb4a6d1
blockchain/types/transaction.go
Outdated
@@ -293,6 +293,10 @@ func (tx *Transaction) setDecoded(inner TxInternalData, size int) { | |||
} | |||
} | |||
|
|||
func (tx *Transaction) UpdateTime() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. e0d2854
kaiax/auction/bid.go
Outdated
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 | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
kaiax/auction/bid.go
Outdated
return errors.New("chainId is nil") | ||
} | ||
|
||
if verifyingContract == (common.Address{}) { | ||
return errors.New("verifyingContract is empty") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
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 CLA Document and I hereby sign the CLA
in first time contribute$ make test
)Related issues
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...