Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Revert "Completes updating of signature."
Browse files Browse the repository at this point in the history
This reverts commit fa11ed5.
  • Loading branch information
ckartik committed Apr 9, 2024
1 parent bae13c8 commit 099522b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/preconfirmation/preconfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (p *Preconfirmation) handleBid(
case providerapiv1.BidResponse_STATUS_REJECTED:
return status.Errorf(codes.Internal, "bid rejected")
case providerapiv1.BidResponse_STATUS_ACCEPTED:
preConfirmation, err := p.signer.ConstructPreConfirmation(bid, st.PublishedTimestamp)
preConfirmation, err := p.signer.ConstructPreConfirmation(bid)
if err != nil {
return status.Errorf(codes.Internal, "failed to construct preconfirmation: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/preconfirmation/preconfirmation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (t *testSigner) ConstructSignedBid(_ string, _ string, _ int64, _ int64, _
return t.bid, nil
}

func (t *testSigner) ConstructPreConfirmation(_ *preconfpb.Bid, _ int64) (*preconfpb.PreConfirmation, error) {
func (t *testSigner) ConstructPreConfirmation(_ *preconfpb.Bid) (*preconfpb.PreConfirmation, error) {
return t.preConfirmation, nil
}

Expand Down
10 changes: 4 additions & 6 deletions pkg/signer/preconfsigner/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (

type Signer interface {
ConstructSignedBid(string, string, int64, int64, int64) (*preconfpb.Bid, error)
ConstructPreConfirmation(*preconfpb.Bid, int64) (*preconfpb.PreConfirmation, error)
ConstructPreConfirmation(*preconfpb.Bid) (*preconfpb.PreConfirmation, error)
VerifyBid(*preconfpb.Bid) (*common.Address, error)
VerifyPreConfirmation(*preconfpb.PreConfirmation) (*common.Address, error)
}
Expand Down Expand Up @@ -77,15 +77,14 @@ func (p *privateKeySigner) ConstructSignedBid(
return bid, nil
}

func (p *privateKeySigner) ConstructPreConfirmation(bid *preconfpb.Bid, decayPublishTimestamp int64) (*preconfpb.PreConfirmation, error) {
func (p *privateKeySigner) ConstructPreConfirmation(bid *preconfpb.Bid) (*preconfpb.PreConfirmation, error) {
_, err := p.VerifyBid(bid)
if err != nil {
return nil, err
}

preConfirmation := &preconfpb.PreConfirmation{
Bid: bid,
DecayPublishTimestamp: decayPublishTimestamp,
Bid: bid,
}

preConfirmationHash, err := GetPreConfirmationHash(preConfirmation)
Expand Down Expand Up @@ -243,7 +242,7 @@ func GetPreConfirmationHash(c *preconfpb.PreConfirmation) ([]byte, error) {

// EIP712_MESSAGE_TYPEHASH
eip712MessageTypeHash := crypto.Keccak256Hash(
[]byte("PreConfCommitment(string txnHash,uint64 bid,uint64 blockNumber,uint64 decayStartTimeStamp,uint64 decayEndTimeStamp,string bidHash,string signature,uint64 decayPublishTimestamp)"),
[]byte("PreConfCommitment(string txnHash,uint64 bid,uint64 blockNumber,uint64 decayStartTimeStamp,uint64 decayEndTimeStamp,string bidHash,string signature)"),
)

// Convert the txnHash to a byte array and hash it
Expand All @@ -259,7 +258,6 @@ func GetPreConfirmationHash(c *preconfpb.PreConfirmation) ([]byte, error) {
data = append(data, math.U256Bytes(big.NewInt(c.Bid.DecayEndTimestamp))...)
data = append(data, bidDigestHash.Bytes()...)
data = append(data, bidSigHash.Bytes()...)
data = append(data, math.U256Bytes(big.NewInt(c.DecayPublishTimestamp))...)
dataHash := crypto.Keccak256Hash(data)

rawData := append([]byte("\x19\x01"), append(domainSeparatorBid.Bytes(), dataHash.Bytes()...)...)
Expand Down
13 changes: 6 additions & 7 deletions pkg/signer/preconfsigner/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestBids(t *testing.T) {
t.Fatal(err)
}

preConfirmation, err := providerSigner.ConstructPreConfirmation(bid, 10)
preConfirmation, err := providerSigner.ConstructPreConfirmation(bid)
if err != nil {
t.Fail()
}
Expand Down Expand Up @@ -131,8 +131,7 @@ func TestHashing(t *testing.T) {
}

preConfirmation := &preconfpb.PreConfirmation{
Bid: bid,
DecayPublishTimestamp: 10,
Bid: bid,
}

hash, err := preconfsigner.GetPreConfirmationHash(preConfirmation)
Expand All @@ -141,7 +140,7 @@ func TestHashing(t *testing.T) {
}

hashStr := hex.EncodeToString(hash)
expHash := "6a59e79e8ab974d8db3225687a305fb21a0b7d8158f4c23ab5fc0ec72fb8a1f5"
expHash := "54c118e537dd7cf63b5388a5fc8322f0286a978265d0338b108a8ca9d155dccc"
if hashStr != expHash {
t.Fatalf("hash mismatch: %s != %s", hashStr, expHash)
}
Expand Down Expand Up @@ -170,15 +169,15 @@ func TestSignature(t *testing.T) {
}
keySigner = mockkeysigner.NewMockKeySigner(providerKey, crypto.PubkeyToAddress(providerKey.PublicKey))
provider := preconfsigner.NewSigner(keySigner)
preconf, err := provider.ConstructPreConfirmation(bid, 10)
preconf, err := provider.ConstructPreConfirmation(bid)
if err != nil {
t.Fatal(err)
}

expBidDigest := "a0327970258c49b922969af74d60299a648c50f69a2d98d6ab43f32f64ac2100"
expBidSig := "876c1216c232828be9fabb14981c8788cebdf6ed66e563c4a2ccc82a577d052543207aeeb158a32d8977736797ae250c63ef69a82cd85b727da21e20d030fb311b"
expCommitmentDigest := "6a59e79e8ab974d8db3225687a305fb21a0b7d8158f4c23ab5fc0ec72fb8a1f5"
expCommitmentSig := "399c12c2cd21de19538e049f281752f40ce20f94a70ee1a4ab9b5965ffbf0bdf7de947f0efab28c8f8c292d7c48b01d4d8ace7afa41d420591bf2ec566fdaf8a1b"
expCommitmentDigest := "54c118e537dd7cf63b5388a5fc8322f0286a978265d0338b108a8ca9d155dccc"
expCommitmentSig := "ec0f11f77a9e96bb9c2345f031a5d12dca8d01de8a2e957cf635be14802f9ad01c6183688f0c2672639e90cc2dce0662d9bea3337306ca7d4b56dd80326aaa231b"
if hex.EncodeToString(preconf.Bid.Digest) != expBidDigest {
t.Fatalf("digest mismatch: %s != %s", hex.EncodeToString(preconf.Bid.Digest), expBidDigest)
}
Expand Down

0 comments on commit 099522b

Please sign in to comment.