久久久久久精品无码人妻_青春草无码精品视频在线观_无码精品国产VA在线观看_国产色无码专区在线观看

COMP26020代做、代寫Lab 5 - Solidity

時間:2024-05-03  來源:  作者: 我要糾錯



COMP26020: Programming Languages and Paradigms
Lab 5 - Solidity
Joseph Razavi and Richard Banach
1 Introduction
This lab exercise is about learning a programming language with unusual aspects from its documentation.
We focus on the Solidity programming language, in particular Solidity version 6, which you can read about
here:
https://docs.soliditylang.org/en/v0.6.0/
Solidity is a language designed to write so-called “smart contracts”. These are pieces of code which are
supposed to run on a public “blockchain” – a system which keeps a log of every event which happens, and
where no user can single-handedly affect what happens. That means that once your code is deployed, you
can no longer influence it, unless you have programmed mechanisms to do so. And if you find a bug, the
bug is there forever!
In addition, the blockchain is designed to support payments of various kinds – for instance a smart
contract has a balance of currency (called ‘wei’ for the Etherium blockchain on which Solidity contracts run)
which it must use to pay for its own computing resources. Contracts can charge each other and pay each
other for services.
Whether or not any of this is a sensible technical or social project is perhaps debatable, but it certainly
creates interesting design challenges for a programming language – and where weird programming languages
lead, let us follow!
Read about Solidity’s notion of a contract, and its execution model (the ‘Ethereum Virtual Machine’) here:
https://docs.soliditylang.org/en/v0.6.0/introduction-to-smart-contracts.html
Refer to the Solidity documentation to complete the exercises below. Aside from the above these sections
are particularly useful:
• https://docs.soliditylang.org/en/v0.6.0/solidity-by-example.html
• https://docs.soliditylang.org/en/v0.6.0/solidity-in-depth.html
If you prefer videos, I have made available on Blackboard some videos designed to help you get started.
Note these videos belong to the lab and are not part of the content of any week. Solidity will be used only
for the lab, and is not examinable.
In this lab exercise, rather than deploying our code on the real public blockchain (and having to pay
to run it!) we will use a simulated version of the Etherium Virtual Machine which is used for developing
code and testing it before deploying it for real. You must use the version provided on Blackboard; see next
section.
1
2 Setup
Make sure you have downloaded Remix from Blackboard:
https://online.manchester.ac.uk/bbcswebdav/courses/I3132-COMP-26020-1231-1YR-040494/remix-d624303.zip
(If the link above does not work, check the Lab 5 folder on Blackboard for information.)
and that you can compile and run programs. To do this, you might need to click on the ‘plug’ icon on the
left hand menu, and made sure ‘Solidity compiler’ and ‘deploy and run transactions’ are enabled. This will
let you compile and run Solidity programs in Remix as seen in the videos. Remix is a browser based editor,
and has been tested for this course on Google Chrome on Linux and Windows. With other browsers you
may get strange behaviour. It is better to edit in a separate text editor and paste into Remix for testing, as
it can have problems with saving files and allowing text to be copied out of it in some browsers. Make sure
you always have a copy of your code in another editor so that you don’t lose your work. Clone the gitlab
repository
26020-lab5-S-Solidity_
where is replaced by your username. This contains the files you will need for the exercise.
3 Background
The exercises concern three contracts which should interact with each other, alongside other contracts which
we assume exist (but do not implement or worry about the implementation of). The first contract we consider is a ‘paylock’. The idea is that a supplier does some work, which can then be collected by a customer.
If the customer collects early, they get a discount, and how much discount they get depends on how early:
there are two deadlines. If they miss the second deadline they forfeit their discount altogether.
Done_2 Forfeit
Done_1 Delay
 Working Completed
Start
Signal
Collect_1_Y Collect_1_N
Collect_2_Y Collect_2_N
The blobs indicate possible states of the paylock, and the arrows represent function calls. The ‘Start’
arrow represents the constructor. The idea is that the functions should only succeed if the paylock is in
the state at the beginning of the arrow, and then the resulting state should be the one at the end. Of
course, there are other conditions: collect_1_Y should only succeed if called before the first deadline,
and collect_1_N should only succeed if called once the first deadline has passed; similar considerations
apply to the other two collect functions. Look in the file paylock.sol to see a partially finished implementation of the paylock. The first two exercises (see next section) concern only the logic of the paylock.
They are about adding features to the implementation, though we never complete a realistic implementation.
The subsequent exercises are about implementing a supplier which has to interact with both the paylock
contract and a rental contract which it needs to use to complete its work. As above, we will only model
2
certain aspects of these contracts. On the one hand this makes the exercises manageable, but on the other
hand it can be confusing if not pointed out: you would naturally wonder when we would add the rest of the
necessary features!
4 Exercises
The implementation of the paylock which you are given does not model the passage of time. To do this, we
will add a tick function, representing the passage of one unit of time. We shall assume for the moment that
the tick function is going to be called by a neutral third party, who we trust to call it at a regular interval.
For now we also trust all other contracts in the universe not to call this function. (And assume that the
blockchain updates quickly enough that this is a reasonable model of time! This is not how one would deal
with time in a real smart contract system.)
EXERCISE 1: (2 marks)
Add an int variable clock and a tick function which models the passage of time. Modify the various
collect functions to adhere to the deadlines, where we consider the first deadline to happen if the clock
has reached 4 units of time or more, and the second deadline to be when the clock has increased by
4 units of time or more from when collect_1_N was called.
We now need to make sure this tick function can only be called by the agreed third party.
EXERCISE 2: (2 marks)
Add an address variable timeAdd to the contract. Add an argument to the constructor and set the
value of timeAdd to that argument. Now modify tick so that it can only be called by someone from
the address timeAdd .
Tip: when testing your code, copy one of the addresses from the ‘Account’ dropdown menu and paste
it into the constructor argument. That should make it easier to experiment.
Look in the file supplier.txt and paste its contents at the end of paylock.sol . Note how the Supplier
contract interacts with the paylock, indicating to the paylock when it has finished its task. In the next
exercise, we will make it interact with the Rental contract too. The idea is that in order to finish its job,
the Supplier must rent a resource, then return it, before calling finish will succeed.
EXERCISE 3: (2 marks)
Add functions aquire_resource and return_resource which must be called in that order to the
Supplier contract. To do this you will need to add new local variables. Add a local variable
representing an instance of the Rental contract, and allow the address of an instance of Rental to
be passed as an argument to the constructor. Modify the aquire_resource and return_resource
functions so that they call the appropriate functions of the Rental contract.
Tip: Since the constructor of Supplier requires the addresses of a Paylock and a Rental, make sure
you deploy instances of those first when testing.
We will now make our model of the Rental contract somewhat more realistic, by requiring the payment
of a deposit which is returned once the rented resource is re- turned. For the purposes of the lab we assume
that the deposit is 1 wei.
Since the Rental contract is not supposed to assume that it is being called be a Supplier, it should
assume that the contract it is connected to implements a receive function; you can read about this in the
Solidity language documentation:
https://docs.soliditylang.org/en/v0.6.0/contracts.html#receive-ether-function.
3
Since we are not allowed to assume the calling contract is a Supplier, it is also useful to look at the
functions which can be applied to any address:
https://docs.soliditylang.org/en/v0.6.0/types.html#members-of-addresses .
In fact, our intention is to make as few assumptions about the other contract as possible, so we will use
the low-level .call() function. Find out how to make this work and attach a value to it.
EXERCISE 4: (2 marks)
Modify the Rental contract in the following way. First find the commented line
//CHECK FOR PAYMENT HERE
and replace it with something which prevents the function from succeeding unless proper payment is
made. You will also have to make the functions payable. Then find the commented line
//RETURN DEPOSIT HERE
and replace it with a single use of the .call function which returns the deposit. Modify the Supplier
contract so that it has a receive function, and make sure that Rental does not assume that the
contract which calls its functions is an instance of Supplier. Modify the external function calls made
by Supplier to Rental so that they transfer the deposit as appropriate.
At this point you should copy the file paylock.sol to supplier2.sol and work in supplier2.sol .
The rental contract as implemented has a security flaw (which is described in the ‘Reentrancy’ section of
chapter 9 of Antonopoulos’s book Mastering Etherium (available online from the library, and also at
https://github.com/ethereumbook/ethereumbook/blob/develop/09smart-contracts-security.asciidoc
EXERCISE 5: (1 mark)
Modify the Supplier contract to take advantage of this security flaw to take more Ether belonging
to the Rental contract than it has sent to the contract, if more ehter is available. Make sure this
work is saved in the file supplier2.sol
At this point you should copy the file supplier2.sol to suppler3.sol and work in supplier3.sol .
EXERCISE 6: (1 mark)
Re-order the lines of the retrieve_resource function of the Rental contract so that the vulnerability
above is fixed. Make sure this work is saved in the file supplier2.sol
Note: You need only prevent the attack described here while preserving correct functionality; you do
not need to solve any other security flaws.
5 Submission
Submission is by gitlab, following the same procedure as the other labs for this unit. Ensure that you have
pushed a commit containing your submission (i.e. make sure you have added all files to the repository),
tagged with the tag lab5-submission , by 6pm on 03/05.
Check SPOT to make sure your submission has been received correctly, and contact me (Joe) if you
notice any strange behaviour from SPOT.
請加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp





 

標簽:

掃一掃在手機打開當前頁
  • 上一篇:代寫program、代做c/c++,Python語言編程
  • 下一篇:EBU4201代做、代寫Java設計編程
  • 無相關信息
    昆明生活資訊

    昆明圖文信息
    蝴蝶泉(4A)-大理旅游
    蝴蝶泉(4A)-大理旅游
    油炸竹蟲
    油炸竹蟲
    酸筍煮魚(雞)
    酸筍煮魚(雞)
    竹筒飯
    竹筒飯
    香茅草烤魚
    香茅草烤魚
    檸檬烤魚
    檸檬烤魚
    昆明西山國家級風景名勝區
    昆明西山國家級風景名勝區
    昆明旅游索道攻略
    昆明旅游索道攻略
  • 短信驗證碼平臺 理財 WPS下載

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 kmw.cc Inc. All Rights Reserved. 昆明網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    久久久久久精品无码人妻_青春草无码精品视频在线观_无码精品国产VA在线观看_国产色无码专区在线观看

    乱熟女高潮一区二区在线| xxx国产在线观看| 91淫黄看大片| 男女裸体影院高潮| 午夜久久久精品| 国产又大又硬又粗| 人人妻人人澡人人爽欧美一区双| 日韩a一级欧美一级| 色乱码一区二区三区在线| 国产极品美女高潮无套久久久| 黄页网站大全在线观看| 精品一区二区三区无码视频| 久久久久久久久网| 欧美日韩视频免费在线观看| jizzzz日本| 日韩中文字幕a| 中文字幕22页| 一级黄色录像在线观看| 99sesese| 一区二区三区国产好的精华液| 最新国产黄色网址| 在线观看中文av| 色呦呦网站入口| 天天干天天色天天爽| 丰满人妻一区二区三区53号| 激情视频小说图片| 欧美极品少妇无套实战| 加勒比成人在线| 女人和拘做爰正片视频| 日本福利视频在线| 久久婷婷国产精品| 在线免费观看av的网站| 中文字幕亚洲影院| 国风产精品一区二区| 精品无码国产一区二区三区av| 日本a在线免费观看| 久久久久久久久久久福利| wwwwww.色| 天堂网成人在线| 国产成人永久免费视频| 日韩久久一级片| 中文字幕精品一区二区三区在线| 三级黄色片免费看| 亚洲精品蜜桃久久久久久| aⅴ在线免费观看| 日本黄色福利视频| 9191国产视频| av网站在线观看不卡| 午夜精品中文字幕| 777久久精品一区二区三区无码 | 在线观看国产中文字幕| 中文字幕免费高| 青青草成人免费在线视频| 国产精彩免费视频| 久久精品国产露脸对白| 欧美国产视频一区| 成人亚洲视频在线观看| 最新黄色av网站| 黄色免费视频大全| 亚洲天堂伊人网| 欧美国产激情视频| www.亚洲自拍| 日本成年人网址| 日韩国产精品毛片| aaaaaa亚洲| 亚洲国产一二三精品无码| 成人在线观看a| 穿情趣内衣被c到高潮视频| 成人在线免费在线观看| 手机在线免费毛片| 六月激情综合网| 欧美与动交zoz0z| 少妇人妻互换不带套| 久久国产精品免费观看| 欧美 激情 在线| 欧美一级特黄aaaaaa在线看片| 欧美日韩一区二区在线免费观看| 1314成人网| 人人干人人视频| 免费网站在线观看视频 | 午夜精品久久久久久久99热影院| 无码熟妇人妻av在线电影| 久久撸在线视频| 欧美 日本 亚洲| 国产91视频一区| 亚洲五月激情网| 黄色国产小视频| 日韩日韩日韩日韩日韩| 国产又大又长又粗又黄| 五月婷婷六月合| 91国视频在线| 中文字幕人妻熟女人妻洋洋| 国产成人在线综合| 毛葺葺老太做受视频| 国产中文字幕二区| www国产无套内射com| 亚洲第一成肉网| 九九热99视频| 韩国一区二区av| 91精品91久久久中77777老牛| 99视频精品全部免费看| 亚洲热在线视频| 免费一区二区三区在线观看| 欧美 激情 在线| 国产91在线免费| 和岳每晚弄的高潮嗷嗷叫视频| 欧美一级黄色录像片| 天堂在线中文在线| 污版视频在线观看| www.日日操| 91看片就是不一样| 少妇高潮喷水久久久久久久久久| 黄色一级在线视频| 99热亚洲精品| 欧美乱大交xxxxx潮喷l头像| 久久久久99精品成人片| 97超碰国产精品| 免费看日本黄色| 成人在线视频一区二区三区| 日韩一二区视频| 天天想你在线观看完整版电影免费| 三级av免费看| 亚洲制服在线观看| 久久精品一二三四| 18视频在线观看娇喘| 国产一区二区三区播放| 成人短视频在线观看免费| 在线观看污视频| 黄色a级片免费看| 日韩一级性生活片| 国产精品无码av在线播放| 黄色片视频在线免费观看| 青青青在线播放| av在线无限看| 亚洲欧美日本一区二区三区| 波多野结衣免费观看| 精品视频在线观看一区二区| 男的插女的下面视频| 成年人观看网站| xxxx一级片| 国产精品探花在线播放| 超薄肉色丝袜足j调教99| 久久在线中文字幕| 高清在线观看免费| 天堂在线资源视频| 国产农村妇女精品久久| 欧美人与动牲交xxxxbbbb| 亚洲不卡中文字幕无码| 免费在线观看的av网站| 午夜免费看毛片| 国产又粗又长又爽视频| 日本日本19xxxⅹhd乱影响| 高清一区二区视频| 夜夜爽久久精品91| www.成年人视频| 国产视频一区二区三区在线播放| 亚洲免费一级视频| 精品国产三级a∨在线| 又大又硬又爽免费视频| av片中文字幕| 日本高清免费观看| 狠狠干 狠狠操| 日日躁夜夜躁aaaabbbb| 国产三级中文字幕| 国产主播在线看| 特级黄色片视频| 国产成人黄色片| 手机在线免费毛片| 国产原创中文在线观看 | 三年中国国语在线播放免费| 国产欧美精品一二三| 一本久道高清无码视频| www.欧美日本| 久久免费一级片| 国产视频一区二区三区在线播放 | 精品成在人线av无码免费看| 国产精品免费成人| 国产av第一区| 一级黄色香蕉视频| 无码人妻精品一区二区蜜桃网站| 欧美日韩在线成人| 国产精品无码电影在线观看| 三级在线视频观看| 日韩一级片免费视频| 小明看看成人免费视频| 波多野结衣乳巨码无在线| 国产乱叫456| 人妻无码视频一区二区三区| 欧美精品久久96人妻无码| 国产精品无码专区av在线播放| 久久精品在线免费视频| 亚洲36d大奶网| 国产精品无码一区二区在线| 成人免费黄色av| 麻豆av免费在线| 久久国产精品视频在线观看| 欧美爱爱视频网站| 日韩精品你懂的| 欧美牲交a欧美牲交aⅴ免费真| 日韩中文字幕在线不卡|