-
Notifications
You must be signed in to change notification settings - Fork 3
/
assembleIeleCode.go
77 lines (64 loc) · 13.9 KB
/
assembleIeleCode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ielecompiler
import (
"go/build"
"log"
"os/exec"
"path/filepath"
)
// AssembleIeleCode calls the Haskell compiler to assemble contract code
func AssembleIeleCode(contractPathFilePath string) string {
initPrecompiledMap()
precompiled, found := tryRetrievePrecompiled(contractPathFilePath)
if found {
return precompiled
}
cmd := exec.Command("stack", "exec", "iele-assemble", contractPathFilePath)
cmd.Dir = filepath.Join(build.Default.GOPATH, "src/github.com/ElrondNetwork/elrond-vm/iele/compiler/compiler")
compiledBytes, err := cmd.Output()
if err != nil {
log.Fatal("compile iele error " + err.Error())
}
// uncomment this to print in console compiled bytes
//fmt.Printf("precompiledMap[\"%s\"] = \"%s\"\n", filepath.Base(contractPathFilePath), string(compiledBytes))
return string(compiledBytes)
}
// contains some hard-coded contract address
// to make it possible to run the VM without resorting to the haskell assembler
var precompiledMap map[string]string
func tryRetrievePrecompiled(contractPathFilePath string) (string, bool) {
fileName := filepath.Base(contractPathFilePath)
precompiled, found := precompiledMap[fileName]
return precompiled, found
}
func initPrecompiledMap() {
if precompiledMap != nil {
return
}
precompiledMap = make(map[string]string)
precompiledMap["adder.iele"] = "0000003B6302690003616464690004676574416700000001616101550468000100016161015406010A6161015506F6000068000200006161005401F6000101"
precompiledMap["agar_v1.iele"] = "000003986305690010706C6179657242616C616E63654B657969000F706C617965725374617475734B657969000E67616D65506C61796572734B657969000A67616D654265744B657969000962616C616E63654F66690005746F705570690008776974686472617769000B7769746864726177416C6C69000F616464506C61796572546F47616D6569000C72657761726457696E6E6572690007656E6447616D656900076465706F73697467000000003300618001550020670001000161010161820100021B0823170064F6000104670002000161020161820100021B0823170064F600010467000300016103016120021B0823170064F600010467000400016104016120021B0823170064F6000104680005000161A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0111040265000002F80001000100010003540064F6000104660000FE680006000033003401F80001000100010002540043010463550043F6000068000700013301F80001000100010022540043100064650000040300635500435705F2000C000000000004A665000006F60000660000FE68000800003300F80001000100010001540022618003140C44650000046180035500235705F2000C000000000100A665000106660000F60000660001FE680009000333036180045400850F14666500000661A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0411102661070455008665000006F800020001000100275400E80F2506650000066101045500E4F8000100010001002A54014B10096C6500000C03096B55014BF8000300010001000D5401AE61820100041B11CE1705CEF8000300010001000D5501AEF8000400010001000F5401F0010A105501F0F60000660000FE68000A000333036180045400850F14666500000661A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0411102665000006F800040001000100075400E8100906650000060309085500E8F8000100010001002954012A01094A55012AF60000660000FE68000B000133016180025400430F0C2465000204F800040001000100055400A66180020F08C465000204F800030001000100075400E86180021409046500020461010261820100091B244A61010203094A618002618201000903244B66000016290C61800214098D6500010DF8000200010001018E6180025501C21B2D08610102650000026600016180025500E2F60000660002FE"
precompiledMap["agar_v2.iele"] = "000004016305690010706C6179657242616C616E63654B657969000F706C617965725374617475734B657969000E67616D65506C61796572734B657969000A67616D654265744B657969000962616C616E63654F66690005746F705570690008776974686472617769000B7769746864726177416C6C69000F616464506C61796572546F47616D656900086A6F696E47616D6569001A616464506C61796572546F47616D6553746174654368616E676569000C72657761726457696E6E6572690007656E6447616D656900076465706F73697467000000003300618001550020670001000161010161820100021B0823170064F6000104670002000161020161820100021B0823170064F600010467000300016103016120021B0823170064F600010467000400016104016120021B0823170064F6000104680005000161A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0111040265000002F80001000100010003540064F6000104660000FE680006000033003401F80001000100010002540043010463550043F6000068000700013301F80001000100010022540043100064650000040300635500435705F2000E000000000004A665000006F60000660000FE68000800003300F80001000100010001540022618003140C44650000046180035500235705F2000E000000000100A665000106660000F60000660001FE680009000333036180045400850F146665000006F8000B000300000820F60000660000FE68000A000133013402F8000600000000F8000B000300000820F60000660000FE67000B000361A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF03110C2465000004F800020001000100255400A66101035500A3F800010001000100275400E8100909650000090309085500E8F8000300010001000A54014B61820100031B0D6B17056BF8000300010001000A55014BF8000400010001000C54018D0109AD55018DF60000660000FE68000C000333036180045400850F14666500000661A0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0411102665000006F800040001000100075400E8100906650000060309085500E8F8000100010001002954012A01094A55012AF60000660000FE68000D000133016180025400430F0C2465000304F800040001000100055400A6F800030001000100075400E86180021409046500030461010261820100091B244A61010203094A618002618201000903244B66000016290C61800214098D6500010DF8000200010001018E6180025501C21B2D0860018F610102650000026600016180025500E26180021408D0650002106180021409E465000304F8000C0003000019E0660002F60000660003FE"
precompiledMap["erc20_elrond.iele"] = "0000028E63046900066D61704B657969000A73657442616C616E636569000C736574416C6C6F77616E636569000C6C6F672E417070726F76616C69000C6C6F672E5472616E7366657269000B746F74616C537570706C7969000962616C616E63654F66690009616C6C6F77616E6365690007617070726F76656900087472616E7366657269000C7472616E7366657246726F6D67000100026120020C012361820100041B0405170356F60001066700020002610102F800010002000100235531F600006700030003610203F80001000200010034F800010002000101455552F600006700040003618003533261A07134692B230B9E1FFA39098904722134159652B09C5BC41D88D6698779D228FF04A31043F600006700050003618003533261A0F099CD8BDE557814842A3121E8DDFD433A539B8C9F14BF31EBF108D12E6196E904A31043F6000068000600006180005401F6000101670000000161800155103302F800020002000002F600006800070001610101F800010002000100125423F60001036800080002610202F80001000200010023F800010002000101345445F60001056800090002618002100213650000033304F80003000300000104F80004000300000104610102F6000102660000FE68000A0002618002100213650000033304F80007000100014510015365000003030155F800020002000054F800070001000106010166F800020002000060F80005000300000104610102F6000102660000FE68000B0003618003100324650000043305F80007000100010610026465000004F8000800020001050710027465000004030266F800020002000060030277F80003000300000750F800070001000118010288F800020002000081F80005000300000210610103F6000103660000FE"
precompiledMap["erc20.iele"] = "0000028D63046900066D61704B657969000A73657442616C616E636569000C736574416C6C6F77616E636569000C6C6F672E417070726F76616C69000C6C6F672E5472616E7366657269000B746F74616C537570706C7969000962616C616E63654F66690009616C6C6F77616E6365690007617070726F76656900087472616E7366657269000C7472616E7366657246726F6D67000100026114020C01236181A0041B0405170356F60001066700020002610102F800010002000100235531F600006700030003610203F80001000200010034F800010002000101455552F600006700040003618003533261A07134692B230B9E1FFA39098904722134159652B09C5BC41D88D6698779D228FF04A31043F600006700050003618003533261A0F099CD8BDE557814842A3121E8DDFD433A539B8C9F14BF31EBF108D12E6196E904A31043F6000068000600006180005401F6000101670000000161800155103302F800020002000002F600006800070001610101F800010002000100125423F60001036800080002610202F80001000200010023F800010002000101345445F60001056800090002618002100213650000033304F80003000300000104F80004000300000104610102F6000102660000FE68000A0002618002100213650000033304F80007000100014510015365000003030155F800020002000054F800070001000106010166F800020002000060F80005000300000104610102F6000102660000FE68000B0003618003100324650000043305F80007000100010610026465000004F8000800020001050710027465000004030266F800020002000060030277F80003000300000750F800070001000118010288F800020002000081F80005000300000210610103F6000103660000FE"
precompiledMap["factorial.iele"] = "0000004C6303690009666163746F7269616C6800010001618001100042650003026101036600006180011200446500020466000102001B610101030040640000660002F6000103660003FE6700000000"
precompiledMap["sum.iele"] = "00000046630369000373756D6800010001618001100042650003026180036600006180011200446500020466000101001B610101030040640000660002F6000103660003FE6700000000"
precompiledMap["forwarder.iele"] = "0000003A63036900076465706F73697467000000003300618001550868000100003400618001540A5703F2000100000000009C65000004F60000660000FE"
precompiledMap["forwardingWallet.iele"] = "000000C863036900076465706F736974690008776974686472617769000C6E6577466F727761726465726A003E0000003A63036900076465706F73697467000000003300618001550868000100003400618001540A5703F2000100000000009C65000004F60000660000FE6700000001618001550868000100006800020002618002541333040F00E5650000055706F2000100000000023765000007F60000660000FE6800030000618000540133020F005365000003618000F000040000002C65000004F6000105660000FE"
precompiledMap["forwardingWallet-copycreate.iele"] = "0000008F63036900076465706F736974690008776974686472617769000C6E6577466F7277617264657267000000026180025510610102551168000100006800020002618002541333040F00E5650000055706F2000100000000023765000007F60000660000FE6800030000618000540133020F0053650000036101005404618000F10000083565000005F6000106660000FE"
precompiledMap["simpleOpenAuction.iele"] = "00000105630469000362696469000E736574746C652E61756374696F6E6900076465706F7369746700000002618002552042036101025523010134610202552461800261030555526180026104055552618002610505555268000100004200610201541213020365000203340461040154151205466500020615576500010766000061030154185709F2000300000000589A6500030A660001330B610301551B6104015514F60000660002620101F701660003FE68000200004200610201541210020365000103610501541465000004610401541561800154165707F20003000000005678650002086101016105095591660000610301541AF600010A660001620101F701660002FE"
// the other tests:
precompiledMap["bits.iele"] = "0000003663026900047465737468000100006180006105010C12650000026180006105010B1265000002F60000660000620100F7006700000000"
precompiledMap["bits2.iele"] = "0000002D6303690004746573746800010003650000026180030300596600000C00440B0104140065F60001056700000000"
precompiledMap["blockhash.iele"] = "00000021630269000E746573745F626C6F636B686173686800010002400255066700000000"
precompiledMap["calladdress.iele"] = "0000004C6303690003626172690005746573743269000362617A67000000006800010001FA0002015702618003F30000000101846C6500000465000005FA00030665000006F60000660000620103F703"
precompiledMap["collision.iele"] = "0000000763006700000000"
precompiledMap["endian.iele"] = "0000001963026900047465737468000100020D12F60001026700000000"
precompiledMap["escape.iele"] = "0000002F6300690004746573746A000B00000007630067000000006A000B000000076300670000000067000000006800010000"
precompiledMap["exceptions.iele"] = "0000022D630369000574657374316900057465737432690005746573743369000574657374346900057465737435690005746573743669000574657374376900057465737438690005746573743969000674657374313069000674657374313169000674657374313269000674657374313369000674657374313469000674657374313569000674657374313769000674657374313869000674657374313969000466756E6369000566756E63326A00230000001F6303670000000265000001618002618003F100020180ACF704660000F600006700000000680001000057003001618002F20013000000000443680002000057003001618002F20013000000020111636600006800030000610100618001040042680004000061010062010107004268000500006101006180010600426800060000610100610101618002080443680007000061010061010161800209044368000800006101006101016180020A044368000900006102006201016102020A044368000A00006101006201010B004268000B00006101006201010D004268000C00006180001C0168000D000057003001610102F20013000000012223F70368000E000057003001618002F2000E000000012223F70368000F000057003001618002F20014000000000443F70368001000016800110000610100618001610102F0001500022223F7036800120000618000618001610102F0001500022223618000618001F000150002182BF7036800130000618000F60001006700140000"
precompiledMap["fptr.iele"] = "000001146303690004746573746900057465737432690008746573746661696C690009746573746661696C32680001000061020061800153086180015108F900000001026500000230035704618001F30000000100B8156500000565000002F500000001381565000005650000026182271004618001F200030000000002E56101010F006E65000006618001F200040000000002E56102010F006E65000006F60000660000620101F70167000000006800020000618000F60001006800030000610F003001618203E802618003F30000000101942C6101030F00E66500000665000005F500000001142C6101030F00E66500000665000005F90000000105660000620103F7036800040000610200618001F9000100010042"
precompiledMap["illFormed.iele"] = "000000026300"
precompiledMap["logarithm.iele"] = "00000023630169000E746573745F6C6F6761726974686D68000100011C01F60001016700000000"
precompiledMap["selfdestruct.iele"] = "0000001463006900046B696C6C6800010001FF6700000000"
precompiledMap["shift.iele"] = "00000039630269000A746573745F736869667468000100026182010003540E1B0A6182010003550E6182010103540E1B1A6182010103550E6700000000"
precompiledMap["staticcall.iele"] = "000001F8630369000F746573745F73746174696363616C6C690007737461746963326900077374617469633169000A6E6F6E7374617469633169000A6E6F6E7374617469633269000A6E6F6E7374617469633369000A6E6F6E7374617469633469000A6E6F6E7374617469633569000A6E6F6E7374617469633669000A6E6F6E737461746963376A000B0000000763006700000000680001000030005701F4000300000001005A650000026500000361824E2004F4000400000001011A6104040F011565000005618203E804F4000500000001011A6104040F011565000005618203E804F4000600000001011A6104040F011565000005618207D004F4000700000001011A6104040F01156500000561829C4004F4000800000001011A6104040F01156500000561829C4004F4000900000001011A6104040F0115650000056182271004F4000A00000001011A6104040F011565000005618004F6000104660000620104F7046800020000F60000680003000030005701618002F2000200000000040B65000003618002F6000102660000620102F702680004000061800061800155086800050000618000A0006800060000618000618001A108680007000030005701610102F2000200000000040B6800080000618000F0000B0000001168000900003000618001F10000005A68000A0000618000FF006700000000"
}