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

fix: fix vuln demonstrated by #583 #584

Merged
merged 8 commits into from
Sep 22, 2023

Conversation

grepsuzette
Copy link
Contributor

@grepsuzette grepsuzette commented Mar 10, 2023

This is a fix for the 2022-10-07 Binance vuln demonstrated in #583.

Original fix was simply (cosmos/iavl#582):

if len(pin.Left) > 0 && len(pin.Right) > 0 {
	return nil, errors.New("both left and right child hashes are set")
}

Our iavl functions however don't return errors. Proposing to use panic() instead, as it does in other parts of this file.


More about the vuln, for comments and archival:

@grepsuzette grepsuzette requested a review from a team as a code owner March 10, 2023 04:50
@grepsuzette grepsuzette changed the title fix vuln demonstrated by https://github.com/gnolang/gno/pull/583 fix vuln demonstrated by #583 Mar 10, 2023
@moul moul added the 🐞 bug Something isn't working label Mar 27, 2023
grepsuzette added a commit to grepsuzette/gno that referenced this pull request Mar 30, 2023
@grepsuzette grepsuzette changed the title fix vuln demonstrated by #583 fix: fix vuln demonstrated by #583 Mar 30, 2023
@tbruyelle
Copy link
Contributor

@grepsuzette Thanks for all the links, that's very interesting to dive again into that. Have you noticed that they literally removed the range proof from cosmos/iavl, in favor of the ics23 proof ?

I came across this while trying to find range_proof.go in the cosmos/iavl repo, it's no longer there ! Then I find this commit cosmos/iavl@401725a which removes it.
Maybe we should follow that too, wdyt?

@grepsuzette
Copy link
Contributor Author

grepsuzette commented Mar 31, 2023

@grepsuzette Thanks for all the links, that's very interesting to dive again into that. Have you noticed that they literally removed the range proof from cosmos/iavl, in favor of the ics23 proof ?

Yes I did.

I came across this while trying to find range_proof.go in the cosmos/iavl repo, it's no longer there ! Then I find this commit cosmos/iavl@401725a which removes it. Maybe we should follow that too, wdyt?

Range proofs I think were written by Jae; my guess, also I think I read that somewhere, is that they found it scary to modify (because it's a little bit scary; also whoever modifies it must be a kamikaze). Ics23 is more of a community effort, more reassuring for a community. But, if you've seen Dragonberry, it was a vuln in ics23 that could have resulted in all funds in ibc channels being hacked. So there's no silver bullet.

Still I think the ics23 iavl is an interesting question. It would take more studying to have an opinion. First of all, this vuln should be studied https://blog.verichains.io/p/vsa-2022-100-tendermint-forging-membership-proof ; does it affect GNO's iavl? But in any case even if we decided to adopt it (ics23), I think it should be in a different PR.

@tbruyelle
Copy link
Contributor

Thanks for the additional details @grepsuzette I agree with your arguments, range proof isn't necessarily something we need to replace for now.

About the tendermint vuln, you're right we should definitively study it since it concerns the tendermint/crypto/merkle package and GNO has the same package pkg/crypto/merkle, which is used in pkg/iavl.

anyway, LGTM for this PR 👍

@grepsuzette
Copy link
Contributor Author

Thanks, appreciate you taking the time to review and talk.

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Thank you for applying the fix 🙏

This fix is just part of a bigger issue of maintaining a stable iavl implementation.
I don't agree with the way we handled this fix with a panic, but it's a good starting point to discuss how we can make this safer and more reliable

cc @moul

pkgs/iavl/proof_forgery_test.go Outdated Show resolved Hide resolved
pkgs/iavl/proof_forgery_test.go Outdated Show resolved Hide resolved
@zivkovicmilos
Copy link
Member

@grepsuzette

Please resolve the conflicts in this PR 🙏

Original fix at cosmos/iavl#582, is simply:

```
if len(pin.Left) > 0 && len(pin.Right) > 0 {
	return nil, errors.New("both left and right child hashes are set")
}
```
Our iavl functions however don't return errors. Proposing to use
`panic()` instead, as it does in other parts of this file.

More about this 2022-10-07 vuln:

https://medium.com/@Beosin_com/how-did-the-bnb-chain-exploiter-pass-iavl-proof-verification-an-in-depth-analysis-by-beosin-c925b77bc13e
https://twitter.com/buchmanster/status/1578879225574350848
Won't compile yet.
Is a test of the iavl proof forgery as exploited during BSC 2022-10-07 hack.

Notes:
1. proof_forgery_test.go comes from cosmos/iavl#582
2. gist showing the same vuln at https://gist.github.com/samczsun/8635f49fac0ec66a5a61080835cae3db

The test is not going to compile as is, it needs some work.
…lnerable)

output follows

--- FAIL: TestProofForgery (0.00s)
    proof_forgery_test.go:69:
                Error Trace:    /home/bob/opt/src/COINS/Cosmos/GNO/gno/pkgs/iavl/proof_forgery_test.go:69
                Error:          Should be empty, but was [73 209 82 89 222 179 131 99 170 27 180 58 80 20 211 (...) 94 7 254 45 183 20 244]
                Test:           TestProofForgery
                Messages:       roothash must be empty if both left and right are set
FAIL
FAIL    command-line-arguments  0.003s
FAIL
and fails otherwise (fails when vuln not fixed)

It should now be ok for review.
applying @zikovicmilos suggestion
@grepsuzette
Copy link
Contributor Author

@zivkovicmilos done

@grepsuzette
Copy link
Contributor Author

I don't understand why there's one cancelled check.

@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Jun 1, 2023
@ajnavarro
Copy link
Contributor

@moul shall we review/merge this? thanks!

@moul moul added this to the 🚀 main.gno.land milestone Sep 6, 2023
@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05% 🎉

Comparison is base (e10c0c7) 46.98% compared to head (f4766e5) 47.04%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #584      +/-   ##
==========================================
+ Coverage   46.98%   47.04%   +0.05%     
==========================================
  Files         365      365              
  Lines       61159    61161       +2     
==========================================
+ Hits        28737    28771      +34     
+ Misses      30062    30036      -26     
+ Partials     2360     2354       -6     
Flag Coverage Δ
gnovm-_test.cmd 45.89% <ø> (ø)
gnovm-_test.gnolang.native 63.09% <ø> (ø)
gnovm-_test.gnolang.other 16.63% <ø> (ø)
gnovm-_test.gnolang.pkg0 17.98% <ø> (ø)
gnovm-_test.gnolang.pkg1 8.21% <ø> (ø)
gnovm-_test.gnolang.pkg2 9.87% <ø> (ø)
gnovm-_test.gnolang.realm 41.68% <ø> (ø)
gnovm-_test.gnolang.stdlibs 53.53% <ø> (ø)
gnovm-_test.pkg 25.95% <ø> (ø)
tm2-_test.flappy ∅ <ø> (∅)
tm2-_test.pkg.amino 58.32% <ø> (ø)
tm2-_test.pkg.bft 63.67% <ø> (+0.16%) ⬆️
tm2-_test.pkg.others 59.27% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
tm2/pkg/iavl/proof.go 92.98% <100.00%> (+0.12%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@moul moul merged commit b449e89 into gnolang:master Sep 22, 2023
173 checks passed
gfanton pushed a commit to gfanton/gno that referenced this pull request Nov 9, 2023
This is a fix for the 2022-10-07 Binance vuln demonstrated in gnolang#583.

**Original fix** was simply (cosmos/iavl#582):

```
if len(pin.Left) > 0 && len(pin.Right) > 0 {
	return nil, errors.New("both left and right child hashes are set")
}
```
Our iavl functions however don't return errors. Proposing to use
`panic()` instead, as it does in other parts of this file.

---
More about the vuln, for comments and archival:

* https://twitter.com/buchmanster/status/1578879225574350848
*
https://medium.com/@Beosin_com/how-did-the-bnb-chain-exploiter-pass-iavl-proof-verification-an-in-depth-analysis-by-beosin-c925b77bc13e

---------

Co-authored-by: grepsuzette <grepsuzette@users.noreply.github.com>
Co-authored-by: Antonio Navarro Perez <antnavper@gmail.com>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Done
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants