Skip to content

Commit

Permalink
feat: adapt verification key check + set local instance
Browse files Browse the repository at this point in the history
  • Loading branch information
iluxonchik committed Apr 30, 2024
1 parent 99cb148 commit 9c9f360
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
18 changes: 14 additions & 4 deletions contracts/src/blockchain/contracts/bounty/BountySC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployArgs, SmartContract, State, state , Permissions, method, Field, PublicKey, AccountUpdate, UInt64} from "o1js";
import { DeployArgs, SmartContract, State, state, Permissions, method, Field, PublicKey, AccountUpdate, UInt64 } from "o1js";
import { ZKLContract } from "../tokens/zkl/ZKLContract";

export class BountySC extends SmartContract {
Expand All @@ -13,9 +13,14 @@ export class BountySC extends SmartContract {
});
}

/**
* Claims the bounty by transferring the ZKL tokens to the claimer's address.
*
* @param zklTokenAddr - The address of the ZKL token contract.
*/
@method claim(zklTokenAddr: PublicKey) {
// ensure that the sender is the claimed one, by requiring a signature
const claimer: PublicKey = this.sender;
const claimer: PublicKey = this.sender;
const ac: AccountUpdate = AccountUpdate.createSigned(claimer);
this.approve(ac);

Expand All @@ -26,8 +31,13 @@ export class BountySC extends SmartContract {
zklTokenSC.sendFromTo(this.address, claimer, balance);
}

@method confirmUsage() {
Field(0).assertEquals(Field(0));
/**
* Asserts that the verification key of the smart contract is the expected one.
* This is done by calling an empty method on the smart contract.
* Method call = Account Update with proof of authorization.
*/
@method assertVerificationKeyIsCorrect() {
// must remain empty. no need for assertions or state changes
}

}
18 changes: 16 additions & 2 deletions contracts/src/blockchain/contracts/experiments/DeployeeSC.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { DeployArgs, PublicKey, SmartContract, State, state , Permissions, method, Field} from "o1js";

/**
* `DeployeeSC` is a smart contract that is deployed by the `BountyBulletinBoardSC` smart contract.
* It represents a specific instance of a bounty.
*
* @property {State<Field>} deployer - The Poseidon.hash() of the public key of the deployer of this smart contract
* @property {State<PublicKey>} funder - The funder of this Bounty. The funder will be able to associate this bounty with a zkLocus proof
*
* @see {@link BountyBulletinBoardSC} for the smart contract that deploys instances of `BountySC`.
*/
export class DeployeeSC extends SmartContract {
// who cares by whom it was deployed as long as it behaves according to the expected interface?
@state(Field) deployer = State<Field>();
@state(PublicKey) bountyMapRoot = State<PublicKey>();
@state(PublicKey) funder = State<PublicKey>();

deploy(args: DeployArgs) {
super.deploy(args);
Expand All @@ -12,8 +22,12 @@ export class DeployeeSC extends SmartContract {
});
}

@method claim() {
// empty (for now)
}

@method confirmUsage() {
// Meant to be empty
// empty
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import { DeployeeSC } from "./DeployeeSC";
*/
export class DeployerVerificationSC extends SmartContract {

@state(Field) expectedVerificationKeyDigest = State<Field>();

deploy(args: DeployArgs) {
super.deploy(args);
this.account.permissions.set({
...Permissions.default(),
});

}

/**
Expand All @@ -33,8 +30,6 @@ export class DeployerVerificationSC extends SmartContract {
const supposedDeployerAddr: Field = deployedSC.deployer.get();
deployedSC.deployer.requireEquals(supposedDeployerAddr);
supposedDeployerAddr.assertEquals(claimedDeployeeAddrDigest);

deployedSC.confirmUsage();

// TODO:
// Verify that the verification key of the SC is the expected one
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AccountUpdate, Field, Mina, Poseidon, PrivateKey, PublicKey, Signature, UInt64 } from "o1js";
import { AccountUpdate, Field, Mina, Poseidon, PrivateKey, PublicKey, UInt64 } from "o1js";
import { ZKLContract } from "../../../../blockchain/contracts/tokens/zkl/ZKLContract";
import { BountyBulletinBoardSC } from "../../../../blockchain/contracts/bounty/BountyBulletinBoardSC";
import { BountySC } from "../../../../blockchain/contracts/bounty/BountySC";

describe('Bounty Bulletin Board Integration', () => {
const Local = Mina.LocalBlockchain();
Local.setProofsEnabled(false);
Mina.setActiveInstance(Local);
let zklSC: ZKLContract;
const deployerPrivateKey: PrivateKey = Local.testAccounts[0].privateKey;
const deployerPublicKey: PublicKey = deployerPrivateKey.toPublicKey();
Expand All @@ -26,7 +27,7 @@ describe('Bounty Bulletin Board Integration', () => {

zklSC = new ZKLContract(zklAppAddress);
const bbbSC: BountyBulletinBoardSC = new BountyBulletinBoardSC(bbbAppAddress);

beforeAll(async () => {
console.log("Compiling smart contracts...");
const startTimeSC = Date.now();
Expand Down

0 comments on commit 9c9f360

Please sign in to comment.