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 uo #28

Merged
merged 17 commits into from
Aug 21, 2017
Merged

Fix uo #28

merged 17 commits into from
Aug 21, 2017

Conversation

Georgi87
Copy link
Contributor

@Georgi87 Georgi87 commented Aug 10, 2017

A fix for the front running issue in the UO discovered by @niran

(For some reason I cannot add you as reviewer @niran. I guess because you are not part of the Gnosis organization?)

@Georgi87 Georgi87 requested a review from cag August 10, 2017 06:06
cag
cag previously approved these changes Aug 10, 2017
Copy link
Contributor

@cag cag left a comment

Choose a reason for hiding this comment

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

totalAmount >= totalOutcomeAmounts[_outcome]
spreadMultiplier >= 2 >= 1

maxAmount = sM * (tA - tOA[i]) - tOA[i] == sM * tA - (sM + 1) * tOA[i] >= 0 when
tA >= ((sM + 1) / sM)  *  tOA[i]

Edit: originally, I had a minus instead of a plus sign, and that caused my math to say that this expression would work no matter what, but I've since corrected that.

Copy link
Contributor

@cag cag left a comment

Choose a reason for hiding this comment

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

Oops =___= I made an error in my analysis. Lemme see if there is still an edge case.

@cag
Copy link
Contributor

cag commented Aug 10, 2017

Okay, so (totalAmount - totalOutcomeAmounts[_outcome]).mul(spreadMultiplier) could be less than totalOutcomeAmounts[_outcome] if somebody was already voting for an outcome which is far enough in the lead, like if somebody voted for the challenge outcome immediately after the outcome was set. In that case, the oracle would reject the transaction instead of doing a 0 transaction, which is what would happen if a person over-committed to a vote. However, these seem to be analogous situations to me.

I recommend adding a test section under the challenge:

        // Sender 1 tries to increase their bid but can't
        await etherToken.deposit({value: 50, from: accounts[sender1]})
        await etherToken.approve(ultimateOracle.address, 50, { from: accounts[sender1] })
        await ultimateOracle.voteForOutcome(2, 50, { from: accounts[sender1] })
        assert.equal(await ultimateOracle.outcomeAmounts(accounts[sender1], 2), 100)

And clamping the subtraction so the maxAmount gets set to 0 when the subtraction would underflow.

@cag cag dismissed their stale review August 10, 2017 17:24

I made a mistake

@niran
Copy link

niran commented Aug 10, 2017

Looks good to me! That additional test is a good idea.

@Georgi87
Copy link
Contributor Author

Thank you both for checking, I will add the test.

@Georgi87
Copy link
Contributor Author

Georgi87 commented Aug 16, 2017

Added a test for this @cag

The transaction throws, because the .sub method throws.

@codecov-io
Copy link

codecov-io commented Aug 16, 2017

Codecov Report

Merging #28 into master will increase coverage by 0.22%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
+ Coverage   84.78%   85.01%   +0.22%     
==========================================
  Files          25       25              
  Lines         631      634       +3     
  Branches      105      106       +1     
==========================================
+ Hits          535      539       +4     
+ Misses         96       95       -1
Impacted Files Coverage Δ
contracts/Oracles/UltimateOracle.sol 100% <100%> (+1.96%) ⬆️
contracts/Markets/StandardMarket.sol 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 85a5077...e979337. Read the comment docs.

@cag cag requested a review from puellavulnerata August 18, 2017 15:18
@cag cag merged commit aef17cc into master Aug 21, 2017
@cag cag deleted the fix_uo branch August 21, 2017 14:58
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

Successfully merging this pull request may close these issues.

5 participants