Question 1: solidity
1- Program a super simple “Hello World” smart contract: store an unsigned integer
and then retrieve it. Please clearly comment your code. Once completed, deploy the
smart contract on Remix. Include the .sol file and a screenshot of the Remix UI once
deployed in your final submission pdf (more info about submission formatting
below).
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
//This is basic helloworld contract
contract Helloworld
//unsigned integer field
uint field;//function for storing data
function saveValue(uint newValue) public {field = newValue;//function for retrieving data function getValue() public view returns (uint) {return field}

2- On the documentation page, the “Ballot” contract demonstrates a lot of features
on Solidity. Read through the script and try to understand what each line of code is
doing, then implement the Possible Improvements by reducing the number of
transactions in the “giveRightToVote” function while maintaining the same
functionality of the program.
Solution 1:
To reduce the number of transactions in the “giveRightToVote” function WITH maintaining the same
functionality of the program we can instead of just one address at a time. That way we can assign
voting rights to multiple voters in one transaction and save some gas fee by creating a data
structure “array” and pass it to the “giveRightToVote” function
/**
- create an array of all voters (their addresses) and
- pass that array to the “giveRightToVote” function
*/ function giveRightToVote(address[] memory votersToAssign) public {
require(
msg.sender == chairperson,
“Only chairperson can give right to vote.”); - for(uint i=0; i < votersToAssign.length; i ++){
require( !voters[votersToAssign[i]].voted,
“The voter already voted.”);
require(voters[votersToAssign[i]].weight == 0);
voters[votersToAssign[i]].weight = 1;
} }
Solution 2: - (zk rollups; just a thought)
I read the contract but not sure should I treat it as in the case the “chairperson” is the point of trust
and what it would be the case in a scenario of resolving disputes, a stake can be leveraged to maintain
vote delegation integrity
to reduce the number of transactions in the “giveRightToVote” function while maintaining the same
functionality of the program. In the original case the right to vote is assigned by the chair person
one address at a time and that consumes gas every time a transaction initiated but its essential to
change the state each time to maintain integrity of delegation, I guess in other way we can use a
layer2 solution to force the chair person to generate a proof maintain the integrity of each
transaction/vote and we can bundle and verify the finale state of layer2 onto layer 1 by creating a
data structure “array” and pass it to the “giveRightToVote” function on layer 2 smart contract and
pass the whole state as a one transaction/one address to the smart contract in layer one, in that
scenario its risk free that the chair person can maliciously censorship any of the voters.
- Deploy your script on Remix and compare the difference in gas fees between the
original script and the improved script when giving 10 voters the right to vote. Once
completed, submit (1) your improved version of the contract as an .sol file with
comments describing the changes you made, and (2) screenshots (before and after) of
the gas fees for the transaction(s) to give 10 voters the right to vote.
Before Improvements: (gas : 44757/vote)
The original “giveRightToVote” function accepts one address as a parameter, and gives a right for a
vote to only one person at a time. The transaction cost is 44757 gas.

After Improvements: (gas : 27597/vote )
In case of assigning the right to vote for 5 people using an array of addresses for the function to accept
the gas decreased drastically from 44757 gas to 27597 gas for a total of 137985/5 votes

Question 2: Writing circuits with Circom
Introduction:
I can see that zkuniversity tries to introduces us to circom and snarkjs, circom is used to build circuits
to be used into Zero-Knowledge proofs and snarkjs is an independent implementation of snarks
protocol fully written in javascript.
What circuits do?
It takes a both a private input and a public input and runs a Statement Deterministic Program Circuit
and finally emits an output, so the prover runs the circuit and generates a proof, given the proof and
both public input/output, I can proof to the verifier that who generated that proof knew the private
input and executed the circuit, alongside the proof does not reveal anything about the private input.

A simple circuit logic:
I like to think about circom circuits as electronic circuts consists of gates (logical) connected with wires
(inputs/outputs) to build a constraints system, in order to manifest a truth table, the circom circuits
semantics and syntax is architectueed as templates and signals
in the above example:
1) we define template NAND()
2) we define signals S1,S2 (inputs) and S3 (output)
3) and the constraints : we assign S3 as 1-s1s2
- Briefly describe signals, templates, components, constraints, and why we use
Circom for ZK.
Why we use circom for zk?
Circom is mainly DSL “Domain Specific Languge” is very easy to write circuits bottom-up and compose
complex circuits from simple circuits to express ideas as a proof, is a language designed to write
arithmetic circuits that can be used in zero knowledge proofs. In particular, it is designed to work in
zksnarks JavaScript library.
Circom language features:
Circuit target is R1CS type “because R1CS historically has been the circuit for the fastest prrof systems”
, Its of type HDL “Hardware Description Language” it describes the layout of the circuit explicitly as
building wires connecting gates and doing that through a library but doing it through a dedicating
language, it doesn’t feature mutable variable so user cant use it as a mutable state, and features Field
primitive types so you can proof over fields themselves but dont have access to booleans or machine
integers, but dont features “IF statements” on the contrary to cairo, and also don’t features
UserStructures as its basically a HDL, it works with arrays but only supports constant indices “arrays
you only going to access them on constant locations”
Signals:
The arithmetic circuits built using circom operate on signals, which contain field elements in Z/pZ.
Signals are immutable. Once they have a value assigned, this value cannot be changed.
Templates:
Represent a mechanism to create generic circuits in Circom. They represent the shape of a circuit.
Templates check certain conditions that are written as constraints. they can call other templates and
use internal helper signals. There must be one main template.
Components:
A component another abstraction of templates for ease use, as such, it receives N input signals and
produces M output signals and K intermediate signalsn Components are immutable (like signals).
Constraints:
Are arithmetic expressions that accept input signals and their result is the output signal. They define
arithmetic circuits logic.
All constraints must be quadratic of the form A*B + C = 0, where A, B and C are linear
combinations of signals. - For the following truth table, what is the constraint system? Hint: your answer should be a simple equation relating x1 and x2 to y. Solution: the truth tables: It represents the logical “and” operator ( y <= x1 * x2)
- Using open source resources like circomlib, define, compile, and prove a circuit that
checks if a number is less than 10.
First : as we are going to use snarks as its faster than starks but the downside is it requires a trusted
setup like the following. - Start a new powers of tau ceremony:
- Contribute to the ceremony and provide entropy:






