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 panic in handleRPCFormContract #143

Closed
ChrisSchinnerl opened this issue Dec 18, 2024 · 2 comments · Fixed by #145
Closed

Fix panic in handleRPCFormContract #143

ChrisSchinnerl opened this issue Dec 18, 2024 · 2 comments · Fixed by #145
Labels
bug Something isn't working

Comments

@ChrisSchinnerl
Copy link
Member

Ran into a panic on our CI today while fixing tests. The panic is related to handleRPCFormContract.

  go.sia.tech/coreutils/rhp/v4.(*Server).handleRPCFormContract(0xc0011dd700, {0x29c8270, 0xc00013da20})
  	/home/runner/go/pkg/mod/go.sia.tech/[email protected]/rhp/v4/server.go:615 +0x3297
  go.sia.tech/coreutils/rhp/v4.(*Server).handleHostStream(0xc0011dd700, {0x29c8270, 0xc00013da20}, 0xc0011e4180)
  	/home/runner/go/pkg/mod/go.sia.tech/[email protected]/rhp/v4/server.go:1033 +0x2a33
  go.sia.tech/coreutils/rhp/v4.(*Server).Serve.func1()
  	/home/runner/go/pkg/mod/go.sia.tech/[email protected]/rhp/v4/server.go:1103 +0xe5
  created by go.sia.tech/coreutils/rhp/v4.(*Server).Serve in goroutine 997336
  	/home/runner/go/pkg/mod/go.sia.tech/[email protected]/rhp/v4/server.go:1095 +0x126

Seems like the server doesn't sufficiently validate some data received from the client and the client is sending potentially faulty data.

@ChrisSchinnerl ChrisSchinnerl converted this from a draft issue Dec 18, 2024
@ChrisSchinnerl ChrisSchinnerl added the bug Something isn't working label Dec 18, 2024
@ChrisSchinnerl ChrisSchinnerl moved this from Triage to Todo in Sia Dec 18, 2024
@lukechampine
Copy link
Member

My guess is it's coming from here: https://github.com/SiaFoundation/coreutils/blob/b5e84c03d17f6f0f4ea5b7e33078b1db37308d4f/rhp/v4/server.go#L586C1-L596C3

        // update renter input basis to reflect our funding basis
        if basis != req.Basis {
                hostInputs := formationTxn.SiacoinInputs[len(formationTxn.SiacoinInputs)-len(req.RenterInputs)]
                formationTxn.SiacoinInputs = formationTxn.SiacoinInputs[:len(formationTxn.SiacoinInputs)-len(req.RenterInputs)]
                txnset, err := s.chain.UpdateV2TransactionSet([]types.V2Transaction{formationTxn}, req.Basis, basis)
                if err != nil {
                        return errorBadRequest("failed to update renter inputs from %q to %q: %v", req.Basis, basis, err)
                }
                formationTxn = txnset[0]
                formationTxn.SiacoinInputs = append(formationTxn.SiacoinInputs, hostInputs)
        }

Looks like the order is mixed up: the renter inputs are first, followed by the host inputs, so it should be:

        // update renter input basis to reflect our funding basis
        if basis != req.Basis {
---             hostInputs := formationTxn.SiacoinInputs[len(formationTxn.SiacoinInputs)-len(req.RenterInputs)]
---             formationTxn.SiacoinInputs = formationTxn.SiacoinInputs[:len(formationTxn.SiacoinInputs)-len(req.RenterInputs)]
+++             hostInputs := formationTxn.SiacoinInputs[len(req.RenterInputs):]
+++             formationTxn.SiacoinInputs = formationTxn.SiacoinInputs[:len(req.RenterInputs)]
                txnset, err := s.chain.UpdateV2TransactionSet([]types.V2Transaction{formationTxn}, req.Basis, basis)
                if err != nil {
                        return errorBadRequest("failed to update renter inputs from %q to %q: %v", req.Basis, basis, err)
                }
                formationTxn = txnset[0]
                formationTxn.SiacoinInputs = append(formationTxn.SiacoinInputs, hostInputs)
        }

I'm wondering if we even need to be removing the host inputs before updating in the first place, though...?

@ChrisSchinnerl
Copy link
Member Author

That was my initial feeling as well. Deployed a branch with a println within the if and it does indeed print every time we encounter the panic.

@github-project-automation github-project-automation bot moved this from Todo to Done in Sia Dec 18, 2024
ChrisSchinnerl added a commit to SiaFoundation/renterd that referenced this issue Dec 19, 2024
This PR fixes all the NDFs apart from the
[panic](SiaFoundation/coreutils#143 (comment))
which we will need to fix in `coreutils`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants