亚洲十八**毛片_亚洲综合影院_五月天精品一区二区三区_久久久噜噜噜久久中文字幕色伊伊 _欧美岛国在线观看_久久国产精品毛片_欧美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

    亚洲欧美网站在线观看| 午夜精品毛片| 婷婷综合五月| 日本亚洲最大的色成网站www| 99riav一区二区三区| 一区二区高清在线| 欧美成人r级一区二区三区| 日韩欧美电影在线观看| 午夜dj在线观看高清视频完整版 | 欧美精品国产| 不卡大黄网站免费看| 天天免费综合色| 影音先锋可以看的网站| 女海盗2成人h版中文字幕| 亚洲动漫精品| 国产精品伊人色| 欧美日韩国产在线看| 久久白虎精品| 国语自产精品视频在线看抢先版结局 | 色88888久久久久久影院按摩| 伊人发布在线| 素人啪啪色综合| 激情综合自拍| 国产精品久久久久一区| 精品日韩一区二区三区| 在线看一级片| 日韩av有码| 成人妖精视频yjsp地址| 欧美网站一区二区| 成人无遮挡免费网站视频在线观看| 国产精品对白久久久久粗| 老司机午夜精品视频| 一二三区精品福利视频| 色播在线视频| av日韩精品| 国产高清在线观看免费不卡| 欧美性淫爽ww久久久久无| 国产精品天堂| 精品国产一级毛片| 久久女同互慰一区二区三区| 精品国产免费一区二区三区四区 | 亚洲综合网站在线观看| 在线观看国产视频一二三| 成人交换视频| 毛片不卡一区二区| 欧美三级视频在线播放| mm视频在线视频| 99热精品在线观看| 精品欧美激情精品一区| 国产激情在线视频| 国产精品v亚洲精品v日韩精品 | 天天草夜夜操| 成人全视频在线观看在线播放高清 | 国产美女精品一区二区三区| 9191精品国产综合久久久久久| 美女91在线| 一本色道久久综合亚洲精品不卡 | 国产一级二级在线| 欧美成人精品午夜一区二区| 成人激情小说网站| 国产一级激情| 日韩电影不卡一区| 国产精品污www在线观看| 欧洲亚洲精品视频| 国产中文字幕一区二区三区| 亚洲视频一区二区在线观看| 国产高清av在线| 欧美国产综合| 欧美无砖砖区免费| 成人黄页网站视频| 成人国产电影网| 香港日本韩国三级| 亚洲最大在线| 亚洲精品成人a在线观看| 最新国产在线拍揄自揄视频| 久久久一二三| 天天做夜夜操| 色综合综合网| 亚洲成av人影院在线观看网| 永久免费毛片在线播放| 国产福利一区二区| 视频在线国产| 欧美日本不卡| 日韩天堂在线观看| 精品欧美午夜寂寞影院| 亚洲免费观看在线观看| 交100部在线观看| 国产黄色成人av| 你懂的视频在线| 亚洲欧美日韩国产一区| 成人免费淫片免费观看| 成人动漫免费在线观看| 色综合视频在线观看| 日韩av黄色| 18欧美亚洲精品| 碰碰在线视频| 久久久久国产免费免费| 最新超碰在线| aaa国产一区| 成人影院www在线观看| 国产盗摄精品一区二区三区在线| 日韩成人在线观看视频| 国产一区二区三区四区老人| 亚洲免费观看高清完整版在线 | 香蕉成人app免费看片| 国产午夜亚洲精品理论片色戒| 天天干天天摸| 亚洲午夜在线| 欧美巨大另类极品videosbest | 极品中文字幕一区| 亚洲不卡在线观看| 国产精品3区| 精品久久久久久| 亚洲午夜免费| 在线日本视频| 9色porny自拍视频一区二区| 日韩伦理片在线观看| 99热精品在线观看| 三上悠亚国产精品一区二区三区| 免费成人在线观看| 欧美日韩亚洲高清一区二区| 奇米亚洲午夜久久精品| 91亚洲精品| 美乳中文字幕| 欧美激情一区二区三区蜜桃视频| 亚洲深夜福利在线观看| 日中文字幕在线| 久久久影视传媒| 一区视频网站| 亚洲午夜精品在线| 国产精品视区| 亚洲妇熟xxxx妇色黄| 欧美羞羞免费网站| 黄色av一区| 在线天堂视频| 91在线视频观看| 国产精品欧美在线观看| 日韩中文视频| 黄色羞羞视频在线观看| 26uuu亚洲电影在线观看| 免费av网站在线观看| 天海翼女教师无删减版电影| 日韩欧美色综合| 一区二区三区四区视频精品免费 | 欧美日韩国产欧美日美国产精品| 日本在线一区二区| 高清色视频在线观看| 五月婷婷另类国产| 国产一区二三区好的| 日日夜夜一区二区| 久久亚洲影院| 丝袜美腿亚洲色图| 国产成人av影院| 丝袜美腿亚洲一区二区图片| 俺要去色综合狠狠| 香蕉精品久久| 午夜影院免费在线| 欧美日韩国产综合视频| 日韩欧美aaa| 国产色产综合色产在线视频| 国产精品久久观看| 92国产精品| 酒色婷婷桃色成人免费av网| 欧美日韩日日摸| 国产成人免费在线观看不卡| 日韩av有码| 日韩在线你懂得| 久久国内精品| 最新国产精品视频| 久久精品播放| 成人免费观看视频大全| 亚洲大胆精品| 免费观看一二区视频网站| 精品国产免费一区二区三区四区| 久久精品一级爱片| 成人女性视频| 国产精品xvideos88| 最新日韩在线| 欧美一区成人| 丁香激情综合五月| 亚洲成人资源在线| 国产美女视频黄a视频免费| 飘雪影视在线观看免费观看| 日韩成人伦理| 国产精品任我爽爆在线播放| 欧美午夜影院| 久久亚洲精华国产精华液| 国产精品免费视频网站| 亚洲大胆视频| 99久久久无码国产精品| 日本在线不卡视频| 日日夜夜免费精品| 99亚洲视频| 免费黄网站欧美| 91免费观看在线| 国产精品国产自产拍高清av王其| 日韩在线卡一卡二| 久久人人97超碰国产公开结果| 久久狠狠一本精品综合网| 六月丁香婷婷色狠狠久久|