You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This forces language bindings to implement business logic in the wrapper layer just to be spec compliant. I think any such cases should be left out of the test spec until they are exported in bitcoinkernel.h on master.
In the same vein, I think we should strive for the test spec to following btck naming conventions as much as possible. For example:
btck_ScriptVerificationFlags has a WITNESS member, but it is called VERIFY_WITNESS in kernel-bindings-tests
btck exports a btck_ScriptVerifyStatus enum, but it is called ScriptVerify in kernel-bindings-tests
as already suggested on IRC, aligning method naming with btck functions would make sense
Thanks a lot for the feedback @stickies-v. You're making fair points.
Re: extra error variants (TxInputIndex, SpentOutputsMismatch, ...) introduced in script_verify_errors.json: Personally, I find the extra guards included in the verify() implementation in the Rust wrapper nice; though I understand it doesn't make much sense to enforce them here when libbitcoinkernel hasn't included them.
1. Error structure refactoring
It seems I have to refactor the expected error structure. Right now we have:
But that doesn't seem suitable anymore if we want to stick to the btck symbols. Looking at bitcoinkernel.h, operations currently could return a non-zero value or nullptr indicating error (except for btck_script_pubkey_verify() which returns zero on failure). I'm thinking about how these cases could be unified and presented in the JSON structure; perhaps the following for when we don't have the reason for the failure:
Personally, I find the extra guards included in the verify() implementation in the Rust wrapper nice
I agree, and if we find that every language bindings wants to implement them in the wrapper logic I think it might be worth discussing to just add them to the C header.
I'm thinking about how these cases could be unified and presented in the JSON structure; perhaps the following for when we don't have the reason for the failure:
Since errors can be null, I think we need an explicit success field (as you currently do), I think "error": {} should be equivalent to the json object not having an error key at all. I think the exact return type of btck (false, 0, nullptr) on failure can all be generalized into "succes": "false". The (optional) "error" field can the encode information about the specifics of the error, if available. Ideally, it is structured so that clients can automatically parse and convert it into their local naming convention. I think the below makes that quite easy:
Would it make more sense to you if it's replaced with an array of flags that should be ORed together: ... Or just use the numerical result value?
Either approach seems acceptable to me. Using numerical result values seems more elegant, but I think there is value in testing the flag names since that's what users will actually be using, so that probably has my preference (even though I don't like that the OR operations are implied but not specified)
I think it might be worth discussing to just add them to the C header.
I've opened bitcoin/bitcoin#33943 to address this. It doesn't have status code for malformed requests - I'm not convinced that is meaningful, but the approach does allow kernel-bindings-tests to properly test that these malformed edge cases are handled uniformly across language bindings. Hope to hear your thoughts on the PR!
I think it might be worth discussing to just add them to the C header.
I've opened bitcoin/bitcoin#33943 to address this. It doesn't have status code for malformed requests - I'm not convinced that is meaningful, but the approach does allow kernel-bindings-tests to properly test that these malformed edge cases are handled uniformly across language bindings. Hope to hear your thoughts on the PR!
@stickies-v Thank you for opening the PR, I will have a look soon. I had the same struggle, I found the enum extension of the rust impl. logical and nice to have but it made the implementation kinda not optimal. This will solve that :)
Since errors can be null, I think we need an explicit success field (as you currently do), [...] quite easy:
I agree with the proposal of the addition of succes field , it can even represent the nullptr state:
{
"success": "false",
"error": {}
}
Would it make more sense to you if it's replaced with an array of flags that should be ORed together: ... Or just use the numerical result value?
Both would make sense to me, if both are to be expected.
Would it make more sense to you if it's replaced with an array of flags that should be ORed together: ... Or just use the numerical result value?
Either approach seems acceptable to me. Using numerical result values seems more elegant, but I think there is value in testing the flag names since that's what users will actually be using, so that probably has my preference (even though I don't like that the OR operations are implied but not specified)
I am thinking whether we should reconsider bringing back the test cases I removed in #7 (error_tx_input_index_out_of_bounds, error_spent_outputs_mismatch, error_invalid_flags) as they seem to be valuable in validating that binding implementations perform input validation before calling into the C API and prevent crashes resulting from a naive implementation. Not sure how it could fit in the new structure; maybe a generic failure with no error code?
{
"id": "error_tx_input_index_out_of_bounds",
"description": "Binding must validate input_index before calling kernel",
"expected": {
"success": false
}
}
What do you think? An alternative is to just wait to see how kernel is improved in dealing with bad user input.
as they seem to be valuable in validating that binding implementations perform input validation before calling into the C API and prevent crashes resulting from a naive implementation.
I agree that it is useful, and I think we should work towards being able to do that, but I think doing it now will cause more problems than benefit
What do you think? An alternative is to just wait to see how kernel is improved in dealing with bad user input.
If you add them back now, I don't think you'll be able to make the tests succeed on the C API itself, and that seems like a big problem to me. I really don't think it makes sense to have tests that violate the API's preconditions.
I really don't think it makes sense to have tests that violate the API's preconditions.
Can you elaborate a bit on this please?
I understand it is challenging to have such tests if the goal is to stick to btck symbols, but it does not sound unreasonable to have them if at some point we decide to leave the C API minimal and expect bindings to implement additional validation layers.
I agree to delay adding them though, hoping for the C API to make it less challenging.
if at some point we decide to leave the C API minimal and expect bindings to implement additional validation layers.
That is exactly what I think shouldn't happen. Bindings should make the interface idiomatic, nothing else. They shouldn't be relied on for extra validation, because that risks diverging behaviour across users depending on their language choice. It creates first-class and second-class citizens, whereas the C API and all of its language bindings should be on equal footing.
In this particular case, the C API already does the validation, it just makes it untestable because it asserts these preconditions. If we can't test that behaviour is identical across implementations, I think it shouldn't be part of the interface. For that reason, I think it would be useful if someone built a handler for the C API.
Activity
stringintech commentedon Nov 25, 2025
Thanks a lot for the feedback @stickies-v. You're making fair points.
Re: extra error variants (
TxInputIndex,SpentOutputsMismatch, ...) introduced inscript_verify_errors.json: Personally, I find the extra guards included in theverify()implementation in the Rust wrapper nice; though I understand it doesn't make much sense to enforce them here whenlibbitcoinkernelhasn't included them.1. Error structure refactoring
It seems I have to refactor the expected error structure. Right now we have:
But that doesn't seem suitable anymore if we want to stick to the
btcksymbols. Looking atbitcoinkernel.h, operations currently could return a non-zero value ornullptrindicating error (except forbtck_script_pubkey_verify()which returns zero on failure). I'm thinking about how these cases could be unified and presented in the JSON structure; perhaps the following for when we don't have the reason for the failure:And when we have the reason:
2.
VERIFY_ALL_PRE_TAPROOTrepresentationWould it make more sense to you if it's replaced with an array of flags that should be ORed together:
Or just use the numerical result value?
I'd appreciate your further feedback on the above two points.
cc @janb84 @yuvicc
stickies-v commentedon Nov 25, 2025
I agree, and if we find that every language bindings wants to implement them in the wrapper logic I think it might be worth discussing to just add them to the C header.
Since errors can be null, I think we need an explicit
successfield (as you currently do), I think"error": {}should be equivalent to the json object not having anerrorkey at all. I think the exact return type ofbtck(false, 0, nullptr) on failure can all be generalized into"succes": "false". The (optional) "error" field can the encode information about the specifics of the error, if available. Ideally, it is structured so that clients can automatically parse and convert it into their local naming convention. I think the below makes that quite easy:{ "success": "false", "error": { "code": { "type": "btck_ScriptVerifyStatus", "member": "ERROR_INVALID_FLAGS_COMBINATION" } } }Either approach seems acceptable to me. Using numerical result values seems more elegant, but I think there is value in testing the flag names since that's what users will actually be using, so that probably has my preference (even though I don't like that the
ORoperations are implied but not specified)stickies-v commentedon Nov 25, 2025
I've opened bitcoin/bitcoin#33943 to address this. It doesn't have status code for malformed requests - I'm not convinced that is meaningful, but the approach does allow
kernel-bindings-teststo properly test that these malformed edge cases are handled uniformly across language bindings. Hope to hear your thoughts on the PR!janb84 commentedon Nov 25, 2025
@stickies-v Thank you for opening the PR, I will have a look soon. I had the same struggle, I found the enum extension of the rust impl. logical and nice to have but it made the implementation kinda not optimal. This will solve that :)
I agree with the proposal of the addition of succes field , it can even represent the nullptr state:
{ "success": "false", "error": {} }Both would make sense to me, if both are to be expected.
stringintech commentedon Nov 26, 2025
I have addressed the feedback and suggestions in #7.
Thank you!
yuvicc commentedon Nov 27, 2025
I tend to agree with the approach mentioned by @stickies-v.
stringintech commentedon Nov 27, 2025
I am thinking whether we should reconsider bringing back the test cases I removed in #7 (
error_tx_input_index_out_of_bounds,error_spent_outputs_mismatch,error_invalid_flags) as they seem to be valuable in validating that binding implementations perform input validation before calling into the C API and prevent crashes resulting from a naive implementation. Not sure how it could fit in the new structure; maybe a generic failure with no error code?{ "id": "error_tx_input_index_out_of_bounds", "description": "Binding must validate input_index before calling kernel", "expected": { "success": false } }What do you think? An alternative is to just wait to see how kernel is improved in dealing with bad user input.
stickies-v commentedon Nov 27, 2025
I agree that it is useful, and I think we should work towards being able to do that, but I think doing it now will cause more problems than benefit
If you add them back now, I don't think you'll be able to make the tests succeed on the C API itself, and that seems like a big problem to me. I really don't think it makes sense to have tests that violate the API's preconditions.
stringintech commentedon Nov 28, 2025
Can you elaborate a bit on this please?
I understand it is challenging to have such tests if the goal is to stick to
btcksymbols, but it does not sound unreasonable to have them if at some point we decide to leave the C API minimal and expect bindings to implement additional validation layers.I agree to delay adding them though, hoping for the C API to make it less challenging.
stickies-v commentedon Nov 28, 2025
That is exactly what I think shouldn't happen. Bindings should make the interface idiomatic, nothing else. They shouldn't be relied on for extra validation, because that risks diverging behaviour across users depending on their language choice. It creates first-class and second-class citizens, whereas the C API and all of its language bindings should be on equal footing.
In this particular case, the C API already does the validation, it just makes it untestable because it asserts these preconditions. If we can't test that behaviour is identical across implementations, I think it shouldn't be part of the interface. For that reason, I think it would be useful if someone built a handler for the C API.
stringintech commentedon Nov 28, 2025
That clarifies it for me. Thanks.
That would be interesting... Would like to look into that when I get some more time.