Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("It should profile int", async () => {
const pA = pbInt.alloc();
const pB = pbInt.alloc();
const pC = pbInt.alloc(64);
let start, end, time;
const A = bigInt.one.shiftLeft(256).minus(1);
const B = bigInt.one.shiftLeft(256).minus(1);
pbInt.set(pA, A);
pbInt.set(pB, B);
start = new Date().getTime();
pbInt.test_int_mul(pA, pB, pC, 50000000);
end = new Date().getTime();
time = end - start;
const c1 = pbInt.get(pC, 1, 64);
assert(c1.equals(A.times(B)));
console.log("Mul Time (ms): " + time);
// start = new Date().getTime();
// pbInt.test_int_mulOld(pA, pB, pC, 50000000);
it("It should do various test in zq Snarks modules", async () => {
const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
const f1 = await buildF1(q);
const v= [
q.minus(1),
q.minus(2),
q.minus(1).shiftRight(1),
q.minus(1).shiftRight(1).add(1),
q.minus(1).shiftRight(1).add(2),
q.minus(1).shiftRight(1).minus(1),
q.minus(1).shiftRight(1).minus(2),
bigInt(2),
bigInt.one,
bigInt.zero
];
const pA = f1.allocInt();
const pB = f1.allocInt();
const pC = f1.allocInt();
let c;
for (let i=0; i
const genSalt = (): bigInt.BigInteger => {
const buf = crypto.randomBytes(54)
const salt = bigInt.fromArray(Array.from(buf), 256, false).minus(340)
// 4 * (4^3) + 4 * (4^2) + 4 * (4^1) + 4 * (4^0) = 340
// Only return values greater than the largest possible solution
if (salt.lt(340)) {
return genSalt()
}
return salt
}
testname +
"线程数为" +
threadgeshu +
" " +
"圆周率计算" +
piwei +
"位 " +
"计算圆周率中......" +
" \n"
);
// debugger;
// console.log(outputtext1);
console.log(testname);
console.time(testname);
strt = new Date().getTime();
p = new bigInt(0);
// myworker = [];
// myworker.length = threadgeshu;
finishflag = [];
finishflag.length = threadgeshu;
// if (typeof worker1 == "undefined") {
// worker1 = new Worker("service-worker-mythread1-bigint.js");
// }
// worker1=Array( threadgeshu)
// for (var i = 0, len = threadgeshu; i < len; i++) {
// myworker[i] = worker1;
// }
// var worker1 = Array(threadgeshu);
// myworker =Array(threadgeshu);
// for(var key=0;key< threadgeshu; key++){
// myworker[key]=undefined
// }
arr[index].onmessage = function(event) {
console.log(
"主线程从副线程" + (index + 1) + "接收" + "event.data\n",
event.data
);
// console.log(
// "第一个参数",
// event.data[0],
// "\n第二个参数",
// event.data[1]
// );
var p1 = new bigInt(event.data[0]);
p = bigInt.add(p, p1);
x = Math.max(x, parseInt(event.data[1]));
finishflag[index] = 1;
// threadfinish(btnele);
// currentValue.terminate()
rs(event.data);
};
arr[index].onerror = e => {
arr[index].onmessage = function(event) {
console.log(
"主线程从副线程" + (index + 1) + "接收" + "event.data\n",
event.data
);
// console.log(
// "第一个参数",
// event.data[0],
// "\n第二个参数",
// event.data[1]
// );
var p1 = new bigInt(event.data[0]);
p = bigInt.add(p, p1);
x = Math.max(x, parseInt(event.data[1]));
finishflag[index] = 1;
// threadfinish(btnele);
// currentValue.terminate()
rs(event.data);
};
arr[index].onerror = e => {
confirmNumber_dice(input){
/* Equivalent of solidity hash function:
function confirm(bytes32 _s) public returns(uint256){
return uint256 (sha3(_s));
}
*/
let hash = '0x'+Eth.ABI.soliditySHA3(['bytes32'],[ input ]).toString('hex')
let confirm = bigInt(hash,16).divmod(65536).remainder.value
return confirm
}
confirmNumber_blackjack(input){
async function getStartPositionForEnd() {
try {
const head = await store.readHeadPosition()
// Edge case where start position is 0 (beginning of time) and the stream is empty.
if (head === '0') {
return BigInteger.zero
}
return BigInteger(head).plus(1)
} catch (error) {
logger.error(
'Unable to get stream information. Dropping subscription and disposing.',
error
)
await dropAndDispose()
return BigInteger(-1)
}
}
function toRationals(args) // Takes an array of Objects and returns an array of Rationals
{
var r = new Array(args.length);
for (var i = 0; i < args.length; i++)
{
var v = evaluate_expression(args[i]);
if (v instanceof RationalTerm)
r[i] = v.value;
else if (v instanceof BigIntegerTerm)
r[i] = new Rational(v.value, BigInteger.one);
else if (v instanceof IntegerTerm)
r[i] = new Rational(new BigInteger(v.value), BigInteger.one);
else
throw new Error("Illegal BigInteger conversion from " + v.getClass());
}
return r;
}
if (messages.length === count + 1) {
// We intentionally included another message to see if we are at the end.
// We are not.
isEnd = false
messages.splice(messages.length - 1, 1)
}
const lastMessage = messages[messages.length - 1]
const nextPosition = forward
? BigInteger(lastMessage.position)
.plus(BigInteger.one)
.toString()
: // nextVersion will be 0 at the end, but that always includes the first message in
// the stream. There's no way around this that does not skip the first message.
BigInteger.max(
BigInteger(lastMessage.position).minus(BigInteger.one),
BigInteger(-1)
).toString()
return {
isEnd,
nextPosition,
messages: await maybeFilterExpiredMessages(messages)
}
}