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

compress user data #39

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 3 additions & 5 deletions hardhat/contracts/verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,12 @@ contract Verifier {
}

function verifyUserData(
uint8[32] memory _userData,
bytes memory _userData,
uint32[8] memory _memRootBefore,
uint32[8] memory _memRootAfter
) public pure returns (uint256) {
uint256 userData = 0;
for (uint256 i = 0; i < 32; i++) {
userData |= uint256(_userData[i]) << (8 * (31 - i));
}
bytes32 userData = sha256(_userData);

uint256 memRootBefore = 0;
for (uint256 i = 0; i < 8; i++) {
memRootBefore |= uint256(_memRootBefore[i]) << (32 * (7 - i));
Expand Down
7 changes: 6 additions & 1 deletion hardhat/test/Verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ describe('Verifier', function () {

const memBefore = data.slice(0, 8);
const memAfter = data.slice(8, 16);
const userData = data.slice(16, 48);
// bincode user data
let userData = new Uint8Array(16);
userData[0] = 8;
const subData = ethers.toUtf8Bytes('12345678');
userData.set(subData, 8);

const result = await verifier.verifyUserData(userData, memBefore, memAfter);

const snarkProofData = JSON.parse(fs.readFileSync('./test/snark_proof_with_public_inputs.json', 'utf8'));
Expand Down
94 changes: 47 additions & 47 deletions hardhat/test/block_public_inputs.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
{
"public_inputs": [
2645411388,
1918618995,
2268631598,
3183284462,
3815684253,
3953758369,
2551602184,
2652146175,
3962388252,
1005663092,
3551977212,
2177403159,
1305914519,
1209071037,
3218163367,
2719638513,
49,
50,
51,
52,
53,
"public_inputs":[
1380951869,
239922150,
1747502278,
3199536443,
2750757822,
4242399953,
2221649883,
1272338940,
1889331786,
4147100095,
1014626113,
3289204812,
3195022193,
3332098556,
1718484747,
2961728694,
230,
245,
247,
227,
157,
46,
250,
46,
138,
54,
55,
219,
217,
215,
255,
60,
0,
75,
194,
233,
78,
191,
73,
39,
56,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
90,
202,
124,
214,
139,
21,
251,
205,
7296770697235859686,
14901092621598462682,
872906789517051880,
Expand Down
2 changes: 1 addition & 1 deletion hardhat/test/snark_proof_with_public_inputs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Proof":{"Ar":{"X":"16349475433919184449376139834002043178637600221014601000516138741713461301694","Y":"7805244456018210287230655160528566410925066697076917826072898921230257026121"},"Krs":{"X":"5784749582197176868591746957584229953845261480804832102898076454284637131090","Y":"14341156713565859834390298358664931486388362679817715748104395840371449820913"},"Bs":{"X":{"A0":"12240533202613844214465357071048553540876223164147929523953631035263615462770","A1":"8079895101352593282771900424944714713613302060023173497423004513383989936974"},"Y":{"A0":"209086305796689487866454825068961888629604727511471188147775562562871362637","A1":"8612984748855499443632459563702985083024717632582589300033628435315756937869"}},"Commitments":[{"X":"17699761404969230255279415853526103725628337982994872527601821957444905166955","Y":"7219321304793754962848359126102612308116111013386635949811426598886231860327"}],"CommitmentPok":{"X":"4879772352977014307378965044945728744403879330095244232088081622339754075965","Y":"11281366430195181572749591381505383889687980730853519889283709424200129768462"}},"PublicWitness":["3353355750137778279073368176179104458200357789932889866317858435397393381372","15648512900330230795392620242926018784963194272102423444327306418594528647298"]}
{"Proof":{"Ar":{"X":"7770581961456683194439566354330342830233791029955217321968926018582649657149","Y":"20239899792058519207037360069147708142187160656820197974855571461545908355209"},"Krs":{"X":"17994256184306063236700994540599437832866312520803319363100330592826185326303","Y":"12543300686044794510755760358389017171822900279162027664523653957808136613667"},"Bs":{"X":{"A0":"5936134582421470921242827313450104698754772242160104410548955162714142538645","A1":"17441194492374078669061633997219229605324946761354342713206456109849288539532"},"Y":{"A0":"12032232687900811355743080247343572009381988688460794593288681723278313992014","A1":"18779790676479714209936358447847604283093331157761278224661914877151417648115"}},"Commitments":[{"X":"15548023973502623049711480725635875008509417049314960798953842123579957709455","Y":"11790903872064165561102951625964618604273089536967958814557126593705656215938"}],"CommitmentPok":{"X":"11731724392651112280501000547285404061781069166330628519247291990348812479822","Y":"3580411210227037957215448100373720333877502528698901110354252085057791971127"}},"PublicWitness":["4723783147812920290037440184140205795578331144140274603640391060373642456465","17476388237640769581838811489172240981847761100869998586086565643371833075453"]}
94 changes: 47 additions & 47 deletions testdata/mips/block_public_inputs.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
{
"public_inputs": [
2645411388,
1918618995,
2268631598,
3183284462,
3815684253,
3953758369,
2551602184,
2652146175,
3962388252,
1005663092,
3551977212,
2177403159,
1305914519,
1209071037,
3218163367,
2719638513,
49,
50,
51,
52,
53,
"public_inputs":[
1380951869,
239922150,
1747502278,
3199536443,
2750757822,
4242399953,
2221649883,
1272338940,
1889331786,
4147100095,
1014626113,
3289204812,
3195022193,
3332098556,
1718484747,
2961728694,
230,
245,
247,
227,
157,
46,
250,
46,
138,
54,
55,
219,
217,
215,
255,
60,
0,
75,
194,
233,
78,
191,
73,
39,
56,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
90,
202,
124,
214,
139,
21,
251,
205,
7296770697235859686,
14901092621598462682,
872906789517051880,
Expand Down
2 changes: 1 addition & 1 deletion testdata/mips/proof_with_public_inputs.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions verifier/verifier.sol.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,12 @@ contract Verifier {
}

function verifyUserData(
uint8[32] memory _userData,
bytes memory _userData,
uint32[8] memory _memRootBefore,
uint32[8] memory _memRootAfter
) public pure returns (uint256) {
uint256 userData = 0;
for (uint256 i = 0; i < 32; i++) {
userData |= uint256(_userData[i]) << (8 * (31 - i));
}
bytes32 userData = sha256(_userData);

uint256 memRootBefore = 0;
for (uint256 i = 0; i < 8; i++) {
memRootBefore |= uint256(_memRootBefore[i]) << (32 * (7 - i));
Expand Down