---
# System prepended metadata

title: Untitled

---

### A. Conceptual Knowledge

Before programming, it is important to know these main concepts. You should be able to explain these concepts to a (smart) five-year-old.

1. What is a smart contract? How are they deployed? You should be able to describe how a smart contract is deployed and the necessary steps.

- We can think blockchain as a world computer, it is one single virtual machine that runs across millions of CPUs all at the same time. we call that code executed on the world virtual machine as smart contract. People can invoke those contracts' ABI only after implementing and deploying those contracts to blockchain.
- Everyone has a public address and a private key on blockchain, the former used to indicate account, the latter used to sign to confirm a transaction. There has nothing difference beteen deploy a smart contract and propose a transaction. After compiling contract code to virtual machine's byte code, you can send a special transaction to blockchain for deploying your smart contract. If successfully deployed, you will get a address which is location of the smart contract you just deployed. So that everyone who can access the blockchain can invoke your smart contract.
- From a practical standpoint, people usually use `remix ` to develop `solidity` smart contract.  First connect the MetaMask wallet and select the network to deploy the contract. Once the contract is successfully compiled, it can be deployed.



2. What is gas? Why is gas optimization such a big focus when building smart contracts?

- Since decentralization is core property of blockchain, specific mechanism is needed to incentivize nodes to participate in the maintenance of the blockchain. In Ethereum, users pay gas fee for transactions, and these fees are used to incentivize consensus nodes.
- Just imagine, if your contract is lengthy and the time & space complexity of the algorithm are very high, then the consensus node must invest more computing resources when executing your contract, so users who call your contract need to pay more gas fee. This obviously discourages users from using your smart contract. So gas optimization is definitely import in something like DeFi, GameFi, etc.



3. What is a hash? Why do people use hashing to hide information?

- I think that the `hash` term here represents cryptographic hash function specificlly. A cryptographic hash function is a mathematical algorithm that maps data of an arbitary size to a bit array of fixed size. It's a one-way function, that is, a function for which it is practically infeasible to invert or reverse the computation.
- Ideally, the only way to find a message that produces a given hash is to attempt a brute-force search of possible inputs to see if they produce a match. Ideally it should also have the following properties.
  - it is quick to compute the hash value for any given message
  - it is infeasible to generate a message that yields a given hash value (i.e. to reverse the process that generated the given hash value)
  - it is infeasible to find two different messages with the same hash value
  - a small change to a message should change the hash value so extensively that a new hash value appears uncorrelated with the old hash value, also known as avalanche effect.



4. How would you prove to a colorblind person that two different colored objects are actually of different colors? You could check out Avi Wigderson talk about a similar problem [here](https://www.youtube.com/watch?v=5ovdoxnfFVc&t=4s).

- Let's assume two objects named $A$ and $B$ that are identical in every way except their color. In other words, stripped of color, they are indistinguishable.
- At the beginning, let the colorblind person remember the relative positions of $A$ and $B$, and then other people go out and let the blind person adjust the positions of $A$ and $B$ at will. It is reasonable to assume that after swapping positions, only the colorblind person remember the positions of $A$ and $B$.
- Next let the prover come in and let him/her distinguish between $A$ and $B$. Since $A$ and $B$ are indistinguishable in anything but color, the prover prove $A$ and $B$ objects are actually of different colors successfully when he/she answers correctly.



### B. **You sure you’re solid with Solidity?**

1. Program a super simple “Hello World” smart contract: write a `storeNumber` function to store an unsigned integer and then a `retrieveNumber` function to retrieve it. Clearly comment your code. Once completed, deploy the smart contract on [remix](http://remix.ethereum.org/). Push the .sol file to Github or Gist and include a screenshot of the Remix UI once deployed in your final submission pdf.

![](https://i.imgur.com/UjPLyEO.png)



3. Suppose we want to limit the voting period of each Ballot contract to **5 minutes**. To do so, implement the following: Add a state variable **`startTime`** to record the voting start time. Create a [modifier](https://www.youtube.com/watch?v=b6FBWsz7VaI) **`voteEnded`** that will check if the voting period is over. Use that modifier in the `vote` function to forbid voting and revert the transaction after the deadline.


![](https://i.imgur.com/JFGi6zH.png)



### Github repository link:

https://github.com/wangtsiao/ZKU-Repo

