Full-stack Web3 Engineering Assignment – 全栈Web3工程作业区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Full-stack Web3 Engineering Assignment – 全栈Web3工程作业区块链毕设代写 是一篇很好的国外资料

Full-stack Web3 Engineering Assignment

Thank you for your interest in joining the AP Capital Crypto engineering team!

This document is just a quick test to see where your coding and problem solving skills are with something related to dApp development. It’s designed to be straightforward and not take too much of your time.

Since a lot of this position will be JavaScript/Typescript-based app development and integrating with Solidity contracts, we’ve created a task that, in some capacity, represents the tooling you’ll be working with on a day-to-day basis with us.

Background

“Blind” voting on a public blockchain takes some thought. All data is public so without any extra tricks it’s trivial to see who voted what and which side is likely to win. This can greatly bias voters and lead to inefficient decisions.

One way to mitigate this is to use a “commit-reveal” scheme. In such a scheme, eligible voters commit Hash(x + secret) in some “commit period” where x is their vote choice. For simplicitly, suppose x is either 0 or 1 and the "+" operator means concatenation. So for example, a user might commit a vote "Hash(0~mysuperbigsecret)". We call this the “commitment”.

After the “commit period”, voters can reveal their vote by supplying (x + secret), and their Hash(x + secret). This would be "0~mysuperbigsecret" and "Hash(0~mysuperbigsecret)" respectively, in this case. Using the fact that hash collisions are impossible using a cryptographic hash function, we can cryptographically prove that a user committed to a particular vote by computing the hash of (x + secret) and comparing it with the supplied commitment.

Using this technique, it’s now impossible to know what a given user committed to before the revealing period unless they told you their secret beforehand, grealty improving the effectiveness of the vote.

The task

We’ve written a simple implementation of a commit-reveal vote scheme in Solidity in CommitReveal.sol. Our ask is for you to write a very simple script to wrap it and make it easy for users to participate in the vote.

The Solidity implementation we wrote is very simple: it has only two choices, “YES” and “NO”, the commit phase lasts 2 minutes, and users can vote multiple times. It’s based on the blog written by Karl Floresch which we encourage you to check out here if you’re looking for more background. For this simple assignment, there will be only one voter (you).

Requirements

Using any framework you’d like, please make a linear script that interacts with the contract. In a real implementation, we would have many different voters and a requirement that a voter can only vote once, but this is just a dummy example. Here are the functional requirements:

  • If the blockchain is in the commit phrase, the user should be able to see the two choices they can vote for, “YES” (choice1 in CommitReveal.sol) and “NO” (choice2 in CommitReveal.sol) and commit a vote. A user can run this as many times as they want, provided they use a different secret each time. Behind the scenes it should be map “YES” and “NO” to the appropriate “1” or “2”
  • If the blockchain is in the reveal phase, the user should be able to reveal a vote by supplying their secret and their vote. A user can run this as many times as they want, provided they reveal a different commit each time.
  • If all votes have been revealed, the program should output
    • The winner of the vote
    • How many votes were cast

Things you don’t have to do:

  • Publish this as an NPM package
  • Write any further tests for the contracts or exhaustive tests for your script. The script just needs to work.
  • Add any functionality for “switching” between accounts. A user can vote multiple times with different secrets and that is totally fine.
  • Deploy this on any public blockchain. Use a local blockchain such as ganache-cli.

For interacting with the contracts, you can use ethers.js, web3, or the native truffle contract wrappers. Up to you.

Setup

First, install the dependencies. You’ll need a local Ethereum blockchain to deploy the contracts and run the contract tests if you want. We recommend ganache. You can install ganache with

npm install -g ganache-cli

and start it up with

ganache-cli

To get the code deployed onto the blockchain, just truffle migrate in this repo once ganache-cli is up.

If you want to run the tests (not necessary to complete this assignment, just to verify the functionality of the solidity contracts), you’ll have to monkey patch the line

node_modules/@0x/utils/lib/src/provider_utils.js:81

with

if (_.includes(supportedProvider.send.toString().replace(' ', '').replace(' ', ''), 'function(payload,callback)')) :

otherwise you’ll run into a TypeError: Cannot read property 'then' of undefined as there is some annoying bug with web3 currently.

Other notes

  • We’ve already written the migration script with pre-defined choices (see 1_initial_migration.js) and there are some helper npm scripts in package.json in case you don’t want to install truffle globally.
  • truffle-config.js is already configured to point to your local ganache on port 8545.
  • The test folder includes some example code to interact with the contracts using the truffle-contract wrappers if you need some hints. You don’t have to use truffle to interact with the contracts as mentioned above.
  • To help with transitioning from the commit phase to the reveal phase, we’ve provided some example code in the test folder. Ganache has a special command called evm_increaseTime which can artifically set the next block’s timestamp and @0xproject provides a nice wrapper around this command. Alternatively you can just wait. Just remember that once you go forward in time you can’t go back. Yu’ll need to restart your ganache-cli to do that.

All you have to do is write your script.

What we’re looking for

We’re interested in your coding style, your familarity with developer tooling for smart contracts or your ability to learn the tooling, and your JavaScript/TypeScript proficiency.

How to complete this challenge

Fork this repo, and make your new repo private. Write your code in a sub-folder in this repo, and edit this README to include instructions on how to use your script. Feel free to change anything in the repo except for the CommitReveal.sol contract.

Send [email protected] the private GitHub link when you’re done.

Good luck!

solidity


全栈Web3工程作业

感谢您对加入AP Capital加密工程团队的兴趣

本文档只是一个快速测试,以了解您的编码和问题解决技能与dApp开发相关的地方。它的设计是直截了当的,不会占用你太多的时间

由于该职位的大部分工作是基于JavaScript/Typescript的应用程序开发和与Solidity合同的集成,因此我们创建了一个任务,在某种程度上代表了您将与我们日常合作的工具

背景

对公共区块链blockchain的“盲目”投票需要一些思考。所有的数据都是公开的,所以不需要任何额外的技巧就可以知道谁投了什么票,哪一方可能获胜。这会使选民产生极大的偏见,导致决策效率低下

缓解这种情况的一种方法是使用“提交-显示”方案。在这种方案中,合格的投票者在某个“提交周期”内提交Hash(x+secret),其中x是他们的投票选择。简单地说,假设x是0或1,“+”运算符表示串联。例如,用户可能提交一个投票“Hash(0~mysuperbigsecret)”。我们称之为“承诺”

在“提交期”之后,投票者可以通过提供(x+secret)和散列(x+secret)来显示他们的投票。在本例中,这将分别是“0~mysuperbigsecret”和“Hash(0~mysuperbigsecret)”。利用使用加密散列函数不可能发生散列冲突的事实,我们可以通过计算(x+secret)的散列并将其与提供的承诺进行比较,以密码学的方式证明用户承诺了特定的投票

使用这种技术,现在不可能知道一个给定的用户在披露期之前承诺了什么,除非他们事先告诉你他们的秘密,这大大提高了投票的效率

任务

我们在CommitReveal.sol中编写了一个简单的conmit-reveal投票方案的实现。我们的要求是让你写一个非常简单的脚本来包装它,让用户能够轻松参与投票

我们编写的Solidity实现非常简单:它只有两个选择,“YES”和“NO”,提交阶段持续2分钟,用户可以多次投票。这是基于卡尔弗洛雷斯写的博客,我们鼓励你在这里检查,如果你想了解更多的背景。对于这个简单的分配,将只有一个投票人(你)

要求

请使用您喜欢的任何框架,制作一个与合同交互的线性脚本。在一个真正的实现中,我们会有许多不同的投票者,并且要求投票者只能投一次票,但这只是一个虚构的例子。以下是功能要求:

  • 如果区块链blockchain处于提交阶段,用户应该能够看到他们可以投票的两个选项,“是”(CommitReveal.sol中的选项1)和“否”(CommitReveal.sol中的选项2)并提交投票。如果用户每次都使用不同的密码,则用户可以根据需要多次运行此操作。在幕后,应该将“是”和“否”映射到适当的“1”或“2”
  • 如果区块链blockchain处于揭示阶段,用户应该能够通过提供他们的秘密和投票来揭示投票。如果用户每次都显示不同的提交,则用户可以根据需要多次运行此操作
  • 如果显示了所有投票,程序应输出投票的获胜者投出了多少票

您不必做的事情:

  • 为合同编写任何进一步的测试或为脚本编写详尽的测试。剧本需要发挥作用
  • 添加任何帐户间“切换”功能。一个用户可以投票多次不同的秘密,这是完全好的
  • 将其部署到任何公共区块链blockchain上。使用本地区块链blockchain,如ganache cli
  • 我们已经编写了带有预定义选项的迁移脚本(参见1u initialu migration.js),package.json中有一些帮助程序npm脚本,以防您不想全局安装truffle

为了与契约交互,您可以使用ethers.js、web3或原生的truffle契约包装器。由你决定

设置

首先,安装依赖项。如果需要,您将需要一个本地以太坊eth区块链blockchain来部署契约并运行契约测试。我们推荐甘纳切。您可以使用npm install-g ganache cli安装ganache,并使用ganache cli启动它,以将代码部署到区块链blockchain上,只要在ganache cli启动后在这个repo中执行truffle migrate即可

如果要运行测试(不需要完成此分配,只需验证solidity契约的功能),则必须使用If(

includes(supportedProvider.send.toString().replace(”,”).replace(”,”).replace(”,”),’function(payload,callback)’):

否则会遇到一个TypeError:无法读取未定义的’then’属性,因为web3当前存在一些恼人的错误

你要做的就是写剧本

我们对您的编码风格、您对智能合约开发工具的熟悉程度或您学习该工具的能力以及您的JavaScript/TypeScript熟练程度感兴趣

把这个回购交出来,把你的新回购变成私人的。在这个repo的子文件夹中编写代码,并编辑这个自述文件以包含如何使用脚本的说明。您可以随意更改回购协议中的任何内容,除了CommitReveal.sol合同

派斯特拉去。[email protected] 完成后,将打开专用GitHub链接

祝你好运

otherwise you’ll run into a TypeError: Cannot read property 'then' of undefined as there is some annoying bug with web3 currently.

其他说明

  • truffle-config.js已经配置为指向端口8545上的本地ganache。
  • 如果需要一些提示,test文件夹包含一些示例代码,可以使用truffle合同包装器与合同进行交互。你不必像上面提到的那样使用块菌来与合同交互
  • 为了帮助从提交阶段过渡到显示阶段,我们在test文件夹中提供了一些示例代码。Ganache有一个名为evmu increaseTime的特殊命令,它可以人为地设置下一个块的时间戳,@0xproject为这个命令提供了一个很好的包装器。或者你可以等等。只要记住,一旦你向前走,你就不能回头。你需要重新启动你的ganache cli才能做到这一点
  • To help with transitioning from the commit phase to the reveal phase, we’ve provided some example code in the test folder. Ganache has a special command called evm_increaseTime which can artifically set the next block’s timestamp and @0xproject provides a nice wrapper around this command. Alternatively you can just wait. Just remember that once you go forward in time you can’t go back. Yu’ll need to restart your ganache-cli to do that.

All you have to do is write your script.

我们要找的是什么

We’re interested in your coding style, your familarity with developer tooling for smart contracts or your ability to learn the tooling, and your JavaScript/TypeScript proficiency.

如何完成此挑战

Fork this repo, and make your new repo private. Write your code in a sub-folder in this repo, and edit this README to include instructions on how to use your script. Feel free to change anything in the repo except for the CommitReveal.sol contract.

Send [email protected] the private GitHub link when you’re done.

Good luck!

solidity

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/22697.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Full-stack Web3 Engineering Assignment – 全栈Web3工程作业区块链毕设代写

提供最优质的资源集合

立即查看 了解详情