Skip to content

Commit

Permalink
Merge pull request #1364 from o1-labs/fix/prover-bug-reloaded
Browse files Browse the repository at this point in the history
Fix in-circuit hashing of complex account update layouts
  • Loading branch information
mitschabaude authored Jan 11, 2024
2 parents 9f41c77 + 370a43c commit e5bac80
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased](https://github.com/o1-labs/o1js/compare/08ba27329...HEAD)

### Fixed

- Fix approving of complex account update layouts https://github.com/o1-labs/o1js/pull/1364

## [0.15.2](https://github.com/o1-labs/o1js/compare/1ad7333e9e...08ba27329)

### Fixed

- Fix bug in `Hash.hash()` which always resulted in an error. https://github.com/o1-labs/o1js/pull/1346
- Fix bug in `Hash.hash()` which always resulted in an error https://github.com/o1-labs/o1js/pull/1346

## [0.15.1](https://github.com/o1-labs/o1js/compare/1ad7333e9e...19115a159)

Expand Down
2 changes: 2 additions & 0 deletions src/examples/simple_zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ if (doProofs) {
console.time('compile');
await SimpleZkapp.compile();
console.timeEnd('compile');
} else {
SimpleZkapp.analyzeMethods();
}

console.log('deploy');
Expand Down
18 changes: 7 additions & 11 deletions src/examples/zkapps/dex/dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,13 @@ class TokenContract extends SmartContract {
to: PublicKey,
amount: UInt64
) {
// TODO: THIS IS INSECURE. The proper version has a prover error (compile != prove) that must be fixed
this.approve(zkappUpdate, AccountUpdate.Layout.AnyChildren);

// THIS IS HOW IT SHOULD BE DONE:
// // approve a layout of two grandchildren, both of which can't inherit the token permission
// let { StaticChildren, AnyChildren } = AccountUpdate.Layout;
// this.approve(zkappUpdate, StaticChildren(AnyChildren, AnyChildren));
// zkappUpdate.body.mayUseToken.parentsOwnToken.assertTrue();
// let [grandchild1, grandchild2] = zkappUpdate.children.accountUpdates;
// grandchild1.body.mayUseToken.inheritFromParent.assertFalse();
// grandchild2.body.mayUseToken.inheritFromParent.assertFalse();
// approve a layout of two grandchildren, both of which can't inherit the token permission
let { StaticChildren, AnyChildren } = AccountUpdate.Layout;
this.approve(zkappUpdate, StaticChildren(AnyChildren, AnyChildren));
zkappUpdate.body.mayUseToken.parentsOwnToken.assertTrue();
let [grandchild1, grandchild2] = zkappUpdate.children.accountUpdates;
grandchild1.body.mayUseToken.inheritFromParent.assertFalse();
grandchild2.body.mayUseToken.inheritFromParent.assertFalse();

// see if balance change cancels the amount sent
let balanceChange = Int64.fromObject(zkappUpdate.body.balanceChange);
Expand Down
29 changes: 28 additions & 1 deletion src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,37 @@ class AccountUpdate implements Types.AccountUpdate {
return { accountUpdate, calls };
}

toPrettyLayout() {
let indent = 0;
let layout = '';
let i = 0;

let print = (a: AccountUpdate) => {
layout +=
' '.repeat(indent) +
`AccountUpdate(${i}, ${a.label || '<no label>'}, ${
a.children.callsType.type
})` +
'\n';
i++;
indent += 2;
for (let child of a.children.accountUpdates) {
print(child);
}
indent -= 2;
};

print(this);
return layout;
}

static defaultAccountUpdate(address: PublicKey, tokenId?: Field) {
return new AccountUpdate(Body.keepAll(address, tokenId));
}
static dummy() {
return new AccountUpdate(Body.dummy());
let dummy = new AccountUpdate(Body.dummy());
dummy.label = 'Dummy';
return dummy;
}
isDummy() {
return this.body.publicKey.isEmpty();
Expand Down Expand Up @@ -1321,6 +1347,7 @@ class AccountUpdate implements Types.AccountUpdate {
accountUpdate.body.mayUseToken.inheritFromParent.assertFalse();
return;
}
accountUpdate.children.callsType = { type: 'None' };
let childArray: AccountUpdatesLayout[] =
typeof childLayout === 'number'
? Array(childLayout).fill(AccountUpdate.Layout.NoChildren)
Expand Down
10 changes: 5 additions & 5 deletions tests/vk-regression/vk-regression.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
},
"TokenContract": {
"digest": "346c5ce0416c2479d962f0868825b4bcbf68f5beac5e7a93632013a6c57d1be8",
"digest": "f97dbbb67a72f01d956539b9f510633c0f88057f5dfbad8493e8d08dc4ca049",
"methods": {
"init": {
"rows": 655,
Expand All @@ -86,8 +86,8 @@
"digest": "240aada76b79de1ca67ecbe455621378"
},
"approveUpdateAndSend": {
"rows": 2321,
"digest": "b1cff49cdc3cc751f802b4b5aee53383"
"rows": 3102,
"digest": "77efc708b9517c16722bad9cca54eb9c"
},
"transferToAddress": {
"rows": 1044,
Expand All @@ -103,8 +103,8 @@
}
},
"verificationKey": {
"data": "AAAVRdJJF0DehjdPSA0kYGZTkzSfoEaHqDprP5lbtp+BLeGqblAzBabKYB+hRBo7ijFWFnIHV4LwvOlCtrAhNtk/Ae0EY5Tlufvf2snnstKNDXVgcRc/zNAaS5iW43PYqQnEYsaesXs/y5DeeEaFxwdyujsHSK/UaltNLsCc34RKG71O/TGRVVX/eYb8saPPV9W5YjPHLQdhqcHRU6Qq7hMEI1ejTXMokQcurz7jtYU/P56OYekAREejgrEV38U82BbgJigOmh5NhgGTBSAhJ35c9XCsJldUMd5xZiua9cWxGOHm0r7TkcCrV9CEPm5sT7sP7IYQ5dnSdPoi/sy7moUPRitxw7iGvewRVXro6rIemmbxNSzKXWprnl6ewrB2HTppMUEZRp7zYkFIaNDHpvdw4dvjX6K/i527/jwX0JL4BideRc+z3FNhj1VBSHhhvMzwFW6aUwSmWC4UCuwDBokkkBtUE0YYH8kwFnMoWWAlDzHekrxaVmxWRS0lvkr8IDlsR5kyq8SMXFLgKJjoFr6HZWE4tkO/abEgrsK1A3c9F5r/G2yUdMQZu8JMwxUY5qw7D09IPsUQ63c5/CJpea8PAHbUlzRl2KhAhm58JzY0th81wwK0uXhv2e0aXMoEpM0YViAu+c/32zmBe6xl97uBNmNWwlWOLEpHakq46OzONidU3betWNXGJbS4dC4hTNfWM956bK+fwkIlwhM3B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v0QGZTOxQORosVshOP2eFQ1VMKGWOpCVvyi8QE4fa+gOgYT0JRm4rkQBZ5WDlYGkamD3euC92Kd7Z39G89h/AqeFACahkAW1a78SzLW69mZ+CDLfKp/xQsi2TWgJqGh7QNOEtMnn/2owLzLWd071mvUtT0484Eqx6hUqLJMH70p8oUjQIMsh0mvp1BWSU8XC6z+UZIpVm2CERrV8BMLmTLOgTNJlEIJQR7zzpJCDFNNOI+Y2ZtdcuU8XHgcsQhQ3PgCACFAWN3rO+goXoTWdYR/LcqszKzPnMArmPIHWkRM6Mkm13OsHXCVudUbqQjC/pNQZH1VW+RMXnre1vQVb3fnCy5h28Dce3Q2WzjBSZFhe3iADZpo7gWHM/sqe+Mbnbn8A+RRWVNbtjss9376jN73zV4xPH3un3VjTxrzCluqR8MbH8t7mhPBqV5CslmSIbDNruVXtwCf4VS1nssw63PfLzeOSvzhTTsg82rna/+TKl1RIwhD8VFnCDq/Rk8fdy/+K5qP6GcSTbh6J8ERx4jOOukL9TUCpJkhvo/3ED8GOewmWAwzL8avXuf9AFvhwH3ENp5v4IIGBljuDJ77vckGmTI=",
"hash": "13796172868423455932596117465273580383420853883879480382066094121613342871544"
"data": "AAAVRdJJF0DehjdPSA0kYGZTkzSfoEaHqDprP5lbtp+BLeGqblAzBabKYB+hRBo7ijFWFnIHV4LwvOlCtrAhNtk/Ae0EY5Tlufvf2snnstKNDXVgcRc/zNAaS5iW43PYqQnEYsaesXs/y5DeeEaFxwdyujsHSK/UaltNLsCc34RKG71O/TGRVVX/eYb8saPPV9W5YjPHLQdhqcHRU6Qq7hMEI1ejTXMokQcurz7jtYU/P56OYekAREejgrEV38U82BbgJigOmh5NhgGTBSAhJ35c9XCsJldUMd5xZiua9cWxGOHm0r7TkcCrV9CEPm5sT7sP7IYQ5dnSdPoi/sy7moUPRitxw7iGvewRVXro6rIemmbxNSzKXWprnl6ewrB2HTppMUEZRp7zYkFIaNDHpvdw4dvjX6K/i527/jwX0JL4BideRc+z3FNhj1VBSH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8gfhIa4VEJyyI2joqJeIc7vMZFWhquSFHNs0TZKvKLiSAsyNDrpWZb/1PHxziswKvisk296AJi7hmlM1pKx6S4LlbT2OKLXbgq5HUKfe8QhxG4aOsPSSiVGwvnCrIPdSxLq77M27UWXnXHC8mmJmOsGUFj+bdX/u6AgrBhw/w74dDbuNEpC80PbJTuglF/TeDryYsFWCrBnF/WPstgzy3zDDTZ3DXHVYVxOEvErIynlQEY9Cv9QSxRI3dA+hLtob/L78ZeJSU4Al+Qv0QGZTOxQORosVshOP2eFQ1VMKGWOpCVvyi8QE4fa+gOgYT0JRm4rkQBZ5WDlYGkamD3euC92Kd7Z39G89h/AqeFACahkAW1a78SzLW69mZ+CDLfKp/xQsi2TWgJqGh7QNOEtMnn/2owLzLWd071mvUtT0484Eqx6hUqLJMH70p8oUjQIMsh0mvp1BWSU8XC6z+UZIpVm2CERrV8BMLmTLOgTNJlEIJQR7zzpJCDFNNOI+Y2ZtdcuU8XHgcsQhQ3PgCACFAWN3rO+goXoTWdYR/LcqszKzPnMArmPIHWkRM6Mkm13OsHXCVudUbqQjC/pNQZH1VW+RMXnre1vQVb3fnCy5h28Dce3Q2WzjBSZFhe3iADZpo7gWHM/sqe+Mbnbn8A+RRWVNbtjss9376jN73zV4xPH3un3VjTxrzCluqR8MbH8t7mhPBqV5CslmSIbDNruVXtwCf4VS1nssw63PfLzeOSvzhTTsg82rna/+TKl1RIwhD8VFnCDq/Rk8fdy/+K5qP6GcSTbh6J8ERx4jOOukL9TUCpJkhvo/3ED8GOewmWAwzL8avXuf9AFvhwH3ENp5v4IIGBljuDJ77vckGmTI=",
"hash": "20215142001741862869723990740096021895498505655157925381074115836190155964997"
}
},
"Dex": {
Expand Down

0 comments on commit e5bac80

Please sign in to comment.