Skip to content
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

Feat/u512 #128

Merged
merged 42 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f3f6b79
init
dovgopoly Jan 9, 2025
9d6d09c
rm comments
dovgopoly Jan 9, 2025
c8c57db
wip
dovgopoly Jan 15, 2025
ba239ee
wip
dovgopoly Jan 15, 2025
3720814
fixed add & added test
dovgopoly Jan 16, 2025
a8a79a5
wip (passed ecdsa check) 17.8kk
dovgopoly Jan 16, 2025
c698a36
fix
dovgopoly Jan 16, 2025
85a2c36
opt
dovgopoly Jan 17, 2025
de6382b
-500k
Arvolear Jan 17, 2025
31a36eb
15.8kk 2p
dovgopoly Jan 17, 2025
4e00dc7
15.3kk
dovgopoly Jan 17, 2025
7facbab
rm shl 15.48kk
dovgopoly Jan 17, 2025
32a9716
wip
dovgopoly Jan 20, 2025
9efa52b
wip
dovgopoly Jan 20, 2025
2c5dd2d
added test vectors, tests are failed
dovgopoly Jan 20, 2025
ce83623
fixed ecdsa512 impl 22.2kk
dovgopoly Jan 21, 2025
8f7deb4
20.4kk
dovgopoly Jan 21, 2025
007dc1c
added assert
dovgopoly Jan 21, 2025
e650ce3
small fixes
dovgopoly Jan 21, 2025
85684f1
refactored
dovgopoly Jan 21, 2025
57f0f8d
typo
dovgopoly Jan 21, 2025
6db5141
added crazy optimization with bit skipping 20.1kk
dovgopoly Jan 21, 2025
b9462a7
13.86kk & typos
dovgopoly Jan 21, 2025
288f0c1
remove opt 384 libs
mllwchrry Jan 23, 2025
b3cffd6
add tests for U512
mllwchrry Jan 23, 2025
5df79f0
add natspec
mllwchrry Jan 24, 2025
82a88c0
add operator overloading
mllwchrry Jan 24, 2025
936c966
modify moddiv test
mllwchrry Jan 24, 2025
5b188af
rm ops and fixed tests
dovgopoly Jan 26, 2025
cfc730b
added assign & call & bitwise ops
dovgopoly Jan 26, 2025
c1c7cd8
added modexpU256 & tested gas
dovgopoly Jan 26, 2025
0aaa9fe
typo
dovgopoly Jan 26, 2025
52672ed
small adjustments
dovgopoly Jan 26, 2025
d87784e
add U512 usage example and fix tests
mllwchrry Jan 27, 2025
bbca148
fix natspec
mllwchrry Jan 27, 2025
4b65a75
fixed comment
dovgopoly Jan 27, 2025
bf130be
add toBytes to natspec
mllwchrry Jan 27, 2025
66ba3e1
typos
dovgopoly Jan 27, 2025
d5a813c
typos
dovgopoly Jan 27, 2025
0a427dc
typos
dovgopoly Jan 27, 2025
8dd88d9
small adjustments
dovgopoly Jan 28, 2025
d053dd7
update readme
Arvolear Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
modify moddiv test
mllwchrry committed Jan 24, 2025
commit 936c96676503049d3129c060cb8e00fecef399a4
28 changes: 19 additions & 9 deletions test/libs/bn/U512.test.ts
Original file line number Diff line number Diff line change
@@ -108,6 +108,17 @@ describe("U512", () => {
return toBytes((((aBn - bBn) % mBn) + mBn) % mBn);
}

function moddiv(a: string, b: string, m: string) {
const aBigInt = ethers.toBigInt(a);
const mBigInt = ethers.toBigInt(m);

const bInv = modinv(b, m);

const result = (aBigInt * ethers.toBigInt(bInv)) % mBigInt;

return toBytes(result);
}

before(async () => {
const U512Mock = await ethers.getContractFactory("U512Mock");

@@ -303,15 +314,14 @@ describe("U512", () => {
it("moddiv test", async () => {
const m = toBytes(prime);

const a = toBytes(779149564533142355434093157610126726613246737199n);
const b = toBytes(29118654464229156312755475164902924590603964377702716942232927993582928167089n);

const to = randomU512();

const expected = toBytes(30823410400962253491978005949535646087432096635784775122170630924100507445065n);
for (let i = 0; i < 100; ++i) {
const a = randomU512();
const b = randomU512();
const to = randomU512();

expect(await u512.moddiv(a, b, m)).to.equal(expected);
expect(await u512.moddivAssign(a, b, m)).to.equal(expected);
expect(await u512.moddivAssignTo(a, b, m, to)).to.equal(expected);
expect(await u512.moddiv(a, b, m)).to.be.equal(moddiv(a, b, m));
expect(await u512.moddivAssign(a, b, m)).to.be.equal(moddiv(a, b, m));
expect(await u512.moddivAssignTo(a, b, m, to)).to.be.equal(moddiv(a, b, m));
}
});
});