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

One curve to rule them all: Eliminate dependency to ethereum/go-ethereum #16

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

pdyraga
Copy link
Member

@pdyraga pdyraga commented Jun 26, 2024

Depends on #15

We now use btcsuite/btc/btcec as a curve implementation in ephemeral and frost packages. This allows to eliminate the dependency to ethereum/go-ethereum altogether. The Marshal and Unmarshal code for points had to be copied from ethereum/go-ethereum to bip340.go. I found no code in btcsuite/btc/btcec doing what we need.

We now use `btcsuite/btc/btcec` as a curve implementation in `ephemeral`
and `frost` packages. This allows to eliminate the dependency to
`ethereum/go-ethereum` altogether. The Marshal and Unmarshal code for points
had to be copied from `ethereum/go-ethereum` to `bip340.go`. I found
no code in `btcsuite/btc/btcec` doing what we need.
@pdyraga pdyraga requested review from eth-r and lukasz-zimnoch June 26, 2024 11:59
Base automatically changed from ephemeral to main October 15, 2024 12:16
@lukasz-zimnoch lukasz-zimnoch marked this pull request as ready for review October 15, 2024 12:17
// byteLen := (BitCurve.BitSize + 7) >> 3
// ret := make([]byte, 1+2*byteLen)
return 65
byteLen := (b.BitSize + 7) >> 3
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: I would take an opportunity an explain the bitwise magic for future-us. For example, here we divide by 8 but it took me a while to figure this out 😅 Same regarding other places in-scope of this PR.

// ret := make([]byte, 1+2*byteLen)
return 65
byteLen := (b.BitSize + 7) >> 3
return 1 + 2*byteLen
}

// SerializePoint serializes the provided elliptic curve point to bytes.
// The slice length is equal to SerializedPointLength().
func (b *Bip340Curve) SerializePoint(p *Point) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Probably not in-scope of this PR but we are not checking whether the given point is on the curve here. If this is ok, it's worth flagging this in the method's docstring. This may cause unexpected errors if we ever attempt to marshal a point whose coordinates use a different byte size than the BIP340 curve so, worth flagging.

@@ -113,6 +112,57 @@ func (b *Bip340Curve) DeserializePoint(bytes []byte) *Point {
return point
}

// Marshal and Unmarshal as well as readBits were copied from
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: Worth covering Marshal and Unmarshal with some basic unit tests.

@lukasz-zimnoch lukasz-zimnoch merged commit 07c4f72 into main Oct 15, 2024
2 checks passed
@lukasz-zimnoch lukasz-zimnoch deleted the one-curve branch October 15, 2024 15:37
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