-
Notifications
You must be signed in to change notification settings - Fork 133
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
Dex happy path #484
Dex happy path #484
Conversation
…all `exists` in checked mode
Happy path without proving works! Only TODO for this PR that I see is to investigate & potentially remove the unexpected account updates in redeemLiquidity And fix composability test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments to help reviewing!
}; | ||
let ctx = snarkContext.get(); | ||
let fields = | ||
inCheckedComputation() && !ctx.inWitnessBlock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change improves Circuit.witness
in two ways:
- it doesn't throw an error when used outside the circuit
- it doesn't create another witness block when already inside one
@@ -1003,18 +1009,30 @@ Circuit.constraintSystem = function <T>(f: () => T) { | |||
return result; | |||
}; | |||
|
|||
Circuit.log = function (...args: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the log function requested in #489
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great addition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
@@ -227,21 +227,6 @@ interface Mina { | |||
) => { hash: string; actions: string[][] }[]; | |||
} | |||
|
|||
interface MockMina extends Mina { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this interface wasn't exported and having it internally just made updating LocalBlockchain more annoying.
General philosophy: Let TS just infer types if it can, instead of writing out return types (unless we want to change something about the return type on purpose). This is less work, leads to more accurate types, and better for users because they can see the type instead of its name
@@ -1028,6 +1026,17 @@ class AccountUpdate implements Types.AccountUpdate { | |||
} | |||
return accountUpdate; | |||
} | |||
static attachToTransaction(accountUpdate: AccountUpdate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will sometimes (but rarely) need to be called if something is done in a transaction block without calling methods, because we stopped implicitly attaching the account update to the transaction when this.self
is called (which led to bugs). Being in the spirit of less opaqueness.
TODO: is this a good name / API?
@@ -702,6 +702,7 @@ class SmartContract { | |||
} | |||
this.setValue(this.self.update.permissions, Permissions.default()); | |||
this.sign(zkappKey); | |||
AccountUpdate.attachToTransaction(this.self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we can see an example where we need explicit attaching of an account update to the transaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, just left a few questions :)
tx = await Mina.transaction(userKey, () => { | ||
// pay fees for creating 2 token contract accounts, and fund them so each can create 1 account themselves | ||
let feePayerUpdate = AccountUpdate.createSigned(userKey); | ||
feePayerUpdate.balance.subInPlace(accountFee.mul(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for multiplying it times one? Probably not, just curious tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no there isn't :D it was copied from another place where it was multiplied by 2 I guess
@@ -58,6 +64,7 @@ class Dex extends SmartContract { | |||
let isXZero = dexXBalance.equals(UInt64.zero); | |||
let xSafe = Circuit.if(isXZero, UInt64.one, dexXBalance); | |||
|
|||
// FIXME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! reminds us to fix it
@@ -1003,18 +1009,30 @@ Circuit.constraintSystem = function <T>(f: () => T) { | |||
return result; | |||
}; | |||
|
|||
Circuit.log = function (...args: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great addition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I just had some minor comments/questions.
tx = await Mina.transaction(userKey, () => { | ||
// pay fees for creating user's token X account | ||
AccountUpdate.createSigned(userKey).balance.subInPlace(accountFee.mul(1)); | ||
// 😈😈😈 mint any number of tokens to our account 😈😈😈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the comment emojis ha!
@@ -9,9 +16,9 @@ import { | |||
} from './dex.js'; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason you created a separate arbitrary_token_interaction.ts
file and this run.ts
file? Is the goal to only execute the run.ts
file in CI and not the arbitrary_token_interaction.ts
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes -- this arbitrary_token_interaction.ts
file is a reproduction of that token protocol bug I found yesterday. so, it's an example of an interaction that actually shouldn't be possible. I'd like to come back to this when the bug is fixed and make a test from it or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that makes sense. Maybe we should document the file with this info so we don't forget later on.
@@ -1003,18 +1009,30 @@ Circuit.constraintSystem = function <T>(f: () => T) { | |||
return result; | |||
}; | |||
|
|||
Circuit.log = function (...args: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
This PR finishes the happy path of the first DEX version, without proofs. Proofs currently run into an exotic Pickles error when executing "redeemLiquidity". We checked that the account update structures created by the DEX methods make sense and are as expected.
This also
Circuit.log
function (use like console.log) to removeCircuit.asProver
boilerplate when debugging,lazyAuthorization
#482