Closed jakubgs closed 4 years ago
This is the C implementation of Mersenne Twister which the Chance library uses: https://github.com/ESultanik/mtwister So in theory we could try using that to get the same results in Go.
I tried comparing different implementations of Mersenne Twister from different languages with the same seed(123
) to see if I can get the same thing, and I was unable to:
Library | Language | Method | Result |
---|---|---|---|
ESultanik/mtwister | C | genRandLong() |
-297355222 |
seehuhn/mt19937 | Go | Int31() |
1345184524 |
seehuhn/mt19937 | Go | Uint32() |
2690369049 |
seehuhn/mt19937 | Go | Int63() |
5777523539921853504 |
seehuhn/mt19937 | Go | Uint64() |
5777523539921853504 |
mersenne-twister | JS | random_int() |
2991312382 |
mersenne-twister | JS | random_int31() |
1495656191 |
mersenne-twister | JS | random_long() |
0.6964691855978616 |
chance | JS | integer() |
3539274234331136 |
So I'm really confused as how this is supposed to be deterministic....
Igor did make an implementation already for a bot in Go(which I was told about by Andrea) right here: https://github.com/status-im/status-go-bots/blob/ethdenver-bot/vendor/github.com/status-im/status-go/sdk/three_word_name.go I'm gonna try adding this to the repo in a PR.
I am thinking about dropping Mersenne Twister in favor of something much simpler, fibonacci lfsr https://en.wikipedia.org/wiki/Linear-feedback_shift_register , we don't need anything sophisticated for this I believe, and it should be trivial to port in other languages.
here's for the initial implementation https://github.com/status-im/status-protocol-go/compare/feature/gfycat?expand=1
Also because v1 will be breaking, there's no issue in changing username scheme.
I agree, as I said in OP, it's a good idea to take this opportunity and to switch to something simpler. I was talking about this with @oskarth and @jarradh yesterday and they had some mild complaints, but if we double team them it should be fine. Wish you were here with us.
What are these mild complaints? I would totally go for a simpler version. What @cammellos proposed seems pretty neat.
Well, we can ask them directly:
@oskarth & @jarradh, do you have any specific objections to using V1 as an opportunity to get rid of the weird JS library for 3 word username generation and going with Fibonacci LFSR (for example)?
No specific objections! As long as we can implement the same algo in different code bases. All for simplifying while we have a clean break
One proposal sounded like same seed would generate different names in JS and Go land, which would be bad. That's all.
This is being handled by https://github.com/status-im/status-protocol-go/pull/74 which awaits testing with status-react
in https://github.com/status-im/status-react/pull/9006.
Closing since https://github.com/status-im/status-protocol-go/pull/74 was merged.
Turns out we haven't ported the code that generates the 3 word usernames from JavaScript yet. This code lives here: https://github.com/status-im/status-js-api/blob/master/src/utils.ts And uses this JS package for its deterministic randomness: https://github.com/chancejs/chancejs
This package implements it's own version of Mersenne Twister algorithm for generating 32bit
int
s: https://github.com/chancejs/chancejs/blob/220cb36f/chance.js#L7406-L7440There is a Go version of the Chance library but it doesn't generate the same usernames. I also found a similar implementation of the Mersenne Twister called mt19937 but that produces only random
int64
: https://github.com/seehuhn/mt19937/blob/cc7708819/mt19937.go#L107-L132We could try to reproduce the version of randomness from the JS library, which would probably be a real pain in the ass. Or we could just say "fuck it" - since there's no continuity between Beta and V1 accounts - and just use an existing solution like that
mt19937
library.