Skip to content

Commit

Permalink
Updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
br0wnD3v committed Aug 12, 2024
1 parent f74fc2c commit 6dd14ee
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 32 deletions.
29 changes: 24 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
{
"version": 1,
"deployAliases": {
"devnet": {
"verify": {
"networkId": "testnet",
"url": "https://api.minascan.io/node/devnet/v1/graphql",
"keyPath": "keys/devnet.json",
"feepayerKeyPath": "/home/botvenom/.cache/zkapp-cli/keys/deployer.json",
"feepayerAlias": "deployer",
"fee": "0.1"
"keyPath": "keys/verify.json",
"feepayerKeyPath": "/home/botvenom/.cache/zkapp-cli/keys/bd3v_deployer.json",
"feepayerAlias": "bd3v_deployer",
"fee": "0.1",
"smartContract": "VerifyAggregationProofGenerated"
},
"doot": {
"networkId": "testnet",
"url": "https://api.minascan.io/node/devnet/v1/graphql",
"keyPath": "keys/doot.json",
"feepayerKeyPath": "/home/botvenom/.cache/zkapp-cli/keys/bd3v_deployer.json",
"feepayerAlias": "bd3v_deployer",
"fee": "0.1",
"smartContract": "Doot"
},
"registry": {
"networkId": "testnet",
"url": "https://api.minascan.io/node/devnet/v1/graphql",
"keyPath": "keys/registry.json",
"feepayerKeyPath": "/home/botvenom/.cache/zkapp-cli/keys/bd3v_deployer.json",
"feepayerAlias": "bd3v_deployer",
"fee": "0.1",
"smartContract": "Registry"
}
}
}
3 changes: 0 additions & 3 deletions deployments/info.json

This file was deleted.

47 changes: 41 additions & 6 deletions src/Aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import {
export class PriceAggregationArray20 extends Struct({
pricesArray: Provable.Array(UInt64, 20),
count: UInt64,
}) {}
export class PriceAggregationArray100 extends Struct({
pricesArray: Provable.Array(UInt64, 100),
count: UInt64,
}) {}
}) {
constructor(value: { pricesArray: UInt64[]; count: UInt64 }) {
super(value);
// Ensure the array has exactly 20 elements
while (value.pricesArray.length < 20) {
value.pricesArray.push(UInt64.from(0));
}
if (value.pricesArray.length > 20) {
value.pricesArray = value.pricesArray.slice(0, 20);
}
}
}

export const AggregationProgram20 = ZkProgram({
name: 'doot-prices-aggregation-program',
Expand All @@ -27,7 +34,27 @@ export const AggregationProgram20 = ZkProgram({
privateInputs: [],

async method(publicInput: PriceAggregationArray20) {
return UInt64.from(0);
return publicInput.pricesArray[0]
.add(publicInput.pricesArray[1])
.add(publicInput.pricesArray[2])
.add(publicInput.pricesArray[3])
.add(publicInput.pricesArray[4])
.add(publicInput.pricesArray[5])
.add(publicInput.pricesArray[6])
.add(publicInput.pricesArray[7])
.add(publicInput.pricesArray[8])
.add(publicInput.pricesArray[9])
.add(publicInput.pricesArray[10])
.add(publicInput.pricesArray[11])
.add(publicInput.pricesArray[12])
.add(publicInput.pricesArray[13])
.add(publicInput.pricesArray[14])
.add(publicInput.pricesArray[15])
.add(publicInput.pricesArray[16])
.add(publicInput.pricesArray[17])
.add(publicInput.pricesArray[18])
.add(publicInput.pricesArray[19])
.div(publicInput.count);
},
},
generateAggregationProof: {
Expand Down Expand Up @@ -65,6 +92,11 @@ export const AggregationProgram20 = ZkProgram({
},
});

export class PriceAggregationArray100 extends Struct({
pricesArray: Provable.Array(UInt64, 100),
count: UInt64,
}) {}

export const AggregationProgram100 = ZkProgram({
name: 'doot-prices-aggregation-program100',
publicInput: PriceAggregationArray100,
Expand Down Expand Up @@ -198,6 +230,9 @@ export class AggregationProof100 extends ZkProgram.Proof(
AggregationProgram100
) {}

await AggregationProgram100.compile();
await AggregationProgram20.compile();

export class VerifyAggregationProofGenerated extends SmartContract {
init() {
super.init();
Expand Down
7 changes: 0 additions & 7 deletions src/Doot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ describe('Doot.js', () => {
expect(onChainCommitment).toEqual(expected);
});

it(`Should set inital oracle to ${oracle}`, async () => {
const onChainOracle = dootZkApp.deployerPublicKey.get();
const expected = oracle;

expect(onChainOracle).toEqual(expected);
});

it(`Should set inital secret to 0`, async () => {
const onChainSecret = dootZkApp.secret.get();
const expected = Field.from(0);
Expand Down
15 changes: 6 additions & 9 deletions src/Doot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ export class Doot extends SmartContract {
@state(Field) commitment = State<Field>();
@state(Field) secret = State<Field>();
@state(IpfsCID) ipfsCID = State<IpfsCID>();
@state(PublicKey) deployerPublicKey = State<PublicKey>();
@state(OffchainStateCommitments) offchainState = State(
OffchainStateCommitments.empty()
);

init() {
super.init();
this.deployerPublicKey.set(this.sender.getUnconstrained());
}

@method async initBase(
Expand All @@ -46,7 +44,6 @@ export class Doot extends SmartContract {
pricesArray: PricesArray,
updatedSecret: Field
) {
this.deployerPublicKey.getAndRequireEquals();
this.secret.getAndRequireEquals();
this.commitment.getAndRequireEquals();
this.ipfsCID.getAndRequireEquals();
Expand Down Expand Up @@ -168,7 +165,6 @@ export class Doot extends SmartContract {
pricesArray: PricesArray,
secret: Field
) {
this.deployerPublicKey.getAndRequireEquals();
this.secret.getAndRequireEquals();
this.commitment.getAndRequireEquals();
this.ipfsCID.getAndRequireEquals();
Expand Down Expand Up @@ -290,11 +286,12 @@ export class Doot extends SmartContract {
await offchainState.settle(proof);
}

@method async verify(signature: Signature, Price: Field) {
this.deployerPublicKey.getAndRequireEquals();
const validSignature = signature.verify(this.deployerPublicKey.get(), [
Price,
]);
@method async verify(
signature: Signature,
deployer: PublicKey,
Price: Field
) {
const validSignature = signature.verify(deployer, [Price]);
validSignature.assertTrue();
}
}
1 change: 1 addition & 0 deletions src/Registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('Registry', () => {
updatedGithub,
updatedIpfs,
implementation,
deployer,
secret
);
})
Expand Down
1 change: 1 addition & 0 deletions src/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Registry extends SmartContract {
updatedGithubLink: SourceCodeGithub,
updatedIPFSLink: SourceCodeIPFS,
updatedImplementation: PublicKey,
deployer: PublicKey,
secret: Field
) {
this.githubSourceLink.getAndRequireEquals();
Expand Down
2 changes: 1 addition & 1 deletion src/aggregation_main.ts → src/mains/aggregation_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
AggregationProof100,
PriceAggregationArray100,
VerifyAggregationProofGenerated,
} from './Aggregation.js';
} from '../Aggregation.js';

function testJsonRoundtrip<
P extends Proof<any, any>,
Expand Down
2 changes: 1 addition & 1 deletion src/doot_main.ts → src/mains/doot_main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Doot, IpfsCID, PricesArray, offchainState } from './Doot.js';
import { Doot, IpfsCID, PricesArray, offchainState } from '../Doot.js';

import {
Mina,
Expand Down
2 changes: 2 additions & 0 deletions src/mains/registry_main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Registry } from '../Registry';
import { MultiPackedStringFactory } from 'o1js-pack';

0 comments on commit 6dd14ee

Please sign in to comment.