Comments (6)
If I may ask, how much of this functionality is working right?
I am in need of a BigInt library as well, but there was none to be found.
I am attempting to make one myself, but I am unfamiliar with these algorithms so progress has been very slow.
I have tested the powMod, multMod, and mod in the online Solidity compiler and they are not producing the expected result.
Am I using them incorrectly?
from cypherpoker.
I've put off working on this library indefinitely as I've discovered that I can achieve similar results using Solidity's mulmod. I stopped working on powMod which currently appears to be experiencing overflows (https://github.com/monicanagent/cypherpoker/blob/master/ethereum/solidity/BigInt.sol), although the conversion to/from BigInt and basic math functions seem to work fine.
If you're looking to achieve modular exponentiation within 256 bits then the following function works well (all of my testing has been successful):
function modExp(uint256 base, uint256 exp, uint256 mod) internal returns (uint256 result) {
result = 1;
for (uint count = 1; count <= exp; count *= 2) {
if (exp & count != 0)
result = mulmod(result, base, mod);
base = mulmod(base, base, mod);
}
}
This function runs through at most "exp" loops so it's fairly efficient but it should be noted that at 256 loops "count" resets back to 0, effectively causing an infinite loop. That means that you can only use values that are 255 bits or shorter. With the following modifications you may be able to squeeze in all 256 bits but I haven't tested this yet:
function modExp(uint256 base, uint256 exp, uint256 mod) internal returns (uint256 result) {
result = 1;
for (uint count = 1; count <= exp; (count = (count*2)-1)) {
if (exp & (count+1) != 0)
result = mulmod(result, base, mod);
base = mulmod(base, base, mod);
}
}
As long as you can work with modulo values that are within the (2^256)-1 range you can use practically unlimited exponent sizes simply by calling the modExp function repeatedly. For example, using the exponents a and b:
(((m^a) mod P)^b) mod P) = (m^ab) mod P
If each of our exponents is smaller than (2^256)-1 then we can chain our results to produce the same result as if we'd done one calculation using a single composite exponent, ab, effectively increasing our exponent to any arbitrary size (as long as we can provide enough gas to cover the calculations). You can find more details here
from cypherpoker.
I was hoping to work with 1024-bits for the base, exponential, and modulo values.
Bummer :(
Though for my application, only mulmod is needed. PowMod would have been nice, but it not necessary.
So I was wondering if mod and mulmod was working?
Mod gave me erroneous results and mulmod caused the online compiler to crash.
Great work though, I am hoping to implement the more efficient algorithms from this library and Leemon's JS library that this one is based off.
P.S. Here is my current work, it is pretty bad though.
EDIT: Link fixed
from cypherpoker.
Hey, I know this is an old thread but I built out a full bigint library for Solidity: https://github.com/zcoinofficial/solidity-BigNumber/
from cypherpoker.
This looks great! Thanks for sharing it; I'll definitely have a further look into your big number contracts.
from cypherpoker.
No problem, I intend to get it added to EthPM and Consensys live-libs soon, and to get it properly audited. It's pretty well tested as is
from cypherpoker.
Related Issues (20)
- [Game] Add warning/prevention dialog when attempting to join table with insufficient Ether HOT 1
- [Game] Add runtime checks and workarounds for ".air" export HOT 1
- [Game] Add runtime checks and workarounds for ".swf" export HOT 1
- [Game] Add runtime checks and workarounds for mobile export
- [Game] Add configuration options for Ethereum client RPC-API address and port HOT 1
- [Game] Implement global/game settings update functionality HOT 1
- [Game] Add Slider component to renderer
- [Game] Add "dealer button" graphic to players top bar
- [Game] Add player bets / chips information to player top bar
- [Game] Add handler(s) to Ethereum integration to indicate account lock/unlock status
- [Game] Add account copy-to-clipboard button to Ethereum Account Widget
- [Game] Add all-in functionality / side pots
- [Game] Update blinds and betting order for heads-up play
- [Game] Implement customizable startup window dimensions
- [Game] Revise table list UI
- [Game] Add check for in-use smart contracts during table creation
- [Game] Implement password-protected tables
- [Game] Implement direct-to-table URLs
- [Game] Implement UI theme switching
- actionscript only ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypherpoker.