-
Notifications
You must be signed in to change notification settings - Fork 6
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
Research Which Exponent Library is Safest and Cheapest #4
Comments
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 320.0 DAI (320.0 USD @ $1.0/DAI) attached to it.
|
Issue Status: 1. Open 2. Cancelled Workers have applied to start work. These users each claimed they can complete the work by 3 weeks, 6 days ago. 1) benschza has applied to start work (Funders only: approve worker | reject worker). Having recently looked at the Babylonian method and Bakhshali method for calculating square roots, I believe I have the right context to get started on this problem! There will be some shared value too, because the results of these tests will determine which method we should use in our bonding curve implementation. Initial questions:
Learn more on the Gitcoin Issue Details page. |
Hey @BenSchZA - @nanspro gets precedent as we have worked with him before. But obviously, I back you hard to also produce some interesting results here, especially if you're coding to SAfrican Jazz, so will payout the same bounty to you if you also work on this and submit some tests and an efficient implementation as described above.
FWIW, I reckon this is the best bet from the links above: https://github.com/extraterrestrial-tech/fixidity/blob/master/contracts/ExponentLib.sol#L40 for what we need, but would love to see some other methods and compare gas costs if possible. |
Thanks for the vote of confidence @andytudhope! What else does one code to, but SA Jazz? If capacity allows I'll see what results I can produce within the allocated time. |
@nanspro Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
1 similar comment
@nanspro Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
Hey @andytudhope , In the end we have implemented two SQRT algorithms:
The first one is the standard Newton's method. This method use division in order to get the fraction approximation. Here we had a problem -> Vyper has decimals, but the fraction is rounded to 10th symbol. That is why we implemented another more unknown-algorithm The second algorithm is from: http://www.afjarvis.staff.shef.ac.uk/maths/jarvisspec02.pdf If you need to have a high SQRT precision use the second method. Both methods: We are returning to Solidity uint256(number with 18 symbols) which in case of tokens perfectly works for us. Example Result: I hope this will be useful for you. :) |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done @nanspro due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
1 similar comment
Issue Status: 1. Open 2. Started 3. Submitted 4. Done @nanspro due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
Hi @andytudhope. I started creating a Jupyter notebook to test the efficiency of some of the nth root algorithms. Decided to take this approach because Python has great tools for testing a visualizing efficiency. Haven't had as much time as I'd have liked to work on this in my own time, but happy to share it and work on it further. |
Yeah, please do share it when you're happy to! Am sure it'd help not only me, but also the one and only @bakasura980 ❤️ |
@andytudhope I just came across this comparison for 4 nth root algorithms implemented in CPP - assuming they can be converted to work with Solidity and its float limitations, it might be useful: https://www.boost.org/doc/libs/1_69_0/libs/math/doc/html/math_toolkit/root_comparison/root_n_comparison.html ~ The Newton-Raphson method seems to come out top in terms of execution time, how that translates to Solidity gas use will need to be tested :) |
@andytudhope what do you need ? nth root algorithm or SQRT algorithm, I got confused 😅. If SQRT will work for you, I could make a comparison between Newton and SQRT_HFP algorithms and provide you strengths, weaknesses, gas cost and etc. ? |
It's nth root that we really need, as the calculation is |
Given that these are all Counting Numbers, I'm assuming you're ok with approximations? Can we bound in integer space rather than unint? |
Will post my brain-dump of a Jupyter Notebook later today. Nth root is looking pretty inefficient, depending on the range of |
|
Hey @andytudhope sorry for the inactivity but i was very busy with college work and other intern commitments, I think @BenSchZA has already done a lot of work here and will probably finish this so no point of me jumping on this now. |
@andytudhope Can I assume you meant |
@BenSchZA no, what I wrote is correct. The
@nanspro no problem brother, thanks for letting me know and good luck with all that work 👍 |
If the exponent is not a fraction, which So could you not scale all values by a set number of decimal points, such as the usual default of
|
The description definitely says exponent problem, I think I just led myself astray with the mention of nth root 👍 |
Yeah, I know it's really an exponent problem (hence the shape of the curve and "the genius" of the whole game setup), but here's the issue. If we take your line of thinking:
If I'm wrong about how accurate we can be, let's just go with something similar to the above and write tests to check the sh*t out of ourselves. |
Of course, I can almost get there in vyper (cc @bakasura980), like
but one does not implicitly convert |
That does look promising (and dense). I'll take a look! Any specific issues/progress on that front yet? |
Yeah, take a look here for all progress from here on out 👍 |
Issue Status: 1. Open 2. Cancelled The funding of 320.0 DAI (320.0 USD @ $1.0/DAI) attached to this issue has been cancelled by the bounty submitter
|
The next step in writing this contract is to swap out all the current mathematical operations for safer ones that actually work in Solidity.
The core piece of work here is to figure out the best and cheapest way to calculate
v_minted = d.available ** (1/d.rate)
given that there is no floating point arithmetic in Solidity. A fractional exponent is the equivalent of a square root, so we need a gas-efficient library that will help us achieve this. Look intohttps://github.com/dydxprotocol/protocol/blob/master/contracts/lib/Exponent.sol
and
https://github.com/extraterrestrial-tech/fixidity
to see which one is cheaper, as well as looking for other alternatives. Bancor has an interesting approach too: https://github.com/bogatyy/bancor/blob/master/solidity/BancorFormula.sol#L270 but I suspect that, because our exponent is dynamic, using a static table is not going to be the solution here.
Other Resources
Babylonian method: https://ethereum.stackexchange.com/questions/2910/can-i-square-root-in-solidity
Taylor Series: https://en.wikipedia.org/wiki/Taylor_series
Newton-Raphson: https://ethereum.stackexchange.com/questions/38468/calculate-the-nth-root-of-an-arbitrary-uint-using-solidity?rq=1
Easter Egg: https://en.wikipedia.org/wiki/Fast_inverse_square_root
The text was updated successfully, but these errors were encountered: