Skip to content

Conversation

@tbruyelle
Copy link
Contributor

@tbruyelle tbruyelle commented Jun 13, 2025

Following convo on Signal, I create this draft PR to demonstrate the bug and report all the informations.

Disclaimer

I didn't test all the different scenarios so there might be other cases of proof generation that are incorrect. The case I present here is the one I had a chance to reproduce, but I found an other scenario where the proof was also incorrect but differently than the case here.

Context

While I was asserting the behavior of tm2 proofs (for the IBC connection with A1), I found an issue with absence proofs.

The test TestTreeGetWithProof() (modified in this PR) builds a merkle tree with keys 0x11, 0x32, 0x50, 0x72, 0x99, and so looks like this:

image

  • Node label is KEY / HASH
  • The first two leafs are numbered with 1 and 2 for the purpose of the demo.

After asserting a proof of the presence of the key 0x32, which is not relevant here, the test asserts a proof of the absence of key 0x1. The returned proof is correct and asserts that 0x1 is absent of the tree. In term of leaves, the proof contains only the leaf 1, because 0x1 < 0x11 (key of 1).

Now if that key is changed to 0x1100 like in this PR, the returned proof is exactly the same as with 0x1, but this is incorrect because this time 0x1100 > 0x11. For that proof to be correct, the proof's leaves should contain both 1 and 2 because 0x1100 is between 0x11 and 0x32.

Hence the verification algorithm returns an error, given that absence of second leaf: absence not proved by right leaf (need another leaf?)

Important

The same change applied to the same test in cosmos/iavl produces a valid proof.

@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Jun 13, 2025
@tbruyelle tbruyelle marked this pull request as draft June 13, 2025 10:09
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jun 13, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jun 13, 2025

🛠 PR Checks Summary

🔴 Pending initial approval by a review team member, or review from tech-staff

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: tbruyelle/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🔴 Requirement not satisfied
└── 🔴 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🔴 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🟢 This pull request is a draft
    └── 🔴 Then
        └── 🔴 And
            ├── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)
            └── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jun 13, 2025
@Gno2D2 Gno2D2 requested a review from a team June 13, 2025 10:09
zivkovicmilos added a commit that referenced this pull request Sep 29, 2025
The IBC protocol is based on merkle proofs, and over the years a
standard of merkle proof representation has emerged:
[ICS23](https://github.com/cosmos/ics23). The simplest way for Gno to be
compatible with this protocol is to migrate the iavl implementation to
[`cosmos/iavl`](https://github.com/cosmos/iavl), which already supports
ICS23.

```diff
- Therefore, this PR deprecates `tm2/pkg/iavl` in favour of imported `cosmos/iavl`.
+ Therefore, this PR replaces the code of `tm2/pkg/iavl` with the code of `cosmos/iavl@v1.3.5`.
```

Note that `cosmos/iavl` is just a maintened version of `tm2/pkg/iavl`,
which has received numerous improvements and bug fixes over the years.


In addition to the benefit of making Gno IBC-ready, this change also
eliminates some drawbacks of `tm2/pkg/iavl`:
- `tm2/pkg/iavl` uses the legacy `range-proof` under the hood which is
considered unsafe. It has an exploited vulnerability (see DragonFruit
[[1](https://github.com/cosmos/iavl/issues/584)][[2](https://forum.cosmos.network/t/cosmos-sdk-security-advisory-dragonfruit/7614)])
- `tm2/pkg/iavl` proof generation is buggy: see
#4369

This change only concerns the proof system. The Gno light client realm
which is the other important piece of the IBCv2 connection between
Gnoland and AtomOne is still under progress
[here](#4655).

> [!IMPORTANT]
> This
[change](https://github.com/gnolang/gno/pull/4656/files#diff-4f1d80300014eb607e44892f6ebdcc31de2c0815669acd54f805b83501311b7fL419)
to the commit info hashing is causing a app hash mismatch when
restarting a node with a binary built from this branch.
> ```
> panic: state.AppHash does not match AppHash after replay. Got
> 76BB396891B9F4415AC49FB72CF81933F407AE6A2C04551814719C9A908B2E8E,
expected
8EDAB60FFD0B2C6BB5AC398417CF0AFBFE6E7D491C830F831F9395DB7FAC522A.
> ```
> Unfortunately without it some tests are failing because ics23 does not
expect to have hashed value. As a result, upgrading a mainnet launched
using `tm2/pkg/iavl` to a new version with `cosmos/iavl` might be
challenging. It's probably a good idea to merge this change for the
initial mainnet.


## For reviewers

- Most of the diff is related to the `DB` interface, because most of
declared methods return an error in `comos/iavl`
- When possible I added a comment for change related to the difference
between `tm2/pkg/iavl` and `cosmos/iavl` implementation.
- Lazy loading has been removed in `cosmos/iavl` so I had no other
choice than removing the option from the Gno store. Anyway this feature
was not used.

---------

Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
Co-authored-by: Miloš Živković <milos.zivkovic@tendermint.com>
MikaelVallenet pushed a commit to MikaelVallenet/gno that referenced this pull request Oct 1, 2025
…ng#4656)

The IBC protocol is based on merkle proofs, and over the years a
standard of merkle proof representation has emerged:
[ICS23](https://github.com/cosmos/ics23). The simplest way for Gno to be
compatible with this protocol is to migrate the iavl implementation to
[`cosmos/iavl`](https://github.com/cosmos/iavl), which already supports
ICS23.

```diff
- Therefore, this PR deprecates `tm2/pkg/iavl` in favour of imported `cosmos/iavl`.
+ Therefore, this PR replaces the code of `tm2/pkg/iavl` with the code of `cosmos/iavl@v1.3.5`.
```

Note that `cosmos/iavl` is just a maintened version of `tm2/pkg/iavl`,
which has received numerous improvements and bug fixes over the years.


In addition to the benefit of making Gno IBC-ready, this change also
eliminates some drawbacks of `tm2/pkg/iavl`:
- `tm2/pkg/iavl` uses the legacy `range-proof` under the hood which is
considered unsafe. It has an exploited vulnerability (see DragonFruit
[[1](https://github.com/cosmos/iavl/issues/584)][[2](https://forum.cosmos.network/t/cosmos-sdk-security-advisory-dragonfruit/7614)])
- `tm2/pkg/iavl` proof generation is buggy: see
gnolang#4369

This change only concerns the proof system. The Gno light client realm
which is the other important piece of the IBCv2 connection between
Gnoland and AtomOne is still under progress
[here](gnolang#4655).

> [!IMPORTANT]
> This
[change](https://github.com/gnolang/gno/pull/4656/files#diff-4f1d80300014eb607e44892f6ebdcc31de2c0815669acd54f805b83501311b7fL419)
to the commit info hashing is causing a app hash mismatch when
restarting a node with a binary built from this branch.
> ```
> panic: state.AppHash does not match AppHash after replay. Got
> 76BB396891B9F4415AC49FB72CF81933F407AE6A2C04551814719C9A908B2E8E,
expected
8EDAB60FFD0B2C6BB5AC398417CF0AFBFE6E7D491C830F831F9395DB7FAC522A.
> ```
> Unfortunately without it some tests are failing because ics23 does not
expect to have hashed value. As a result, upgrading a mainnet launched
using `tm2/pkg/iavl` to a new version with `cosmos/iavl` might be
challenging. It's probably a good idea to merge this change for the
initial mainnet.


## For reviewers

- Most of the diff is related to the `DB` interface, because most of
declared methods return an error in `comos/iavl`
- When possible I added a comment for change related to the difference
between `tm2/pkg/iavl` and `cosmos/iavl` implementation.
- Lazy loading has been removed in `cosmos/iavl` so I had no other
choice than removing the option from the Gno store. Anyway this feature
was not used.

---------

Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
Co-authored-by: Miloš Živković <milos.zivkovic@tendermint.com>
@tbruyelle
Copy link
Contributor Author

Fixed by #4656

@tbruyelle tbruyelle closed this Oct 6, 2025
gfanton pushed a commit to gfanton/gno that referenced this pull request Oct 10, 2025
…ng#4656)

The IBC protocol is based on merkle proofs, and over the years a
standard of merkle proof representation has emerged:
[ICS23](https://github.com/cosmos/ics23). The simplest way for Gno to be
compatible with this protocol is to migrate the iavl implementation to
[`cosmos/iavl`](https://github.com/cosmos/iavl), which already supports
ICS23.

```diff
- Therefore, this PR deprecates `tm2/pkg/iavl` in favour of imported `cosmos/iavl`.
+ Therefore, this PR replaces the code of `tm2/pkg/iavl` with the code of `cosmos/iavl@v1.3.5`.
```

Note that `cosmos/iavl` is just a maintened version of `tm2/pkg/iavl`,
which has received numerous improvements and bug fixes over the years.


In addition to the benefit of making Gno IBC-ready, this change also
eliminates some drawbacks of `tm2/pkg/iavl`:
- `tm2/pkg/iavl` uses the legacy `range-proof` under the hood which is
considered unsafe. It has an exploited vulnerability (see DragonFruit
[[1](https://github.com/cosmos/iavl/issues/584)][[2](https://forum.cosmos.network/t/cosmos-sdk-security-advisory-dragonfruit/7614)])
- `tm2/pkg/iavl` proof generation is buggy: see
gnolang#4369

This change only concerns the proof system. The Gno light client realm
which is the other important piece of the IBCv2 connection between
Gnoland and AtomOne is still under progress
[here](gnolang#4655).

> [!IMPORTANT]
> This
[change](https://github.com/gnolang/gno/pull/4656/files#diff-4f1d80300014eb607e44892f6ebdcc31de2c0815669acd54f805b83501311b7fL419)
to the commit info hashing is causing a app hash mismatch when
restarting a node with a binary built from this branch.
> ```
> panic: state.AppHash does not match AppHash after replay. Got
> 76BB396891B9F4415AC49FB72CF81933F407AE6A2C04551814719C9A908B2E8E,
expected
8EDAB60FFD0B2C6BB5AC398417CF0AFBFE6E7D491C830F831F9395DB7FAC522A.
> ```
> Unfortunately without it some tests are failing because ics23 does not
expect to have hashed value. As a result, upgrading a mainnet launched
using `tm2/pkg/iavl` to a new version with `cosmos/iavl` might be
challenging. It's probably a good idea to merge this change for the
initial mainnet.


## For reviewers

- Most of the diff is related to the `DB` interface, because most of
declared methods return an error in `comos/iavl`
- When possible I added a comment for change related to the difference
between `tm2/pkg/iavl` and `cosmos/iavl` implementation.
- Lazy loading has been removed in `cosmos/iavl` so I had no other
choice than removing the option from the Gno store. Anyway this feature
was not used.

---------

Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
Co-authored-by: Miloš Živković <milos.zivkovic@tendermint.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🌐 tendermint v2 Issues or PRs tm2 related

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants