Skip to content

Commit

Permalink
Delete zkcontract.test.ts file & Polish main.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigoto-dev19 committed Feb 1, 2024
1 parent 41d72d9 commit f164d7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/binary-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export {
};

/**
* This type refers to a string that contains a sequence of '0's and '1' which is the binary representation of a number or an UTF-8 encoded native string ty
* This type refers to a string that contains a sequence of '0's and '1's
* which is the binary representation of a number or an UTF-8 encoded native string ty
*/
type BinaryString = string;

Expand All @@ -32,7 +33,7 @@ function uint32ToBinary(input: UInt32): BinaryString {
}

/**
* Convert a BinaryString into Hexadecimal
* Convert a BinaryString into Hexadecimal string
*/
function binaryToHex(x: BinaryString): string {
let result = '';
Expand All @@ -44,7 +45,8 @@ function binaryToHex(x: BinaryString): string {
}

/**
* Convert a BinaryString into an array of o1js Bool type: [Bool(false), Bool(true), Bool(false), Bool(true), Bool(true), Bool(false)]
* Convert a BinaryString into an array of o1js Bool type
* Example: '010110' --> [Bool(false), Bool(true), Bool(false), Bool(true), Bool(true), Bool(false)]
*/
function binaryStringToBoolArray(binaryString: BinaryString): Bool[] {
const boolArray: Bool[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Poseidon,
} from 'o1js';
import { sha256O1js } from './sha256.js';

class Bytes3 extends Bytes(3) {}

// the sha256 digest is poseidon hashed to output a single field that will serve as a publicInput
Expand Down
21 changes: 11 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ const { privateKey: deployerKey, publicKey: deployerAccount } =
const { privateKey: senderKey, publicKey: senderAccount } =
Local.testAccounts[1];

// ----------------------------------------------------

// Create a public/private key pair. The public key is your address and where you deploy the zkApp to
const zkAppPrivateKey = PrivateKey.random();
const zkAppAddress = zkAppPrivateKey.toPublicKey();

// create an instance of Square - and deploy it to zkAppAddress
// create an instance of Sha256ZkApp - and deploy it to zkAppAddress
if (useProof) await Sha256ZkApp.compile();
const zkAppInstance = new Sha256ZkApp(zkAppAddress);

Expand All @@ -29,19 +27,22 @@ const deployTxn = await Mina.transaction(deployerAccount, () => {
});
await deployTxn.sign([deployerKey, zkAppPrivateKey]).send();

// get the initial state of Square after deployment
// fetch the public input of Sha256ZkApp after deployment
const digestInit = zkAppInstance.publicInput.get();
console.log('expected digest:', digestInit.toBigInt());

console.log('expected digest:', digestInit.toString());

// ----------------------------------------------------

/*
- hash the preimage on-chain
- if it is not compliant with the public input the TX will revert!
*/
const txn1 = await Mina.transaction(senderAccount, () => {
const x = Bytes3.fromString('abc');
zkAppInstance.hash(x);
});

await txn1.prove();
await txn1.sign([senderKey]).send();
console.log('txn1: ', txn1.transaction);

console.log('Finished compiling');
// console.log('txn1: ', txn1.toPretty());

console.log('\nFinished compiling');

0 comments on commit f164d7a

Please sign in to comment.