From 3694d358332efc2e14f7fc7d9df694ab19fcae9c Mon Sep 17 00:00:00 2001 From: Gregor Date: Mon, 8 Jan 2024 16:35:34 +0100 Subject: [PATCH 1/7] start debugging dex example --- src/examples/zkapps/dex/dex.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/examples/zkapps/dex/dex.ts b/src/examples/zkapps/dex/dex.ts index 8bf5a1ea8f..0f81f0a0c3 100644 --- a/src/examples/zkapps/dex/dex.ts +++ b/src/examples/zkapps/dex/dex.ts @@ -441,16 +441,16 @@ class TokenContract extends SmartContract { 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.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); From 1e06cfcb76a4a9faf4d1ea333e8cbf0a4bd57439 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 12:53:56 +0100 Subject: [PATCH 2/7] helper to print account update layout --- src/lib/account_update.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/account_update.ts b/src/lib/account_update.ts index 23f5e66c08..f04bcbdab7 100644 --- a/src/lib/account_update.ts +++ b/src/lib/account_update.ts @@ -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 || ''}, ${ + 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(); From 0612d09d49a0a19ac2783355545731a655401b07 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 12:55:46 +0100 Subject: [PATCH 3/7] fix the damn bug --- src/lib/account_update.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/account_update.ts b/src/lib/account_update.ts index f04bcbdab7..b24b32354b 100644 --- a/src/lib/account_update.ts +++ b/src/lib/account_update.ts @@ -1347,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) From 4eda5c910f016d88bf64ce1543935bdd5ef30b2d Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 13:00:28 +0100 Subject: [PATCH 4/7] [dex] remove obsolete scare comments --- src/examples/zkapps/dex/dex.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/examples/zkapps/dex/dex.ts b/src/examples/zkapps/dex/dex.ts index 0f81f0a0c3..44ac6b5178 100644 --- a/src/examples/zkapps/dex/dex.ts +++ b/src/examples/zkapps/dex/dex.ts @@ -440,10 +440,6 @@ 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)); From ed42a3ff49de63c289a16f3a8620ba11fbbfb67e Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 13:00:37 +0100 Subject: [PATCH 5/7] minor example tweak --- src/examples/simple_zkapp.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/examples/simple_zkapp.ts b/src/examples/simple_zkapp.ts index 26f379770d..bd17d6eae4 100644 --- a/src/examples/simple_zkapp.ts +++ b/src/examples/simple_zkapp.ts @@ -91,6 +91,8 @@ if (doProofs) { console.time('compile'); await SimpleZkapp.compile(); console.timeEnd('compile'); +} else { + SimpleZkapp.analyzeMethods(); } console.log('deploy'); From 68417419e9e5b387473526245f28df32a5943fd3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 13:21:40 +0100 Subject: [PATCH 6/7] changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd76e3380e..cd308145b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 370a43c79d185dbe6eb80e75770ecf9edb5e6fd8 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 11 Jan 2024 13:26:44 +0100 Subject: [PATCH 7/7] vk regression --- tests/vk-regression/vk-regression.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/vk-regression/vk-regression.json b/tests/vk-regression/vk-regression.json index 2f69465d55..2d93692c67 100644 --- a/tests/vk-regression/vk-regression.json +++ b/tests/vk-regression/vk-regression.json @@ -63,7 +63,7 @@ } }, "TokenContract": { - "digest": "346c5ce0416c2479d962f0868825b4bcbf68f5beac5e7a93632013a6c57d1be8", + "digest": "f97dbbb67a72f01d956539b9f510633c0f88057f5dfbad8493e8d08dc4ca049", "methods": { "init": { "rows": 655, @@ -86,8 +86,8 @@ "digest": "240aada76b79de1ca67ecbe455621378" }, "approveUpdateAndSend": { - "rows": 2321, - "digest": "b1cff49cdc3cc751f802b4b5aee53383" + "rows": 3102, + "digest": "77efc708b9517c16722bad9cca54eb9c" }, "transferToAddress": { "rows": 1044, @@ -103,8 +103,8 @@ } }, "verificationKey": { - "data": "AAAVRdJJF0DehjdPSA0kYGZTkzSfoEaHqDprP5lbtp+BLeGqblAzBabKYB+hRBo7ijFWFnIHV4LwvOlCtrAhNtk/Ae0EY5Tlufvf2snnstKNDXVgcRc/zNAaS5iW43PYqQnEYsaesXs/y5DeeEaFxwdyujsHSK/UaltNLsCc34RKG71O/TGRVVX/eYb8saPPV9W5YjPHLQdhqcHRU6Qq7hMEI1ejTXMokQcurz7jtYU/P56OY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"13796172868423455932596117465273580383420853883879480382066094121613342871544" + "data": "AAAVRdJJF0DehjdPSA0kYGZTkzSfoEaHqDprP5lbtp+BLeGqblAzBabKYB+hRBo7ijFWFnIHV4LwvOlCtrAhNtk/Ae0EY5Tlufvf2snnstKNDXVgcRc/zNAaS5iW43PYqQnEYsaesXs/y5DeeEaFxwdyujsHSK/UaltNLsCc34RKG71O/TGRVVX/eYb8saPPV9W5YjPHLQdhqcHRU6Qq7hMEI1ejTXMokQcurz7jtYU/P56OYekAREejgrEV38U82BbgJigOmh5NhgGTBSAhJ35c9XCsJldUMd5xZiua9cWxGOHm0r7TkcCrV9CEPm5sT7sP7IYQ5dnSdPoi/sy7moUPRitxw7iGvewRVXro6rIemmbxNSzKXWprnl6ewrB2HTppMUEZRp7zYkFIaNDHpvdw4dvjX6K/i527/jwX0JL4BideRc+z3FNhj1VBSHhhvMzwFW6aUwSmWC4UCuwDBokkkBtUE0YYH8kwFnMoWWAlDzHekrxaVmxWRS0lvkr8IDlsR5kyq8SMXFLgKJjoFr6HZWE4tkO/abEgrsK1A3c9F5r/G2yUdMQZu8JMwxUY5qw7D09IPsUQ63c5/CJpea8PAHbUlzRl2KhAhm58JzY0th81wwK0uXhv2e0aXMoEpM0YViAu+c/32zmBe6xl97uBNmNWwlWOLEpHakq46OzONidU3betWNXGJbS4dC4hTNfWM956bK+fwkIlwhM3BC+wOai+M0+y9/y/RSI8qJkSU3MqOF9+nrifKRyNQ3KILqIyR7LjE0/Z/4NzH7eF3uZTBlqfLdf8WhXdwvOPoP1dCx1shF6g4Hh9V4myikRZBtkix1cO5FLUNLNAFw+glg1PB1eA+4ATFuFcfMjxDpDjxqCFCyuQ5TaLuNfYMA7fiO0vB6yqtWgSmCOlD/MQqAhHYRMq4PXk3TUQSle8XBZ67T0+gENjIJleTRgZFG6PgIEwHXcsKIvfFAPklTlnY+5sNVw8yBisVaFgw36DrHWNavWvsZM5HwD0h1Wk0hkavjEIb8rcV72g0u/pc/DJiHd3yJ8v6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QVb3fnCy5h28Dce3Q2WzjBSZFhe3iADZpo7gWHM/sqe+Mbnbn8A+RRWVNbtjss9376jN73zV4xPH3un3VjTxrzCluqR8MbH8t7mhPBqV5CslmSIbDNruVXtwCf4VS1nssw63PfLzeOSvzhTTsg82rna/+TKl1RIwhD8VFnCDq/Rk8fdy/+K5qP6GcSTbh6J8ERx4jOOukL9TUCpJkhvo/3ED8GOewmWAwzL8avXuf9AFvhwH3ENp5v4IIGBljuDJ77vckGmTI=", + "hash": "20215142001741862869723990740096021895498505655157925381074115836190155964997" } }, "Dex": {