-
Notifications
You must be signed in to change notification settings - Fork 12
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
chore: Do not convert int to uint32 in btcstaking lib #135
Conversation
ed1e4bb
to
ab85b5a
Compare
@@ -45,7 +46,11 @@ func newLightChainCtxFromParams(params *chaincfg.Params) *lightChainCtx { | |||
targetTimePerBlock := int64(params.TargetTimePerBlock / time.Second) | |||
adjustmentFactor := params.RetargetAdjustmentFactor | |||
|
|||
blocksPerRetarget := int32(targetTimespan / targetTimePerBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh this is what btcd does with their types regarding those values, and I would leave it like that. I assume they try to match whatever bitcoind is doing. (ref:https://github.com/btcsuite/btcd/blob/master/blockchain/chain.go#L2186)
And in this case it is better to be consistent with btcd and bitcoind, than be consistent with gosec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we doing the same thing though? No problem with keeping it as it is though, did it just for gosec, but we can add a nosec tag if want to. Reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we doing the same thing though?
Most probably we are doing the same thing, but the probably
part would require some investigation to be 100% sure, given that this values are relevant to consensus of BTC headers.
On the other hand, being compatible with btcd relaxes this a bit (I think there are 60 btcd nodes in bitcoin network rn, so if they are conensus compliant we are off the hook) 😅
63dfbb3
to
f619a3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work
This PR handles the conversion of ints to uint32s in the btcstaking library. The conversions that were modified were not unsafe as they were the results of the `len()` call, but they still made static analyzers complain. Instead, we opted to convert uint32s to ints. However, this makes the assumption that the program will be executed in 64-bit architectures in order to be safe, which afaik is already a requirement. Further, the PR includes some other small conversion fixes that have been found in the codebase -- mostly low hanging fruit.
f619a3e
to
39bd50e
Compare
This PR handles the conversion of ints to uint32s in the btcstaking library. The conversions that were modified were not unsafe as they were the results of the
len()
call,but they still made static analyzers complain.
Instead, we opted to convert uint32s to ints. However, this makes the assumption that the program will be executed in 64-bit architectures in order to be safe, which afaik is already a requirement.