-
Notifications
You must be signed in to change notification settings - Fork 10
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
Prevent account permissions for receive and access from being changed #58
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import { | ||
AccountUpdate, | ||
AccountUpdateForest, | ||
assert, | ||
Bool, | ||
DeployArgs, | ||
Field, | ||
Int64, | ||
MerkleList, | ||
method, | ||
Permissions, | ||
PublicKey, | ||
Reducer, | ||
State, | ||
state, | ||
Struct, | ||
TokenContract, | ||
Types, | ||
UInt64, | ||
UInt8, | ||
} from "o1js" | ||
|
@@ -127,10 +130,29 @@ export class FungibleToken extends TokenContract implements FungibleTokenLike { | |
this.emitEvent("Transfer", new TransferEvent({ from, to, amount })) | ||
} | ||
|
||
private permissionEquals(p1: Types.AuthRequired, p2: Types.AuthRequired) { | ||
return p1.constant | ||
.equals(p2.constant) | ||
.and(p1.signatureNecessary.equals(p2.signatureNecessary)) | ||
.and(p1.signatureSufficient.equals(p2.signatureSufficient)) | ||
} | ||
|
||
private checkPermissionsUpdate(update: AccountUpdate) { | ||
let permissions = update.update.permissions | ||
|
||
let { access, receive } = permissions.value | ||
let accessIsNone = this.permissionEquals(access, Permissions.none()) | ||
let receiveIsNone = this.permissionEquals(receive, Permissions.none()) | ||
let updateAllowed = accessIsNone.and(receiveIsNone) | ||
|
||
assert(updateAllowed.or(permissions.isSome.not())) | ||
} | ||
|
||
@method | ||
async approveBase(updates: AccountUpdateForest): Promise<void> { | ||
this.paused.getAndRequireEquals().assertFalse() | ||
this.checkZeroBalanceChange(updates) | ||
this.forEachUpdate(updates, (update, _usesToken) => this.checkPermissionsUpdate(update)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do it like the wMina example and combine the logic into a single call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's a good point! I'll change that. |
||
} | ||
|
||
@method.returns(UInt64) | ||
|
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.
nice 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.
Thanks!