美女扒开腿免费视频_蜜桃传媒一区二区亚洲av_先锋影音av在线_少妇一级淫片免费放播放_日本泡妞xxxx免费视频软件_一色道久久88加勒比一_熟女少妇一区二区三区_老司机免费视频_潘金莲一级黄色片_精品国产精品国产精品_黑人巨大猛交丰满少妇

COMP26020代做、代寫Lab 5 - Solidity

時(shí)間:2024-05-03  來源:  作者: 我要糾錯(cuò)



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.
請(qǐng)加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp





 

標(biāo)簽:

掃一掃在手機(jī)打開當(dāng)前頁
  • 上一篇:代寫program、代做c/c++,Python語言編程
  • 下一篇:EBU4201代做、代寫Java設(shè)計(jì)編程
  • 無相關(guān)信息
    昆明生活資訊

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

    關(guān)于我們 | 打賞支持 | 廣告服務(wù) | 聯(lián)系我們 | 網(wǎng)站地圖 | 免責(zé)聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 kmw.cc Inc. All Rights Reserved. 昆明網(wǎng) 版權(quán)所有
    ICP備06013414號(hào)-3 公安備 42010502001045

    美女扒开腿免费视频_蜜桃传媒一区二区亚洲av_先锋影音av在线_少妇一级淫片免费放播放_日本泡妞xxxx免费视频软件_一色道久久88加勒比一_熟女少妇一区二区三区_老司机免费视频_潘金莲一级黄色片_精品国产精品国产精品_黑人巨大猛交丰满少妇
    中文字幕有码在线播放| 日韩高清dvd碟片| 成人涩涩小片视频日本| 日韩a级片在线观看 | 国产精品夜夜夜爽阿娇| 中文字幕另类日韩欧美亚洲嫩草| 精品人妻一区二区三| 国产艳俗歌舞表演hd| 欧洲性xxxx| 人妻换人妻a片爽麻豆| 影音先锋制服丝袜| 佐佐木明希电影| av片在线免费看| 性色av蜜臀av浪潮av老女人| 精品熟妇无码av免费久久| 在线播放第一页| 成人小视频免费看| av网站有哪些| 国产人成视频在线观看| 91精品少妇一区二区三区蜜桃臀| 人妻熟女aⅴ一区二区三区汇编| 国产精品三区在线观看| youjizz亚洲女人| 久久只有这里有精品| 国产一级免费片| 久久久久久久穴| 美女又黄又免费的视频| 成人涩涩小片视频日本| 中文乱码字幕高清一区二区| 蜜桃av免费看| 成人免费网站黄| 实拍女处破www免费看| 成人影视免费观看| 三级男人添奶爽爽爽视频| 性农村xxxxx小树林| 扒开伸进免费视频| 无码人妻精品一区二区三| 蜜臀aⅴ国产精品久久久国产老师| 日本aⅴ在线观看| 印度午夜性春猛xxx交| av黄色在线免费观看| 日韩无码精品一区二区| 羞羞在线观看视频| 在哪里可以看毛片| caopeng视频| 欧美亚洲色综久久精品国产| 精品成人av一区二区三区| 国产真人做爰视频免费| jizz日本在线播放| 日本精品久久久久中文| 91制片厂在线| 91在线播放观看| 中文字幕第九页| 五月天综合视频| 日韩av网站在线播放| √天堂中文官网8在线| 波多野结衣电影免费观看| 亚洲av成人精品一区二区三区| 在线免费观看黄色小视频| 成人在线手机视频| 91porn在线视频| a级一a一级在线观看| 欧美图片第一页| 国产老头老太做爰视频| 中文字幕在线视频播放| 中文字幕人妻一区二区| 欧美激情精品久久久久久免费| 澳门黄色一级片| 级毛片内射视频| 欧美黄色aaa| 美女爆乳18禁www久久久久久| 亚洲天堂网av在线| 短视频在线观看| 四川一级毛毛片| 免费毛片视频网站| 波多野结衣电影免费观看| a天堂中文字幕| 中文字幕人妻一区二区三区| 人与嘼交av免费| 中国免费黄色片| 精品国产视频一区二区三区| 一级国产黄色片| 日本女人性视频| 亚洲天堂网av在线| 激情无码人妻又粗又大| 亚洲区免费视频| 毛茸茸free性熟hd| 中国老熟女重囗味hdxx| 中文字幕资源站| 免费看的黄色网| 美女100%无挡| 在线xxxxx| 三上悠亚 电影| 免费成人美女女在线观看| 中文字幕免费看| 三级男人添奶爽爽爽视频| 涩视频在线观看| 精品国产乱码久久久久久鸭王1| 免费看裸体网站| 在线免费观看黄色小视频| 日本xxx在线播放| 中文字幕一区二区三区人妻不卡| 亚洲成a人片在线www| 外国一级黄色片| 91精品国产高清一区二区三蜜臀| 天天操夜夜操av| 99热这里只有精品4| 亚洲综合视频网站| 校园春色 亚洲| 亚洲欧洲日韩综合| youjizz.com日本| 中文字幕人妻一区| 中文字幕免费高清视频| 风间由美一二三区av片| 国产在线观看无码免费视频| 日韩精品卡通动漫网站| 老熟妇一区二区| 免费成人深夜蜜桃视频| 91免费公开视频| 无码人妻少妇色欲av一区二区| 无码人妻丰满熟妇区毛片蜜桃精品| 国产一区二区三区在线视频观看| 国产精品九九九九九九| www.四虎精品| 国产伦精品一区二区三区视频女| 国产小视频你懂的| 女人扒开腿免费视频app| 超碰caoprom| 日韩av在线看免费观看| 亚洲AV成人无码精电影在线| 少妇献身老头系列| 91视频免费观看网站| 最新av电影网站| 人妻无码一区二区三区| 亚洲女同二女同志奶水| 在线中文字日产幕| a天堂中文字幕| 唐朝av高清盛宴| 一区二区黄色片| 日韩精品xxx| 国产探花视频在线播放| 亚洲精品一二三四| 成年人在线免费看片| 人妻精油按摩bd高清中文字幕| 成人网站免费观看| 曰本三级日本三级日本三级| 丰腴饱满的极品熟妇| www.99re7| 农村老熟妇乱子伦视频| 国产麻豆xxxvideo实拍| 欧美激情图片小说| 精品国产大片大片大片| 一区二区伦理片| 欧美大片免费播放器| 中文字幕1区2区| 欧美风情第一页| 女教师淫辱の教室蜜臀av软件| 五级黄高潮片90分钟视频| 国产这里有精品| 农村老熟妇乱子伦视频| 无码国产69精品久久久久同性| 日韩黄色一区二区| 少妇影院在线观看| 91香蕉一区二区三区在线观看| 久久久久久国产免费a片| 亚洲黄色在线网站| 国产视频精品视频| 在线黄色免费网站| av地址在线观看| 一区二区三区影视| 亚洲 欧美 变态 另类 综合| 免费观看特级毛片| 成年人网站在线观看视频| www中文在线| 午夜激情视频在线播放| 老司机福利在线观看| 亚洲一区二区三区日韩| 超薄肉色丝袜一二三| youjizz亚洲女人| 美国精品一区二区| 久久久99999| 又黄又爽又色的视频| 国产探花在线播放| 免费观看一区二区三区| 2一3sex性hd| 中文字幕一区二区人妻在线不卡| 亚洲蜜桃精久久久久久久久久久久| 国产伦精品一区二区免费| 亚洲中文字幕一区| 成年人免费观看视频网站| 日韩免费成人av| 久久免费看少妇高潮v片特黄| 黑鬼狂亚洲人videos| 国内精品免费视频| 黄免费在线观看| 国产一区二区三区在线视频观看| 三大队在线观看| 国产高潮呻吟久久| 国产一二三四区| 99久久国产精|