-
Notifications
You must be signed in to change notification settings - Fork 183
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
Expand math fingerprinting #36
Comments
const bigN = 586084736227728400000000000000000000000
Math.sin(Math.PI)
// FF => 1.2246467991473532e-16
// TB => 1.2246063538223773e-16
Math.sin(bigN)
// FF => 0.994076732536068
// TB => -0.20876350121720488 |
I've thought about using polyfills, but it appears there are some cases where the engine/arch/os computation differs from the polyfill. Example: // exmp1: false in Safari
(Math.exp(1) - 1) == Math.expm1(1)
// sinh: false in Safari
((Math.exp(Math.PI) - 1 / Math.exp(Math.PI)) / 2) == Math.sinh(Math.PI)
// atanh: false in Firefox, Chrome, Safari
n = 9e-8
(Math.log((1 + n) / (1 - n)) / 2) == Math.atanh(n)
// hypot from https://github.com/MaxArt2501/es6-math/blob/master/es6-math.js
// false in Chrome and Safari
function hypot(value1, value2) {
let i, n = 0, args = arguments, len = args.length
for (i = 0; i < len; i++) {
n += args[i] * args[i]
}
return Math.sqrt(n)
}
let n = 5.860847362277284e+38
hypot(n, n) == Math.hypot(n, n) |
That's exactly what we want to be doing - it adds more entropy :) |
I like this idea. |
Some interesting finds through attempts to mimic pow expected = 2.5600000000000008e-62
// polyfill 1
// true in FF, Chrome, and Safari
x = 2e-8;[...Array(3)].forEach((val, i) => x*=x)
x == expected
// native Math.pow(2e-8,8)
// false in Chrome (yields 2.5600000000000003e-62)
Math.pow(2e-8, 8) == expected
// native exponentiation operator 2e-8**8
// ** is equivalent to Math.pow() and implementation-dependent
// false in Chrome (yields 2.5600000000000003e-62)
2e-8**8 == expected
// polyfill 2
// false in FF, Chrome, and Safari (yields 2.5600000000000003e-62)
2e-8*2e-8*2e-8*2e-8*2e-8*2e-8*2e-8*2e-8 == expected
// polyfill 3: altering the operation order changes the result
// true in FF, Chrome, and Safari
2e-8*2e-8*2e-8*2e-8*(2e-8*2e-8*2e-8*2e-8) == expected |
From what I gather, the entropy obtained through a polyfill (if any) can be reduced to testing the implementation-dependent methods: |
There's nice short list of es6 functions at https://github.com/MaxArt2501/es6-math/blob/master/README.md#usage |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
tests: https://es6console.com/kcvb8uvr/
Diff Tester:
https://jsfiddle.net/w3cqtsj1/ (consumes memory)
Polyfills:
https://jsfiddle.net/gz48qutr/14/
The text was updated successfully, but these errors were encountered: