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

Add basic authentication classes #166

Merged
merged 2 commits into from
Jan 10, 2024
Merged

Conversation

mooselumph
Copy link
Collaborator

Why are these changes needed?

Add authentication classes for signing blob request header and checking signature.

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

binary.BigEndian.PutUint32(buf, header.Nonce)
hash := crypto.Keccak256(buf)

publicKeyBytes, err := hexutil.Decode(header.AccountID)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does accountId need any validation before decoding?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shouldn't, if the string is invalid hex then the Decode method will fail.


// Ensure the signature is 65 bytes (Recovery ID is the last byte)
if len(sig) != 65 {
return fmt.Errorf("signature length is unexpected: %d", len(sig))
Copy link
Contributor

@siddimore siddimore Jan 8, 2024

Choose a reason for hiding this comment

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

probably log accountId to help debug or whatever other identifier to uniquely identify this request

// Nonce
Nonce uint32 `json:"nonce"`
// AuthenticationData is the signature of the blob header by the account ID
AuthenticationData []byte `json:"authentication_data"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we call it Signature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's possible this could be more generic in the future... For instance, this could end up being data which gets passed along to the rollup account smart contract, whose semantics the EigenDA protocol is agnostic to. But I'm fine with calling it signature for now.

@@ -40,6 +40,17 @@ type Blob struct {
Data []byte
}

type BlobAuthHeader struct {
// Commitments
BlobCommitments `json:"commitments"`
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 comment on what this means and why we need this field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment to the BlobAuthHeader.

// AccountID is the account that is paying for the blob to be stored
AccountID AccountID `json:"account_id"`
// Nonce
Nonce uint32 `json:"nonce"`
Copy link
Contributor

Choose a reason for hiding this comment

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

does it need to be incremented for every call? looks like Nonce is just being used as a message to sign

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eventually this will be an incremental nonce (https://docs.google.com/document/d/1w2H38txbe21ex8bwxNMAcjRq4K5WHq0NCv6jYy8yo54/edit#heading=h.2ty1ce44eg7b). However, since we don't yet support payments we can simplify things. I think that the random challenge approach is the quickest way to get us the minimal capability that we want.

// Commitments
BlobCommitments `json:"commitments"`
// AccountID is the account that is paying for the blob to be stored
AccountID AccountID `json:"account_id"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this decided already (to be the eth address)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's some uncertainty about how this will marry with the payments design, but I think it's okay to move forward with supporting a simple ECDSA-based authentication. We can swap this out pretty easily, imo.

Currently, the AccountID shoul be the ECDSA public key. I'll update the comment.

}
}

func (s *signer) SignBlobRequest(header core.BlobAuthHeader) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should it also sign BlobCommitments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Authentication will have two stages:

  1. Authentication by Disperser (now)

  2. Authentication by Nodes (future)

  3. will be needed when we add payments. At that point, we will need to implement the full protocol, which will include signing the kzg commitment. But as we are currently only doing Authentication by the Disperser, we can do a more lightweight approach. Signing the challenge parameter just lets the disperser know that the requester has the actual private key, and not merely a signature from the private key.

If we add signing the kzg now, it implies additional work, such as actually verifying the kzg commitment. We can add this quickly, but I'm trying to minimize scope for now.

@mooselumph mooselumph merged commit 7cc5bb0 into Layr-Labs:master Jan 10, 2024
4 checks passed
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.

4 participants