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

Validate BEEFs Using Block-Header-Service #629

Open
nikhil478 opened this issue Jun 26, 2024 · 5 comments
Open

Validate BEEFs Using Block-Header-Service #629

nikhil478 opened this issue Jun 26, 2024 · 5 comments
Assignees

Comments

@nikhil478
Copy link

Proposed Solution
Integrate the block-header-service to validate BEEFs when transactions are received from Paymail. This can be implemented by referencing the go-paymail examples.

Steps to Implement

Add integration code to validate BEEFs using the block-header-service.
Update relevant documentation to reflect the new validation process.
(Optional) Provide example code snippets or tests to demonstrate the validation process.

Additional Context
If there is a specific reason why the current implementation does not validate BEEFs using the block-header-service, please provide details. I am in the process of creating a customized version of this project and want to ensure proper BEEF validation.

Questions

Am I missing where the current implementation is verifying BEEFs?
Are there any challenges or reasons for not using the block-header-service for BEEF validation?

References : https://github.com/bitcoin-sv/go-paymail/blob/main/server/p2p_receive_transaction.go

@nikhil478
Copy link
Author

@rohenaz @Klar @proapi @mrz1836 i would really appreciate any help ! thanks

@dorzepowski
Copy link
Contributor

To use go-paymail one need to implement PaymailServiceProvider interface
https://github.com/bitcoin-sv/go-paymail/blob/main/server/interface.go#L53

We're leaving to the adopter to choose any implementation and any service that could provide this functionality.
We have already implementation of this interface in spv-wallet which uses Block Headers Service (BHS) for SPV. Although the implementation has several layers, at the end it is calling BHS in this service: https://github.com/bitcoin-sv/spv-wallet/blob/main/engine/chainstate/merkle_root_provider.go#L59

Is it sufficient for you?

@dorzepowski dorzepowski self-assigned this Jun 27, 2024
@nikhil478
Copy link
Author

// VerifyMerkleRoots will verify the merkle roots by checking them in external header service - Block Headers Service
func (p *PaymailDefaultServiceProvider) VerifyMerkleRoots(
ctx context.Context,
merkleRoots []*spv.MerkleRootConfirmationRequestItem,
) (err error) {
if metrics, enabled := p.client.Metrics(); enabled {
end := metrics.TrackVerifyMerkleRoots()
defer func() {
success := err == nil
end(success)
}()
}

request := make([]chainstate.MerkleRootConfirmationRequestItem, 0, len(merkleRoots))
for _, m := range merkleRoots {
	request = append(request, chainstate.MerkleRootConfirmationRequestItem{
		MerkleRoot:  m.MerkleRoot,
		BlockHeight: m.BlockHeight,
	})
}
**err = p.client.Chainstate().VerifyMerkleRoots(ctx, request)**
return

} here it is gotcha thanks @dorzepowski

@nikhil478 nikhil478 reopened this Jun 27, 2024
@nikhil478
Copy link
Author

but i didnt find that it was getting used while receiving beef payment through paymail it should be called there what u think @dorzepowski

@dorzepowski
Copy link
Contributor

@nikhil478
The function spv.ExectueSimplifiedPaymentVerification is called upon receiving BEEF through BEEF paymail capability.
And inside it there is a call to verifyMerkleRoots which if you follow the implementation of it, you will find that it will call the provider.VerifyMerkleRoots which is a call to an interface implementation which need to be provided by adopter of the go-paymail.
We're leaving the choice how to implement this integration and more specifically what service and how it should be used to verify that merkleroot was minded at given block height.
In case of spv-wallet, it is implementing this interface and then the implementation is calling https://github.com/bitcoin-sv/spv-wallet/blob/main/engine/chainstate/merkle_root_provider.go#L59 (which I show you earlier).

Hope this answered your question and doubts.

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

No branches or pull requests

2 participants