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

Bug when claiming bonds in the case of multiple answers on reality #310

Open
kongzii opened this issue Aug 9, 2024 · 2 comments
Open

Bug when claiming bonds in the case of multiple answers on reality #310

kongzii opened this issue Aug 9, 2024 · 2 comments

Comments

@kongzii
Copy link

kongzii commented Aug 9, 2024

According to Realitio docs, only the latest history hash is stored in the question struct:

Empty  Bytes32 + Answer + Bond + Answerer + False -> History Hash 1
History Hash 1 + Answer + Bond + Answerer + False -> History Hash 2
History Hash 2 + Answer + Bond + Answerer + False -> History Hash 3 <- stored in Questions struct

If multiple answers were submitted, and we query them on subgraph, we can see it:

Screenshot by Dropbox Capture

All the returned history hashes are the same. (it's this question)

And that's why the following code https://github.com/kongzii/trader/blob/main/packages/valory/skills/market_manager_abci/graph_tooling/requests.py#L297:

answers = [
            {
                "args": {
                    "answer": bytes.fromhex(answer["answer"][2:]),
                    "question_id": bytes.fromhex(answer["question"]["questionId"][2:]),
                    "history_hash": bytes.fromhex(
                        answer["question"]["historyHash"][2:]
                    ),
                    "user": Web3.to_checksum_address(answer["question"]["user"]),
                    "bond": int(answer["bondAggregate"]),
                    "timestamp": int(answer["timestamp"]),
                    "is_commitment": False,
                }
            }
            for answer in raw_answers
]

submits invalid hashes if there are multiple different answers and claiming of bonds fails.

@gabrielfior
Copy link

gabrielfior commented Aug 9, 2024

Here's what I know
-> Subgraph only serves the latest history hash (not all previous history hashes)
-> If there's a second answer, what happens?
a. Second answer is correct - market creator will try to claim bond, unsuccessful (OK, as its answer was wrong)
b. Second answer is incorrect - market creator will try to claim bond, unsucessful (NOT OK, because its answer was correct and claim should have been possible, but history hash will not match the one from the answer)
In conclusion, fetching history_hash from the subgraph is not working for this. My understanding is that responses should be queried, since they contain the different history_hash corresponding to each new answer.

@kongzii
Copy link
Author

kongzii commented Aug 30, 2024

We fixed it in our repo at gnosis/prediction-market-agent-tooling#368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants