HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
MASTER THESIS
IN DATA SCIENCE AND
ARTIFICIAL INTELLIGENCE
Optimizing smart contracts on
Ethereum
NGUYEN QUANG THANG
Supervisor: Dr. Do Ba Lam
Institution:
—————————————-
School of Information and Communication Technology
123doc
Mang
Ln
thay vì
h■■ng
l■im■i
s■
cam
tr■
h■u
m■t
k■t
nghi■m
t■im■t
là
s■
cáwebsite
nhân
mang
kho
m■ith■
kinh
m■
l■i
d■n
vi■n
nh■ng
cho
doanh
■■u
kh■ng
ng■■i
quy■n
chia
t■ th■c
dùng,
l■
s■l■i
v■i
và
hi■n
t■t
cơng
h■n
mua
ngh■a
nh■t
2.000.000
ngh■
báncho
tài
v■
hi■n
ng■■i
li■u
c■a
tài
th■
hàng
mình
li■u
dùng.
hi■n
■■u
■
thìt■t
Khi
■■i,
s■p
Vi■t
c■
khách
b■n
t■i,
l■nh
Nam.
ngh■a
online
hàng
v■c:
Táctr■
khơng
v■
tài
phong
thành
chính
c■a
khác
chun
c■a
thành
tíngì
d■ng,
hàng
so
nghi■p,
viên
v■i
tri■u
cơng
c■a
b■n
hồn
nhà
ngh■
123doc
g■c.
bán
h■o,
thơng
B■n
và
hàng
■■
n■p
có
tin,
l■i
cao
th■
ti■n
ngo■i
chuy■n
tính
phóng
vào
ng■,...Khách
trách
tài
giao
to,kho■n
nhi■m
thu
sang
nh■
c■a
■■i
■■n
hàng
tùy123doc,
v■i
v■
ý.
cót■ng
qu■n
th■b■n
d■
ng■■i
lýChào
dàng
s■ dùng.
■■■c
m■ng
tra c■u
M■c
h■■ng
b■n
tàitiêu
li■u
■■n
nh■ng
hàng
m■t
v■i■■u
quy■n
cách
123doc.
c■a
chính
l■i123doc.net
sau
xác,n■p
nhanh
ti■n
tr■
chóng.
trên
thành
website
th■ vi■n tài li■u online l■n nh■t Vi■t Nam, cung c■p nh■ng tài li■u ■■c khơng th■ tìm th■y trên th■ tr■■ng ngo■i tr■ 123doc.net.
Nhi■u event thú v■, event ki■m ti■n thi■t th■c. 123doc luôn luôn t■o c■ h■i gia t■ng thu nh■p online cho t■t c■ các thành viên c■a website.
Mangh■n
Ln
Th■a
Xu■t
Sau
Nhi■u
123doc
Link
khi
h■■ng
phát
thu■n
l■i
event
cam
s■
nh■n
xác
m■t
tr■
t■
h■u
k■t
s■
thú
nghi■m
t■i
th■c
ýxác
n■m
t■■ng
m■t
d■ng
v■,
là
s■
nh■n
s■
website
ra
mang
event
kho
m■i
■■■c
■■i,
1.
t■o
tLink
t■
th■
m■
l■i
c■ng
ki■m
■■ng
d■n
123doc
CH■P
g■i
vi■n
xác
nh■ng
cho
■■u
■■ng
ti■n
v■
th■c
h■
kh■ng
ng■■i
NH■N
■ã
■■a
quy■n
th■ng
thi■t
chia
t■ng
s■
ki■m
dùng,
l■
ch■
CÁC
s■
■■■c
th■c.
s■
l■i
b■■c
v■i
ti■n
và
email
chuy■n
■I■U
t■t
cơng
h■n
mua
123doc
g■i
online
kh■ng
nh■t
b■n
2.000.000
v■
ngh■
bán
KHO■N
sang
b■ng
ln
cho
■■a
■ã
tài
■■nh
hi■n
■■ng
ng■■i
li■u
ph■n
ln
ch■
tài
TH■A
tài
v■
th■
li■u
hàng
t■o
email
li■u
thơng
ky,
dùng.
tríhi■n
THU■N
hi■u
c■
c■a
b■n
■■u
■b■n
tin
t■t
h■i
Khi
■■i,
qu■
mình
vui
Vi■t
xác
c■
■ã
khách
gia
lịng
b■n
nh■t,
minh
trong
l■nh
■■ng
Nam.
t■ng
Chào
■■ng
online
hàng
uy
tài
v■c:
l■nh
thu
Tác
m■ng
ky,
tín
kho■n
tr■
nh■p
nh■p
khơng
b■n
tài
phong
v■c
cao
thành
b■n
chính
vui
email
nh■t.
tài
email
online
oLink
khác
chun
■■n
li■u
lịng
thành
tínb■n
Mong
c■a
xác
gì
cho
d■ng,
và
■■ng
v■i
so
nghi■p,
viên
th■c
kinh
■ã
mình
t■t
123doc.
123doc.net!
v■i
mu■n
cơng
■■ng
nh■p
c■a
c■
doanh
s■
b■n
vàcác
hồn
mang
■■■c
ngh■
123doc
click
email
ký
g■c.
online.
thành
v■i
h■o,
Chúng
vào
l■i
thơng
B■n
g■i
c■a
và
123doc.netLink
CH■P
cho
viên
linkí
Tính
■■
v■
n■p
có
mình
tơi
tin,
c■ng
c■a
cao
■■a
th■
■■n
cung
NH■N
ti■n
ngo■i
và
tính
mình
website.
phóng
■■ng
ch■
th■i
click
vào
c■p
CÁC
ng■,...Khách
trách
xác
trong
email
tài
■i■m
D■ch
vào
xã
to,kho■n
■I■U
th■c
nhi■m
h■i
thu
linkơng
l■nh
b■n
tháng
V■
nh■
m■t
s■
KHO■N
c■a
■ã
v■c
(nh■
■■i
hàng
■■■c
tin
tùy
ngu■n
5/2014;
■■ng
123doc,
tài
v■i
xác
■■■c
ý.
có
li■u
TH■A
g■i
t■ng
minh
th■
tài
ky,
123doc
và
v■
mơ
ngun
b■n
b■n
d■
ng■■i
THU■N
tài
kinh
■■a
t■
dàng
kho■n
s■
vui
v■■t
d■■i
doanh
tri
dùng.
■■■c
ch■
lịng
tra
th■c
m■c
email
■ây)
email
c■u
■■ng
Chào
online.
M■c
h■■ng
q
100.000
cho
tài
b■n
b■n
m■ng
tiêu
báu,
nh■p
li■u
Tính
b■n,
■ã
nh■ng
■ã
hàng
phong
m■t
l■■t
■■n
email
■■ng
b■n
tùy
■■ng
■■u
quy■n
cách
truy
thu■c
■■n
th■i
phú,
c■a
ký
ky,
c■a
c■p
chính
v■i
■i■m
v■i
■a
mình
l■i
b■n
vào
123doc.net
m■i
123doc.netLink
d■ng,
123doc.net!
sau
xác,
các
vui
tháng
vàngày,
n■p
click
lịng
“■i■u
nhanh
giàu
5/2014;
ti■n
s■
vào
■■ng
tr■
giá
Kho■n
Chúng
chóng.
h■u
trên
linkc■a
thành
tr■
xác
123doc
nh■p
2.000.000
website
■■ng
th■c
Th■a
tơi
th■
website.
cung
email
v■■t
s■
vi■n
th■i
Thu■n
■■■c
c■p
c■a
thành
mong
m■c
tài D■ch
v■
li■u
mình
g■i
viên
100.000
mu■n
S■
online
v■
và
V■
■■ng
D■ng
click
■■a
t■o
(nh■
l■■t
l■n
ký,
D■ch
■i■u
vào
ch■
nh■t
■■■c
truy
l■t
link
email
ki■n
V■”
vào
c■p
Vi■t
123doc
mơtop
sau
cho
b■n
m■i
Nam,
t■200
■ây
d■■i
cho
ngày,
■ã
cung
các
các
(sau
■■ng
g■i
■ây)
s■
website
c■p
users
■ây
h■u
ky,
cho
nh■ng
■■■c
có
b■n
2.000.000
b■n,
ph■
thêm
vui
tài
bi■n
tùy
g■i
lịng
thu
li■u
thu■c
t■t
thành
nh■t
nh■p.
■■c
■■ng
T■i
vào
t■i
viên
khơng
t■ng
Chính
nh■p
Vi■t
các
■■ng
th■i
“■i■u
th■
Nam,
vì
email
v■y
■i■m,
ký,
tìm
t■
Kho■n
c■a
l■t
123doc.net
th■y
l■chúng
vào
mình
tìm
trên
Th■a
top
ki■m
và
tơi
th■
200
ra
click
Thu■n
cóthu■c
■■i
tr■■ng
các
th■
vào
nh■m
website
c■p
v■
top
link
ngo■i
S■
3nh■t
■áp
123doc
Google.
D■ng
ph■
tr■
■KTTSDDV
■ng
123doc.net.
bi■n
■ã
D■ch
Nh■n
nhu
g■i
nh■t
c■u
V■”
■■■c
theo
t■i
chia
sau
Vi■t
quy■t
danh
■ây
s■ Nam,
tài
(sau
hi■u
...li■u
t■
■ây
do
ch■t
l■c■ng
■■■c
tìm
l■■ng
ki■m
■■ng
g■i
và
thu■c
t■t
bình
ki■m
T■i
ch■n
top
ti■n
t■ng
3 Google.
là
online.
th■i
website
■i■m,
Nh■n
ki■m
chúng
■■■c
ti■ntơi
online
danh
có th■
hi■u
hi■u
c■p
do
qu■
nh■t
c■ng
và ■KTTSDDV
uy
■■ng
tín nh■t.
bình ch■n
theo quy■t
là website
... ki■m ti■n online hi■u qu■ và uy tín nh■t.
HANOI, 04/2022
Lnh■n
123doc
Sau
Th■a
Xu■t
khi
h■■ng
phát
thu■n
cam
nh■n
m■t
t■k■t
s■
t■i
ýxác
n■m
t■■ng
d■ng
là
s■
nh■n
website
ra
mang
■■i,
1.
t■o
t■l■i
c■ng
■■ng
d■n
123doc
CH■P
nh■ng
■■u
■■ng
h■
NH■N
■ã
quy■n
th■ng
chia
t■ng
ki■m
CÁC
s■s■
l■i
b■■c
ti■n
vàchuy■n
■I■U
t■t
mua
online
kh■ng
nh■t
bán
KHO■N
sang
b■ng
cho
■■nh
thay
ng■■i
ph■n
tài
TH■A
vìv■
li■u
m■i
thơng
dùng.
tríTHU■N
hi■u
m■t
c■atin
Khi
qu■
mình
cá
xác
khách
nhân
nh■t,
minh
trong
Chào
kinh
hàng
uy
tài
l■nh
m■ng
doanh
tín
kho■n
tr■
v■c
cao
thành
b■n
t■
email
nh■t.
tàith■c
■■n
li■u
thành
b■n
Mong
hi■n
và
v■i
viên
kinh
■ã
123doc.
123doc.net!
mu■n
ngh■a
■■ng
c■a
doanh
mang
123doc
v■
kýonline.
c■a
v■i
Chúng
l■ivà
123doc.netLink
mình
cho
Tính
n■p
tơi
c■ng
thì
■■n
cung
ti■n
s■p
■■ng
th■i
vào
c■p
t■i,
xác
tài
■i■m
D■ch
xã
ngh■a
kho■n
th■c
h■itháng
V■
m■t
s■
v■
c■a
(nh■
■■■c
c■a
ngu■n
5/2014;
123doc,
■■■c
c■a
g■i
tài
123doc
hàng
v■
mơ
ngun
b■n■■a
t■
tri■u
s■
v■■t
d■■i
tri
■■■c
ch■
nhà
th■c
m■c
■ây)
email
bán
h■■ng
q
100.000
cho
hàng
b■n
báu,
b■n,
nh■ng
l■i
■ã
phong
l■■t
chuy■n
tùy
■■ng
quy■n
truy
thu■c
phú,
ky,
c■p
giao
■a
l■i
b■n
vào
m■i
sang
d■ng,
sau
các
vuingày,
n■p
■■n
lịng
“■i■u
giàu
ti■n
s■
■■ng
v■
giá
Kho■n
h■u
qu■n
trên
tr■
nh■p
2.000.000
website
■■ng
Th■a
lý hồn
email
th■i
Thu■n
h■o,
c■a
thành
mong
v■
■■
mình
viên
mu■n
S■
cao
và
■■ng
D■ng
tính
click
t■otrách
ký,
D■ch
■i■u
vàol■t
link
nhi■m
ki■n
V■”
vào
123doc
top
sau
cho
■■i
200
■ây
cho
v■i
■ãcác
các
(sau
g■i
t■ng
website
users
■ây
ng■■i
■■■c
cóph■
dùng.
thêm
bi■n
g■i
thu
M■c
t■t
nh■t
nh■p.
T■i
tiêu
t■i
t■ng
hàng
Chính
Vi■tth■i
■■u
Nam,
vì v■y
■i■m,
c■a
t■123doc.net
l■
123doc.net
chúng
tìm ki■m
tơiracó
tr■
thu■c
■■i
th■
thành
nh■m
c■p
topth■
3nh■t
■áp
Google.
vi■n
■KTTSDDV
■ng
tàiNh■n
nhu
li■uc■u
online
■■■c
theo
chia
l■n
quy■t
danh
s■nh■t
tài
hi■u
...li■u
Vi■t
do
ch■t
Nam,
c■ng
l■■ng
cung
■■ng
và
c■p
bình
ki■m
nh■ng
ch■n
ti■ntài
là
online.
website
li■u ■■cki■m
khơng
ti■n
th■
online
tìm th■y
hi■utrên
qu■th■
và tr■■ng
uy tín nh■t.
ngo■i tr■ 123doc.net.
Ln
Th■a
Xu■t
Sau
Nhi■u
123doc
Mang
thayh■n
khi
vì
h■■ng
phát
thu■n
l■i
event
m■i
cam
s■
nh■n
m■t
tr■
t■
h■u
m■t
k■t
s■
thú
nghi■m
t■i
ýxác
n■m
t■■ng
m■t
d■ng
v■,
là
s■
cá
nh■n
website
ra
nhân
mang
event
kho
m■i
■■i,
1.
t■o
t■
th■
kinh
m■
l■i
c■ng
ki■m
■■ng
d■n
123doc
CH■P
vi■n
nh■ng
cho
doanh
■■u
■■ng
ti■n
h■
kh■ng
ng■■i
NH■N
■ã
quy■n
th■ng
thi■t
chia
t■t■ng
ki■m
th■c
dùng,
l■
CÁC
s■
th■c.
s■
l■i
b■■c
v■i
ti■n
và
hi■n
chuy■n
■I■U
t■t
cơng
h■n
mua
123doc
online
kh■ng
ngh■a
nh■t
2.000.000
ngh■
bán
KHO■N
sang
b■ng
ln
cho
tài
■■nh
v■
hi■n
ng■■i
li■u
ph■n
ln
c■a
tài
TH■A
tài
v■
th■
li■u
hàng
t■o
mình
li■u
thơng
dùng.
tríhi■n
THU■N
hi■u
c■
c■a
■■u
■
thìtin
t■t
h■i
Khi
■■i,
qu■
s■p
mình
Vi■t
xác
c■
khách
gia
b■n
t■i,
nh■t,
minh
trong
l■nh
Nam.
t■ng
Chào
ngh■a
online
hàng
uy
tài
v■c:
l■nh
thu
Tác
m■ng
tín
kho■n
tr■
nh■p
khơng
v■
tài
phong
v■c
cao
thành
b■n
chính
c■a
email
nh■t.
tài
online
khác
chun
■■n
c■a
li■u
thành
tínb■n
Mong
gì
cho
d■ng,
và
hàng
v■i
so
nghi■p,
viên
kinh
■ã
t■t
123doc.
123doc.net!
v■i
mu■n
tri■u
cơng
■■ng
c■a
c■
doanh
b■n
các
hồn
nhà
mang
ngh■
123doc
ký
g■c.
online.
thành
bán
v■i
h■o,
Chúng
l■i
thơng
B■n
và
hàng
123doc.netLink
cho
viên
Tính
■■
n■p
có
tơi
tin,
c■ng
l■i
c■a
cao
th■
■■n
cung
ti■n
ngo■i
chuy■n
tính
website.
phóng
■■ng
th■i
vào
c■p
ng■,...Khách
trách
xác
tài
■i■m
D■ch
giao
xã
to,kho■n
th■c
nhi■m
h■i
thu
sang
tháng
V■
nh■
m■t
s■
c■a
(nh■
■■i
■■n
hàng
■■■c
tùy
ngu■n
5/2014;
123doc,
v■i
v■
■■■c
ý.
cóg■i
t■ng
qu■n
th■
tài
123doc
v■
mơ
ngun
b■n
d■
ng■■i
lý,
■■a
t■
dàng
s■
cơng
v■■t
d■■i
tri
dùng.
■■■c
ch■
tra
th■c
ngh■
m■c
■ây)
email
c■u
M■c
h■■ng
q
hi■n
100.000
cho
tài
b■n
tiêu
báu,
li■u
b■n,
th■
nh■ng
■ã
hàng
phong
m■t
l■■t
hi■n
tùy
■■ng
■■u
quy■n
cách
truy
thu■c
■■i,
phú,
ky,
c■a
c■p
chính
■a
b■n
l■i
b■n
vào
123doc.net
m■i
d■ng,
sau
online
xác,
các
vuingày,
n■p
lịng
“■i■u
nhanh
giàu
khơng
ti■n
s■
■■ng
tr■
giá
Kho■n
chóng.
h■u
trên
khác
thành
tr■
nh■p
2.000.000
website
■■ng
Th■a
gìth■
so
email
vi■n
th■i
v■i
Thu■n
c■a
thành
b■n
mong
tài v■
li■u
mình
g■c.
viên
mu■n
S■
online
và
B■n
■■ng
D■ng
click
t■o
l■n
cóký,
D■ch
■i■u
vào
th■
nh■t
l■t
link
phóng
ki■n
V■”
vào
Vi■t
123doc
top
sau
cho
to,
Nam,
200
thu
■ây
cho
■ã
cung
nh■
các
các
(sau
g■iwebsite
tùy
c■p
users
■ây
ý.nh■ng
■■■c
cóph■
thêm
tài
bi■n
g■i
thu
li■u
t■t
nh■t
nh■p.
■■c
T■it■i
khơng
t■ng
Chính
Vi■tth■i
th■
Nam,
vì v■y
■i■m,
tìm
t■123doc.net
th■y
l■chúng
tìm
trên
ki■m
tơi
th■
racóthu■c
■■i
tr■■ng
th■nh■m
c■p
top
ngo■i
3nh■t
■áp
Google.
tr■
■KTTSDDV
■ng
123doc.net.
Nh■n
nhu c■u
■■■c
theo
chiaquy■t
danh
s■ tài
hi■u
...li■udo
ch■t
c■ng
l■■ng
■■ng
vàbình
ki■mch■n
ti■n là
online.
website ki■m ti■n online hi■u qu■ và uy tín nh■t.
Chia
m■t
u■t
Nhi■u
Mang
Ln
123doc
Th■a
Xu■t
Sau
tri■n
phát
khi
h■n
member
s■
h■■ng
phát
khai
thu■n
l■i
event
s■
cam
nh■n
câu
t■
m■t
tr■
t■
event
h■u
ýk■t
s■
chuy■n
thú
nghi■m
t■i
ýkhơng
t■■ng
xác
n■m
t■■ng
m■t
d■ng
v■,
là
khuy■n
s■
nh■n
website
ra
mang
m■y
event
t■o
kho
thành
m■i
■■i,
1.
t■o
t■
mãi
c■ng
th■
n■i
m■
l■i
c■ng
ki■m
■■ng
d■n
cơng
123doc
CH■P
th■
vi■n
b■t
nh■ng
cho
■■ng
■■u
■■ng
ti■n
trên
n■p
h■
c■a
kh■ng
ng■■i
NH■N
■ã
quy■n
th■ng
123doc
thi■t
chia
ki■m
v■i
c■ng
t■ng
ki■m
dùng,
l■
CÁC
s■
nh■ng
th■c.
ti■n
s■
l■i
b■■c
■■ng
v■i
ti■n
-và
ki■m
chuy■n
■I■U
t■t
cơng
online
h■n
mua
123doc
online
■u
kh■ng
123doc
nh■t
5■ãi
2.000.000
ngh■
bán
KHO■N
tri■u
b■ng
sang
b■ng
ln
cho
c■c
tài
■■nh
■ã
hi■n
ch■
tài
ng■■i
li■u
ph■n
ln
k■
tài
TH■A
xu■t
li■u
tài
v■
v■i
th■
li■u
h■p
hàng
t■o
li■u
thơng
s■c
dùng.
trí
hi■u
7hi■n
THU■N
hi■u
d■n.
tài
c■
c■a
■■u
■■■ng
li■u!
tin
qu■
t■t
h■i
Khi
■■i,
qu■
mình
■■ng
Vi■t
xác
c■
khách
gia
nh■t,
Nghe
trong
b■n
nh■t,
minh
trong
l■nh
Nam.
t■ng
Chào
b■online
có
uy
hàng
danh
l■
uy
tài
v■c:
l■nh
thu
Tác
v■
tín
m■ng
nhé,
tín
kho■n
tr■
sách
cao
nh■p
khó
khơng
tài
phong
v■c
cao
tr■■c
thành
b■n
chính
nh■t.
tin
Top
email
nh■t.
tài
online
khác
nh■ng
chun
■■n
li■u
tiên
thành
danh
tín
Mong
b■n
Mong
gì
cho
d■ng,
và
hãy
v■i
■ây
so
thu
nghi■p,
viên
kinh
■ã
mu■n
t■t
123doc.
123doc.net!
cùng
v■i
mu■n
cao
là
cơng
■■ng
c■a
c■
doanh
b■n
con
nh■t
mang
tìm
các
hồn
mang
ngh■
123doc
s■
ký
g■c.
hi■u
online.
thành
tháng
v■i
l■i
hồn
h■o,
Chúng
l■i
thơng
B■n
thơng
cho
và
123doc.netLink
cho
viên
t■o
tồn
Tính
■■
n■p
có
c■ng
tơi
tin,
c■ng
tin
c■
c■a
cao
th■
chính
■■n
cung
ti■n
ngo■i
v■
h■i
■■ng
tính
website.
phóng
■■ng
Khách
th■i
vào
c■p
xác
gia
ng■,...Khách
trách
xác
xã
tài
t■ng
■i■m
mà
D■ch
xã
to,
hàng
h■i
kho■n
th■c
nhi■m
h■i
BQT
thu
thu
m■t
tháng
V■
có
nh■
m■t
s■
nh■p
123doc
c■a
th■
(nh■
■■i
hàng
ngu■n
■■■c
tùy
ngu■n
5/2014;
123doc,
d■
v■i
online
■■■c
ý.
có
■ã
dàng
tài
g■i
t■ng
th■
tài
thu
123doc
ngun
cho
v■
mơ
ngun
b■n
tra
d■
ng■■i
th■p
t■t
■■a
t■
c■u
dàng
s■
v■■t
tri
d■■i
c■
■■■c
tri
dùng.
■■■c
ch■
tài
th■c
các
tra
th■c
m■c
li■u
■ây)
email
c■u
sau
thành
q
M■c
h■■ng
q
m■t
100.000
cho
■■t
tài
báu,
b■n
tiêu
báu,
viên
li■u
cách
b■n,
t■ng
nh■ng
phong
■ã
hàng
phong
c■a
m■t
l■■t
chính
tùy
■■ng
k■t
■■u
website.
phú,
quy■n
cách
truy
thu■c
phú,
doanh
xác,
ky,
c■a
c■p
■a
chính
■a
nhanh
l■i
b■n
vào
d■ng,
thu
123doc.net
m■i
d■ng,
sau
xác,
các
vui
tháng
chóng.
ngày,
n■p
giàu
lịng
“■i■u
nhanh
giàu
11
ti■n
giá
s■
■■ng
tr■
giá
uy
Kho■n
chóng.
h■u
tr■
trên
tín
thành
tr■
nh■p
■■ng
cao
2.000.000
website
■■ng
Th■a
th■
nh■t.
email
th■i
vi■n
th■i
Thu■n
Mong
mong
c■a
thành
mong
tài v■
li■u
mình
mu■n
mu■n
viên
mu■n
S■
online
và
■■ng
D■ng
mang
t■o
click
t■o
l■n
■i■u
ký,
D■ch
■i■u
vào
l■i
nh■t
l■t
cho
link
ki■n
ki■n
V■”
vào
Vi■t
c■ng
123doc
cho
top
sau
cho
Nam,
■■ng
cho
200
■ây
cho
■ã
cung
các
các
các
(sau
g■i
xãusers
website
h■i
c■p
users
■ây
m■t
nh■ng
có
■■■c
cóph■
thêm
ngu■n
thêm
tài
bi■n
g■i
thu
thu
li■u
tài
t■t
nh■p.
nh■t
nh■p.
ngun
■■c
T■it■i
Chính
khơng
t■ng
Chính
Vi■t
tri th■c
th■i
vìth■
Nam,
vìv■y
v■y
q
■i■m,
tìm
123doc.net
t■123doc.net
báu,
th■y
l■chúng
tìm
phong
trên
ki■m
tơi
ra
th■
ra
phú,
có
■■i
thu■c
■■i
tr■■ng
th■
■Sau
nh■m
nh■m
c■p
top
ngo■i
h■n
■áp
3nh■t
■áp
Google.
m■t
■ng
tr■
■KTTSDDV
■ng
123doc.net.
n■m
nhu
Nh■n
nhuc■u
rac■u
■■i,
■■■c
chia
theo
chia
123doc
s■
quy■t
danh
s■tàitài
hi■u
li■u
■ã
...li■u
t■ng
ch■t
do
ch■t
c■ng
b■■c
l■■ng
l■■ng
■■ng
kh■ng
vàvàki■m
bình
ki■m
■■nh
ch■n
ti■n
ti■n
v■
online.
là
online.
tríwebsite
c■a mình
ki■m
trong
ti■nl■nh
online
v■c
hi■u
tài li■u
qu■và
vàkinh
uy tín
doanh
nh■t.online
Nhi■u
Mang
Ln
123doc
Th■a
Xu■t
Sau
khi
h■n
h■■ng
phát
thu■n
l■i
event
s■
cam
nh■n
m■t
tr■
t■
h■u
k■t
s■
thú
nghi■m
t■i
ýxác
n■m
t■■ng
m■t
d■ng
v■,
là
s■
nh■n
website
ra
mang
event
kho
m■i
■■i,
1.
t■o
t■
th■
m■
l■i
c■ng
ki■m
■■ng
d■n
123doc
CH■P
vi■n
nh■ng
cho
■■u
■■ng
ti■n
h■
kh■ng
ng■■i
NH■N
■ã
quy■n
th■ng
thi■t
chia
t■ng
ki■m
dùng,
l■
CÁC
s■
th■c.
s■
l■i
b■■c
v■i
ti■n
vàchuy■n
■I■U
t■t
cơng
h■n
mua
123doc
online
kh■ng
nh■t
2.000.000
ngh■
bán
KHO■N
sang
b■ng
ln
cho
tài
■■nh
hi■n
ng■■i
li■u
ph■n
ln
tài
TH■A
tài
v■
th■
li■u
hàng
t■o
li■u
thơng
dùng.
tríhi■n
THU■N
hi■u
c■
c■a
■■u
■ tin
t■t
h■i
Khi
■■i,
qu■
mình
Vi■t
xác
c■
khách
gia
b■n
nh■t,
minh
trong
l■nh
Nam.
t■ng
Chào
online
hàng
uy
tài
v■c:
l■nh
thu
Tác
m■ng
tín
kho■n
tr■
nh■p
khơng
tài
phong
v■c
cao
thành
b■n
chính
email
nh■t.
tài
online
khác
chun
■■n
li■u
thành
tínb■n
Mong
gì
cho
d■ng,
và
v■i
so
nghi■p,
viên
kinh
■ã
t■t
123doc.
123doc.net!
v■i
mu■n
cơng
■■ng
c■a
c■
doanh
b■n
các
hồn
mang
ngh■
123doc
ký
g■c.
online.
thành
v■i
h■o,
Chúng
l■i
thơng
B■n
và
123doc.netLink
cho
viên
Tính
■■
n■p
có
tơi
tin,
c■ng
c■a
cao
th■
■■n
cung
ti■n
ngo■i
tính
website.
phóng
■■ng
th■i
c■p
thay
ng■,...Khách
trách
xác
■i■m
D■ch
xã
to,
vì th■c
nhi■m
m■i
h■i
thutháng
V■
nh■
m■t
s■(nh■
■■i
hàng
■■■c
tùy
ngu■n
5/2014;
cáv■i
nhân
■■■c
ý.
cóg■i
t■ng
th■
tài
123doc
kinh
v■
mơ
ngun
d■
ng■■i
doanh
■■a
t■
dàng
v■■t
d■■i
tri
dùng.
ch■
t■
tra
th■c
m■c
■ây)
th■c
email
c■u
M■c
q
100.000
cho
tài
hi■n
b■n
tiêu
báu,
li■u
b■n,
ngh■a
■ã
hàng
phong
m■t
l■■t
tùy
■■ng
■■u
cách
truy
v■
thu■c
phú,
ky,
c■a
c■a
c■p
chính
■a
b■n
vào
mình
123doc.net
m■i
d■ng,
xác,
các
vuingày,
thì
lịng
“■i■u
nhanh
giàu
s■p
s■
■■ng
tr■
giá
t■i,
Kho■n
chóng.
h■u
thành
tr■
ngh■a
nh■p
2.000.000
■■ng
Th■a
th■
email
v■vi■n
th■i
Thu■n
c■a
c■a
thành
mong
tài
c■a
v■
li■u
mình
viên
hàng
mu■n
S■
online
và
■■ng
D■ng
tri■u
click
t■o
l■n
ký,
D■ch
■i■u
vào
nhà
nh■t
l■t
link
bán
ki■n
V■”
vào
Vi■t
123doc
hàng
top
sau
cho
Nam,
200
l■i
■ây
cho
■ã
chuy■n
cung
các
các
(sau
g■iwebsite
c■p
users
■ây
giao
nh■ng
■■■c
cósang
ph■
thêm
tài
bi■n
g■i
■■n
thu
li■u
t■t
nh■t
v■
nh■p.
■■c
T■i
qu■n
t■i
khơng
t■ng
Chính
Vi■t
lý th■i
quy■n
th■
Nam,
vì v■y
■i■m,
tìm
l■i
t■123doc.net
th■y
l■
sau
chúng
tìm
trên
n■p
ki■m
tơi
th■
ti■n
racóthu■c
■■i
tr■■ng
trên
th■nh■m
c■p
website
top
ngo■i
3nh■t
■áp
Google.
tr■
■KTTSDDV
■ng
123doc.net.
Nh■n
nhu c■u
■■■c
theo
chiaquy■t
danh
s■ tài
hi■u
...li■udo
ch■t
c■ng
l■■ng
■■ng
vàbình
ki■mch■n
ti■n là
online.
website ki■m ti■n online hi■u qu■ và uy tín nh■t.
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Declaration of Authorship and Topic
Sentences
Personal Information
• Full name: Nguyen Quang Thang
• Email:
• Class: Data Science
• Tel: 098 669 1647
• Program: Full-time program
• This thesis is performed at: School of Information and Communication Technology
• This thesis is performed: from 10/04/2021 to 10/04/2022
Goals of the Thesis
• Proposing optimizing rules on smart contract source codes using Solidity language.
• Developing a tool named GasSaver, an automatic tool for detecting the wastinggas Solidity source codes and suggesting solutions.
• Conducting experiments and evaluating GasSaver.
Main Tasks of the Thesis
• Study on the blockchain, smart contract, and optimizing smart contract gas
fee on Ethereum
• Collect and analyze the typical wasting gas issues on Solidity smart contract
3
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
• Present seven rules for reducing the gas fee on the smart contract.
• Develop a tool name GasSaver, which implements the seven rules above to
automatically detect the wasting-gas Solidity source codes and suggest solutions for these issues.
• Implement experiments and evaluation GasSaver efficiency.
• Conclude and outline future developments
Declaration of Authorship
I - Nguyen Quang Thang - hereby warrant that the work and presentation in this
thesis are performed by myself under the supervision of Dr. Do Ba Lam.
All results presented in this thesis are truthful and are not copied from any other
works.
Attestation of the Supervisor on the Fulfillment of the Requirements
for the Thesis:
................................................................................
.................................................................................
.................................................................................
.................................................................................
Supervisor
Hanoi, 10th Apr 2022
Author
Dr. Do Ba Lam
Nguyen Quang Thang
4
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Acknowledgements
I want to acknowledge and give my warmest thanks to my supervisor, Dr. Do Ba
Lam. He is an excellent blockchain researcher, gave me the golden opportunity to
do this research on optimizing gas fees on the smart contract, which also helped
me do a lot of research, and I came to know about so many new things. Not
only that, he is very kind and friendly and inspired me a lot in my research
career path.
I would also like to give a special thanks to my girlfriend Nguyen Thi Tham and
my family for their mental support during my thesis writing process. Moreover,
in the absence of my friends, Tong Van Vinh, Hong Ngoc, Xuan Thu, and Thanh
Dat, I could hardly melt away all the tension from my work. I also thank Thanks
for always accompanying me through ups and downs.
5
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Abstract
Currently, the number of smart contracts using Solidity language in Ethereum is
increasing at a breakneck speed. In this context, optimizing gas fees in smart
contracts becomes necessary to save costs for both developers and users who interact directly with these contracts. To optimize gas, developers typically need to
have deep knowledge of blockchain and programming languages, making it a significant challenge for new programmers. This thesis, we introduce GasSaver – an
open-source tool that analyzes Solidity-based contracts and suggests modifications
to reduce transaction fees. Our tool, which relies on seven rules for identifying
non-optimized codes, shows that 6,333 in a total of 10,245 top most interactive
contracts on Ethereum contain at least one optimization problem and the problems
are more than 30,000. Hence, the use of this tool can reduce a considerable cost
for the deployment and interaction of smart contracts.
Author
Nguyen Quang Thang
6
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Table of Contents
Declaration of Authorship and Topic Sentences
3
Acknowledgement
5
Abstract
6
Lists of Figures
9
Lists of Tables
10
Lists of Listing
11
1
2
3
Background and related work
1.1 Blockchain . . . . . . . . . . . . . . . . . .
1.2 Ethereum and smart contracts . . . . . . . .
1.2.1 Ethereum blockchain . . . . . . . .
1.2.2 Smart contracts on Ethereum . . . .
1.2.3 Ethereum Virtual Machine (EVM) .
1.2.4 Gas and payment . . . . . . . . . .
1.2.5 Solidity - a high-level language for
1.3 Related work . . . . . . . . . . . . . . . . .
1.3.1 Bytecode related work . . . . . . .
1.3.2 High-level language related work .
1.3.3 Evaluation . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
developing smart
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
contracts
. . . . .
. . . . .
. . . . .
. . . . .
Gas-inefficient Programming Patterns
2.1 Data Representation . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1.1 Pattern 1: Members Arrangement in Struct (MAS) . . . .
2.1.2 Pattern 2: Data Location and Function Visibility (DLFV)
2.1.3 Pattern 3: Constant State Variables (CSV) . . . . . . . . .
2.1.4 Pattern 4: Immutable State Variables (ISV) . . . . . . . . .
2.2 Logic Relation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.1 Pattern 5: Operator Reduction in Expression (ORE) . . . .
2.2.2 Pattern 6: Repeated Computation in Loop (RCL) . . . . .
2.2.3 Pattern 7: Loop Combination (LC) . . . . . . . . . . . . .
2.3 Sumnary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
15
17
17
18
19
20
21
23
23
26
26
.
.
.
.
.
.
.
.
.
.
27
27
27
29
31
32
34
34
35
37
38
Implementation
3.1 System Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Rule Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2.1 Members Arrangements in Struct . . . . . . . . . . . . . . . .
39
39
40
40
.
.
.
.
.
.
.
.
.
.
7
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.2.7
4
Data Location and Function Visibility
Constant State Variables . . . . . . .
Immutable State Variables . . . . . .
Operator Reduction in Expression . .
Repeated Computation in Loop . . .
Loop Combination . . . . . . . . . . .
Experiments and Evaluations
4.0.1 Optimization Findings
4.0.2 Execution Time . . .
4.0.3 Comparison . . . . . .
4.0.4 Evaluation . . . . . .
.
.
.
.
.
.
.
.
References
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
42
43
43
44
44
46
.
.
.
.
48
48
49
49
51
56
8
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
List of Figures
1
Opensea - the most prominent digital marketplace for crypto collectibles and non-fungible tokens [1] . . . . . . . . . . . . . . . . . .
13
1.1
1.2
Blockchain model networks . . . . . . . . . . . . . . . . . . . . . . . .
Ethereum state machine mechanism . . . . . . . . . . . . . . . . . . .
15
17
3.1
3.2
39
3.8
System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Members Arrangements in
Struct issue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Data Location and Function
Visibility issue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Constant State Variables issue
The example output of GasSaver with Immutable State Variables issue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Operator Reduction in Expression issue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Repeated Computation in Loop
issue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The example output of GasSaver with Loop Combination issue . .
4.1
4.2
4.3
4.4
4.5
4.6
Distribution of Violations on the First Dataset . . . . . . . . . .
Distribution of Violations on the Second Dataset . . . . . . . . .
Time Executions on the First Dataset . . . . . . . . . . . . . . .
Time Executions on the Second Dataset . . . . . . . . . . . . . .
Violations on the First Dataset of GasSaver and Tamara’s tool .
Time comparison of GasSaver and Tamara’s tool . . . . . . . .
49
50
50
51
52
52
3.3
3.4
3.5
3.6
3.7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
42
43
44
45
46
46
47
9
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
List of Tables
1.1
1.2
EVM operation gas cost overview . . . . . . . . . . . . . . . . . . .
EVM operation gas refund overview . . . . . . . . . . . . . . . . . .
22
23
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
Costs of deployment and function call in Listing 2.1
Costs of deployment and function Call in Listing 2.2
Costs of deployment and function call in Listing 2.3
The difference in assembly code in Listing 2.3 . . .
Costs of deployment and function call in Listing 2.4
Costs of deployment and function call in Listing 2.5
Costs of deployment and function call in Listing 2.6
Costs of deployment and function call in Listing 2.7
.
.
.
.
.
.
.
.
29
31
32
32
34
35
36
38
4.1
Costs of deployment and function call in SAC Contract . . . . . . .
54
.
.
.
.
.
.
.
. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
10
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
List of Listings
2.1
2.2
2.3
2.4
2.5
2.6
2.7
3.1
4.1
4.2
An example of Members Arrangement in A Struct issue . .
An example of Data Location and Function Visibility issue
An example of Constant State Variable issue . . . . . . . . .
An example of Immutable State Variable issue . . . . . . . .
An example of Operator Reduction in Expression issue . . .
An example of Repeated Computation in Loop issue . . . .
An example of Loop Fusion issue . . . . . . . . . . . . . . .
Check Members Arrangements in Struct approach . . . . . .
A Sample Contract . . . . . . . . . . . . . . . . . . . . . . . .
The Optimized Contract . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
28
30
31
33
34
36
37
41
53
53
11
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Introduction
In recent years, blockchain has been raised as one of the promising technologies that can make considerable changes to the operations of companies, organizations, and governments over the world [2]. An important factor contributing
to the success of blockchain is smart contracts that represent complex agreements
through codes and provide automated execution flow without the intervention of
any third party. The Uniswap protocol is a suite of persistent, non-upgradable
smart contracts that together create an automated market maker. This protocol facilitates a peer-to-peer market for making and swapping ERC-20 tokens on the
Ethereum blockchain. Users can easily exchange tokens with each other quickly,
anytime, anywhere. Uniswap is the most prominent place for exchanging assets
in the Ethereum network, with over 831 billion USD trading volume and over 88
million exchanging transactions. OpenSea is another example of using the smart
contract in blockchain networks. OpenSea is the world’s first and largest digital
marketplace for crypto-collectibles and non-fungible tokens (NFTs), with over 2.4
million sold items, and the volume is around 4.9 billion USD in January 2022.
With the ability to represent complex agreements through codes and provide automated execution flow without the intervention of any third party, smart contracts
are used in a wide range of fields, including finance, arts, games, etc.
Any developer can easily create a smart contract and publish it to a target network
after paying a fee for them. Next, users can call the smart contract to execute its
functions once they have a balance covering the transaction fee for the network.
As of January 2022, 458,939 smart contracts have been created on Ethereum with
a total fee of 293,770.336 USD [3]. Opensea – Wyvernexchange, one of the top
contracts by usage, reached 72,480 transactions on February 12th, 2022, with a
total gas of 13.43 billion, which equals $1.5 million [4] at that time. These numbers show that the costs of deploying and calling smart contracts are huge if these
contracts are not optimized in advance. On the other hand, these expenditures will
continue to increase according to the rapid introduction of new contracts and the
proliferation of existing contracts. Therefore optimizing gas used in smart contracts
on Ethereum is essential.
Gas optimization can be performed through two main steps, i.e., (i) detect inefficient codes and (ii) fix these codes. The first step mentions parsing the source
code of smart contracts based on the knowledge of analyzers to identify the position of inefficient codes. Next, we change these inefficient codes without changing
12
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Figure 1: Opensea - the most prominent digital marketplace for crypto collectibles
and non-fungible tokens [1]
the logic of the programs to fix these issues. To obtain this goal, developers can
select two main approaches. Firstly, they need in-depth study languages to develop smart contracts on Ethereum, such as Solidity, Vyper, etc..., and optimize
the smart contracts by themselves. Secondly, they can rely on third parties for
optimizing smart contracts and using suggested results. However, there are two
main issues with existing approaches. Firstly, it takes a long time for developers
to study and have deep knowledge about smart contracts language on Ethereum,
especially with newbies. The reason is that optimizing gas consumption in smart
contracts is entirely different from optimizing source code in traditional programming languages such as Python, Java, C, etc... In addition, developers can not
proactively optimize smart contracts if they do not have enough experience. Even
with experienced developers, it still takes time to optimize smart contracts, especially big-sized smart contracts. Secondly, if they choose third parties to optimize
gas used in smart contracts, they must pay a considerable fee for these parties; in
some cases, this fee can be greater than the wasted money from the smart contracts. Furthermore, the vulnerability of leaking the source code of smart contracts
before release may occur.
To address the challenges above, we first comprehensively research Solidity – the
most popular language used in developing smart contracts and then present the
rules describing the wasted codes and how to fix them without changing the logic
of smart contracts. Next, we develop an automatic gas optimizer for detecting and
suggesting solutions for Solidity-based smart contracts before developers publish
13
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
them on Ethereum. Generally, we make contributions as follows:
• Although many people research gas-saving on smart contracts, their works
typically are on bytecode contracts. Therefore, it is challenging for developers to fix contracts when problems are found because developers typically
use high-level language to develop smart contracts. So, based on the existing related research, we extended three rules and introduced four novel rules
to detect gas-wasting codes on smart contract source codes (Solidity source
codes). Then we state the solution to optimize these inefficient codes without
changing the logic.
• We developed a tool named GasSaver, an automatic tool for detecting the
wasting-gas source codes and suggesting solutions on Solidity-based smart
contracts. The source code and experiment datasets are published on Github
at GasSaver.
• We apply GasSaver to 10,245 verified contracts in the top 15,000 smart contracts ranked by the number of caller addresses on Ethereum and find out
over 30,000 issues, in which 6,333 smart contracts contain wasted codes.
The results have demonstrated the efficiency of GasSaver.
The remainder of this thesis is organized as follows. In Chapter 1, we discuss the
backgound and related work. Chapter 2 presents inefficient programming patterns
and solutions for each problem. Next, Chapter 3 illustrates the design of GasSaver
through detailed implementation. Chapter 4 discusses evaluation of GasSaver.
14
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Chapter 1
Background and related work
This chapter will introduce the related knowledge and technologies to clarify my
thesis. I will present the overview of blockchain in Section 1.1, then especially
on Ethereum blockchain, smart contract knowledge on Ethereum and Solidity- the
most popular programming language used to develop smart contracts on Ethereum
at Section 1.2
1.1
Blockchain
A blockchain is a public database that is updated and shared across many computers in a network. “Block” refers to data and states stored in consecutive groups
known as “blocks”. “Chain” refers to the fact that each block cryptographically
references its parent. In other words, blocks get chained together. The data in a
block cannot change without changing all subsequent blocks, which would require
the consensus of the entire network.
Figure 1.1 briefly describes blockchain. When a new block is created, it is linked
to the previous block via the previous ’s block hash. When the data in Block 1 is
changed, it causes the hash of Block 1 is changed, and the consequence is Block
2 cannot link to Block 1. So, to change the data in the blockchain at a block,
they must change all data after the changed block. Because of the difficulty when
a new block is created, changing data in the blockchain is impossible in the real
world.
Block 1
Block 2
Block 3
Block 4
Previous: 000
Previous: 1AB
Previous: 4A9
Previous: 872
Hash: 1AB
Hash: 4C9
Hash: 872
Hash: 29D
Figure 1.1: Blockchain model networks
15
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Blockchain consists of four main definitions: “block”, “node”, “concensus mechanism”, and “minners”.
Block: Every blockchain includes linked blocks together. Each block includes
transactions and other properties such as before block hash, timestamp, nonce, etc.
The block’s hash represents the block and is used to link with a new block to
ensure the immutable data and the scalability of blockchain networks. New blocks
are broadcast to the nodes in the network, checked, and verified, thus updating the
state of the blockchain for everyone.
Node: Decentralization is one of the most significant advantages of blockchain.
No one or organization can own the blockchain. Every computer must agree upon
each new block and the chain in the blockchain network. These computers are
known as “nodes”. Nodes ensure everyone interacting with the blockchain has the
same data. Nodes can be any device, as long as they can maintain the copy of
the blockchain and keep the network active. With many nodes in the blockchain,
the network will not have the problem if it contains some broken nodes, increasing
the availability of blockchain networks.
Consensus mechanism: To accomplish the distributed agreement, blockchains need
a consensus mechanism. A consensus mechanism is a fault-tolerant mechanism
used in computer and blockchain systems to achieve the necessary agreement on
a single data value or a single state of the network among distributed processes
or multi-agent systems. So, people can not arbitrarily add data to the blockchain,
make the data in all nodes consistent, and difficultly fake data. For example,
Ethereum currently uses a proof-of-work consensus mechanism. This means that
anyone who wants to add new blocks to the chain must solve a complex puzzle
that requires a lot of computing power. Solving the puzzle ”proves” that you have
done the ”work” using computational resources. Doing this is known as mining.
Mining is typically brute force trial and error, but successfully adding a block is
rewarded in ETH.
Minner: Minners do work depending on the consensus mechanism to have the
chance of creating a new block in the current chain. In each blockchain network,
many miners take part in creating a new block, ensure no person or organization
can manipulate the network, and increase the trust in the blockchain. After processing the works depending on the consensus mechanism and pass, miners can
add a block to the chain. If the malicious want to change blockchain data, they
must be permitted to add a block in the chain from the modified block to now.
This condition is impossible because the consensus mechanism prevents everybody
from manipulating the network. So, changing data in the blockchain is challenging. After the mining is successful, all nodes in the network will approve the
change, and miners will reward for this mining.
The combination of public information and consensus mechanism makes the integrity and trust of the user. Therefore, blockchain seems that the technology creates absolute trust between users without the parties.
16
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
1.2
1.2.1
Ethereum and smart contracts
Ethereum blockchain
The Ethereum blockchain is essentially a transaction-based state machine. In computer science, a state machine refers to something that will read a series of inputs
and, based on those inputs, will transition to a new state.
With Ethereum’s state machine, the genesis state is analogous to a blank slate
before any transactions have happened on the network. When transactions are executed, this genesis state transitions into some final state. At any point in time,
this final state represents the current state of Ethereum.
Figure 1.2: Ethereum state machine mechanism
The state of Ethereum has millions of transactions. These transactions are grouped
into“blocks”. A block contains a series of transactions, and each block is chained
together with its previous block. A transaction must be valid to cause a transition
from one state to the next. For a transaction to be considered valid, it must go
through a validation process known as mining. Mining is when a group of nodes
expends their computation resources to create a block of valid transactions. Any
node on the network that declares itself as a miner can attempt to create and
validate a block. Many miners from around the world try to create and validate
blocks simultaneously. Each miner provides a mathematical “proof” when submitting a block to the blockchain, and this proof acts as a guarantee: if the proof
exists, the block must be valid. For a block to be added to the main blockchain,
the miner must prove it faster than any competitor miner. The process of validating each block by having a miner provide a mathematical proof is known as a
“proof of work”. A miner who validates a new block is rewarded with a certain
amount of value for doing this work. The Ethereum blockchain uses an intrinsic
digital token called “Ether”. Every time a miner proves a block, new Ether tokens
are generated and awarded.
The Ethereum blockchain tracks the state of every account, and all state transitions on the Ethereum blockchain are transfers of value and information between
accounts. There are two types of accounts:
• Externally Owned Accounts (EOAs), which are controlled by private keys
• Contract Accounts, which are controlled by their contract code and can only
be “activated” by an EOA
17
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
For most users, the primary difference between these is that human users control EOAs because they can control the private keys which control an EOA. On
the other hand, contract accounts are governed by their internal code. A human
user can control them because they are programmed to be controlled by an EOA
with a specific address, owned by whoever holds the private keys that control that
EOA. The popular term “smart contracts” refers to code in a Contract Account –
programs that execute when a transaction is sent to that account. Users can create
new contracts by deploying code to the blockchain.
Contract accounts only operate when instructed by an EOA. So a Contract account
can’t be performing native operations like random number generation or API calls
– it can do these things only if prompted by an EOA. This is because Ethereum
requires nodes to agree on the outcome of computation, which requires a guarantee
of strictly deterministic execution.
Users must pay small transaction fees to the network. This protects the Ethereum
blockchain from frivolous or malicious computational tasks, like DDoS attacks or
infinite loops. The sender of a transaction must pay for each step of the “program” they activated, including computation and memory storage. These fees are
paid in amounts of Ethereum’s native value token, “ether”.
1.2.2
Smart contracts on Ethereum
A “smart contract” is simply a program that runs on the Ethereum blockchain.
It’s a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Smart contracts are a type of Ethereum
account. This means they have a balance and can send transactions over the network. However, they’re not controlled by a user. Instead, they are deployed to the
network and run as programmed. User accounts can then interact with a smart
contract by submitting transactions that execute a function defined on the smart
contract. Smart contracts can define rules, like a regular contract, and automatically enforce them via the code. Smart contracts cannot be deleted by default, and
their interactions are irreversible.
Smart contract on Ethereum contains advantages below:
• Zero downtime: Once the smart contract is deployed and on the blockchain,
the network as a whole will always be able to serve clients looking to interact with the contract. Malicious actors, therefore, cannot launch denial-ofservice attacks targeted toward individual smart contracts.
• Resistance to censorship: No single entity on the network can block users
from submitting transactions, deploying smart contracts, or reading data from
the blockchain.
• Complete data integrity: Data stored on the blockchain is immutable and
indisputable, thanks to cryptographic primitives. As a result, malicious actors
18
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
cannot forge transactions or other data already made public.
• Trustless computation/verifiable behavior: Smart contracts can be analyzed
and are guaranteed to execute in predictable ways, without the need to trust
a central authority. This is not true in traditional models; for example, we
must trust that financial institutions will not misuse our financial data, tamper
with records, or get hacked when using online banking systems.
Anyone can write a smart contract and deploy it to the network. You just need
to learn how to code in a smart contract language and have enough ETH to deploy your contract. Deploying a smart contract is technically a transaction, so you
need to pay your gas in the same way you need to pay gas for a simple ETH
transfer. On the Ethereum blockchain, contracts are typically written in high-level
languages such as Solidity and then compiled into bytecode to be uploaded on
the blockchain. Contracts live on the blockchain in an Ethereum-specific binary
format called Ethereum Virtual Machine (EVM) bytecode. Any user can then call
the smart contract to execute its code, again for a fee paid to the network. Thus,
developers can arbitrarily build and deploy complex user-facing apps and services
such as marketplaces, financial instruments, games, etc.
1.2.3
Ethereum Virtual Machine (EVM)
The analogy of a ’distributed ledger’ is often used to describe blockchains like
Bitcoin, which enable a decentralized currency using fundamental cryptography tools.
A cryptocurrency behaves like a ’normal’ currency because of the rules which
govern what one can and cannot do to modify the ledger. For example, a Bitcoin
address cannot spend more Bitcoin than it has previously received. These rules
underpin all transactions on Bitcoin and many other blockchains.
While Ethereum has its native cryptocurrency (Ether) that follows almost exactly
the same intuitive rules, it also enables a much more powerful function: smart
contracts. For this more complex feature, a more sophisticated analogy is required.
Instead of a distributed ledger, Ethereum is a distributed state machine. Ethereum’s
state is a large data structure that holds all accounts and balances and a machine
state, which can change from block to block according to a pre-defined set of
rules and execute arbitrary machine code. The EVM defines the specific rules of
changing state from block to block.
In computer science, computer engineering, and programming language implementations, a stack machine is a computer processor or a virtual machine in which
the primary interaction is moving short-lived temporary values to and from a pushdown stack. In the case of a hardware processor, a hardware stack is used. The
use of a stack significantly reduces the required number of processor registers.
Stack machines extend push-down automaton with additional load/store operations
or multiple stacks and hence are Turing-complete.
19
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
The EVM is a Turing complete virtual machine, as defined earlier. The only limitation the EVM has that a typical Turing complete machine does not is that the
EVM is intrinsically bound by gas. Thus, the total amount of computation that
can be done is intrinsically limited by the amount of gas provided. The EVM
executes as a stack machine with a depth of 1024 items. Each item is a 256bit word, chosen for ease of use with 256-bit cryptography (such as Keccak-256
hashes or secp256k1 signatures). The EVM maintains a transient memory (as a
word-addressed byte array) during execution, which does not persist between transactions. Contracts, however, do contain a Merkle Patricia storage trie (as a wordaddressable word array) associated with the account in question and part of the
global state. Compiled smart contract bytecode executes several EVM opcodes,
which perform standard stack operations like XOR, AND, ADD, SUB, etc. In addition, the EVM also implements some blockchain-specific stack operations, such
as ADDRESS, BALANCE, BLOCKHASH, etc.
1.2.4
Gas and payment
Gas refers to the unit that measures the computational effort required to execute
specific operations on the Ethereum network. Since each Ethereum transaction requires computational resources to execute, each transaction requires a fee. Gas
refers to the fee required to conduct a transaction on Ethereum successfully. Gas
is the unit used to measure the fees required for a particular computation. Gas
price is the amount of Ether you are willing to spend on every unit of gas and
is measured in “gwei”. “Wei” is the smallest unit of Ether, where 1018 Wei represents 1 Ether. One gwei is 1,000,000,000 Wei. With every transaction, a sender
sets a gas limit and gas price. The gas price and gas limit represent the maximum amount of Wei that the sender is willing to pay for executing a transaction. For example, the sender sets the gas limit to 50,000 and a gas price to
20 gwei. This implies that the sender is willing to spend at most 50,000 x 20
gwei = 1,000,000,000,000,000 Wei = 0.001 Ether to execute that transaction. The
gas limit represents the maximum gas the sender is willing to spend money on.
They’re good to go if they have enough Ether in their account balance to cover
this maximum. The sender is refunded for any unused gas at the end of the transaction, exchanged at the original rate. If the sender does not provide the necessary
gas to execute the transaction, the transaction runs “out of gas” and is considered
invalid. In this case, the transaction processing aborts, and any state changes that
occurred are reversed, such that we end up back at the state of Ethereum before
the transaction. Additionally, a record of the failed transaction shows what was
attempted and where it failed. Since the machine expended effort to run the calculations before running out of gas, logically, none of the gas is refunded to the
sender. Typically, the higher the gas price the sender is willing to pay, the greater
the value the miner derives from the transaction. Thus, the more likely miners
20
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
will be to select it. In this way, miners can choose which transactions they want
to validate or ignore. To guide senders on what gas price to set, miners have the
option of advertising the minimum gas price for which they will execute transactions.
The gas in transactions depends on how much computation is on this. When users
create or interact with smart contracts, it will depend on each operation used in
transactions. Listing 1.1 and 1.2 describe the gas fee and the gas refund for each
operation, respectively.
Where:
• Wzero = {STOP, RETURN, REVERT}
• Wbase = {ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE, GASPRICE, COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT,
CHAINID, RETURNDATASIZE, POP, PC, MSIZE, GAS}
• Wverylow = {ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR,
XOR, BYTE, SHL, SHR, SAR, CALLDATALOAD, MLOAD, MSTORE, MSTORE8,
PUSH*, DUP*, SWAP*}
• Wlow = {MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND, SELFBALANCE}
• Wmid = {ADDMOD, MULMOD, JUMP}
• Whigh = {JUMPI}
• Wcopy = {CALLDATACOPY, CODECOPY, RETURNDATACOPY}
• Wcall = {CALL, CALLCODE, DELEGATECALL, STATICCALL}
• Wextaccount = {BALANCE, EXTCODESIZE, EXTCODEHASH}
1.2.5
Solidity - a high-level language for developing smart contracts
Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs that govern the behavior of accounts within
the Ethereum state. Solidity is a curly-bracket language. It is influenced by C++,
Python, and JavaScript and is designed to target the Ethereum Virtual Machine
(EVM). You can find more details about which languages Solidity has been inspired by in the language influences section. Solidity is statically typed supports
inheritance, libraries, and complex user-defined types, among other features. With
Solidity, you can create contracts for voting, crowdfunding, blind auctions, and
multi-signature wallets.
It is a challenge if smart contract developers directly work with EVM bytecode.
So, typically, smart contract developers use the high-level languages to develop,
compile to EVM bytecode and upload to the Ethereum blockchain. Solidity is
21
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Table 1.1: EVM operation gas cost overview
Name
Gzero
Gjumpdest
Gbase
Gverylow
Glow
Gmid
Ghigh
Gwarmaccess
Gaccesslistaddress
Gaccessliststorage
Gcoldaccountaccess
Gcoldsload
Gsset
Value
0
1
2
3
5
8
10
100
2400
1900
2600
2100
20000
Gsreset
2900
Gselfdestruct
Gcreate
Gcodedeposit
5000
32000
200
Gcallvalue
9000
Gcallstipend
2300
Gnewaccount
25000
Gexp
Gexpbyte
10
50
Gmemory
Gtxcreate
3
32000
Gtxdatazero
Gtxdatanonzero
Gtransaction
Glog
Glogdata
Glogtopic
Gkeccak256
Gkeccak256word
4
16
21000
375
8
375
30
6
Gcopy
3
Gblockhash
20
Description
Nothing paid for operations of the set Wzero .
Amount of gas to pay for a JUMPDEST operation.
Amount of gas to pay for operations of the set Wbase .
Amount of gas to pay for operations of the set Wverylow .
Amount of gas to pay for operations of the set Wlow .
Amount of gas to pay for operations of the set Wmid .
Amount of gas to pay for operations of the set Whigh .
Cost of a warm account or storage access.
Cost of warming up an account with the access list.
Cost of warming up a storage with the access list.
Cost of a cold account access.
Cost of a cold storage access.
Paid for an SSTORE operation when the storage value is set to
non-zero from zero.
Paid for an SSTORE operation when the storage value’s zeroness remains unchanged or is set to zero
Amount of gas to pay for a SELFDESTRUCT operation.
Paid for a CREATE operation.
Paid per byte for a CREATE operation to succeed in placing
code into state.
Paid for a non-zero value transfer as part of the CALL operation.
A stipend for the called contract subtracted from Gcallvalue for
a non-zero value transfer.
Paid for a CALL or SELFDESTRUCT operation which creates
an account.
Partial payment for an EXP operation.
Partial payment when multiplied by the number of bytes in the
exponent for the EXP operation.
Paid for every additional word when expanding memory.
Paid by all contract-creating transactions after the Homestead
transition.
Paid for every zero byte of data or code for a transaction.
Paid for every non-zero byte of data or code for a transaction.
Paid for every transaction.
Partial payment for a LOG operation.
Paid for each byte in a LOG operation’s data.
Paid for each topic of a LOG operation.
Paid for each KECCAK256 operation.
Paid for each word (rounded up) for input data to a KECCAK256 operation.
Partial payment for *COPY operations, multiplied by words
copied, rounded up.
Payment for each BLOCKHASH operation.
22
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Table 1.2: EVM operation gas refund overview
Name
Rsclear
Value
15000
Rselfdestruct
24000
Description
Refund given (added into refund counter) when the storage value is set to zero from non-zero.
Refund given (added into refund counter) for selfdestructing an account.
the most popular language to create smart contracts. Because C++, Python, and
JavaScript influence solidity language, it is easy to read and code. But inexperienced developers can easily make gas-wasting code issues because of the independent logic code with gas fee. On the other hand, the developers only work with
the Solidity code, not EVM byte code, so they can’t see the codes consisting of
gas-wasting issues to avoid it. So, GasSaver is an effective tool to help Solidity
smart contract developers detect and fix these gas-wasting codes.
1.3
Related work
In recent years, in contrast to a considerable number of tools that have been developed to detect security risks in smart contracts [5–11], there has been little
research focused on gas saving. Therefore, new gas analysis tools are being developed to detect potential gas-related issues and infer bounds in these complex
situations. I divide the related work into two categories: bytecode related work detecting the gas-related issues in the bytecode of smart contracts and high-level
language related work - detecting the gas-related problems in the source code of
smart contracts.
1.3.1
Bytecode related work
Chen et al. [12] conducted the first investigation on Solidity and the recommended
compiler. Then they revealed that the compiler fails to optimize gas-costly programming patterns. So, they identify seven gas-costly patterns and divide them
into two categories: useless-code-related patterns and loop-related patterns.
Useless-code related patterns:
• Dead code occurs when the code statements can be reached in the smart
contract. These codes can be removed without changing the logic.
• Opaque predicate. The outcome of an opaque predicate is known to be true
or false without execution. So, the evaluation of this outcome results should
be ignored to reduce the gas fee.
23
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Loop-related patterns:
• Expensive operations in a loop. The expensive operations in a loop are
worth attention because they may execute multiple times in one invocation.
Moving the expensive operations out of the loop can save gas.
• Constant outcome of a loop. In some cases, the outcome of a loop may be
a constant that can be inferred in the compilation
• Loop fusion. It combines several loops into one if possible and thus reduces
the size of bytecode.
• Repeated computations in a loop. In some cases, there may be expressions
that produce the same outcome in each loop iteration. Hence, the gas can
be saved by computing the outcome once and then reusing the value instead
of recomputing it in subsequent iterations, especially for the expressions involving expensive operands.
• Comparison with unilateral outcome in a loop: It means that a comparison
is executed in each iteration of a loop but the result of the comparison is
the same even if it cannot be determined in compilation
Then they proposed and developed GASPER, a new tool for automatically discovering gas-costly patterns in bytecode. GASPER leverages symbolic execution,
and it currently can locate three representative patterns, all in useless-code-related
patterns and expensive operations in a loop in loop-related patterns.
Elvira Albert et al. [13] offer various cost models that infer the gas consumption
associated with selected types of EVM instructions and/or infer the number of
times that such types of bytecode instructions are executed. Among others, they
have cost models for measuring only storage opcodes, for measuring a selected
family of gas-consumption opcodes following Ethereum’s classification to estimate
the cost of a selected program line, etc. After choosing the desired cost model
and the function of interest, Gasol returns the user an upper bound of the cost for
this function. As the gas consumption is often dominated by the instructions that
access the storage, Gasol uses the gas analysis to detect under-optimized storage
patterns and includes an (optional) automatic optimization of the selected function.
The optimization target is the reduction of the gas consumption associated with
storage usage. In particular, Gasol aims to replace multiple accesses to the same
(global) storage data within a fragment of code (each writes operation costs 20,000
in the worst case and 5,000 in the best case) by one access that copies the data
in storage to a (local) memory position followed by accesses to such memory position (access to the local memory costs only 3) and a final update to the storage
if needed. Their tool can be used within an Eclipse plugin for Solidity, which
displays the gas and instructions bounds and, when applicable, the gas-optimized
Solidity function.
24
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep
Extending from GASPER, Chen et al. [14] propose ten gas-inefficient programming patterns, divide them into four categories then they develop a tool named
GasChecker.
Useless code:
• Dead code
• Opaque predicate.
Loop:
• Expensive Operations in a Loop
• Fusible Loops
• Repeated Computation in a Loop
• Unilateral Comparison in a Loop: This pattern means a comparison in a loop
whose outcome is fixed. Moving the unilateral comparison outside the loop
and copying the loop body, the optimized version saves gas for executing
smart contracts since it reduces the number of comparisons at the price of
larger bytecode.
Wasted Disk Space
• Redundant SSTORE: This pattern indicates storage that is never used (e.g.,
SLOAD) after definition. Redundant SSTORE operations waste disk space
and much money as the gas cost of SSTORE, so removing it will reduce
the gas fee
Gas-Inefficient Operation Sequence: This type of gas-inefficient pattern refers to
consecutive EVM operation sequences that can be replaced with gas-efficient operation sequences
• SWAP1/DUP2/SWAP1
• PUSHx/POP
• PUSH1/NOT
Similar to Gasper, GasChecker approach is based on symbolic execution (SE) to
detect these patterns in the bytecode of smart contracts. In addition, this tool can
parallelize the symbolic execution by tailoring it to the MapReduce programming
model. It also proposes a novel feedback-based load balancing strategy to utilize
cloud resources effectively.
25
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep do an to nghiep docx 123docz
luan van hay luan van tot nghiep