diff --git a/Makefile b/Makefile index bc1f19c3db..3d79f79706 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,9 @@ ifeq ($(shell uname -s),Darwin) export CGO_LDFLAGS=-framework Foundation -framework SystemConfiguration endif -juno: vm core-rust ## compile +rustdeps: vm core-rust compiler + +juno: rustdeps ## compile @mkdir -p build @go build $(GO_TAGS) -a -ldflags="-X main.Version=$(shell git describe --tags)" -o build/juno ./cmd/juno/ @@ -24,6 +26,9 @@ vm: core-rust: $(MAKE) -C core/rust $(VM_TARGET) +compiler: + $(MAKE) -C starknet/rust $(VM_TARGET) + generate: ## generate mkdir -p mocks go generate ./... @@ -31,19 +36,19 @@ generate: ## generate clean-testcache: go clean -testcache -test: clean-testcache vm core-rust ## tests +test: clean-testcache rustdeps ## tests go test $(GO_TAGS) ./... -test-cached: vm core-rust ## tests with existing cache +test-cached: rustdeps ## tests with existing cache go test $(GO_TAGS) ./... -test-race: clean-testcache vm core-rust +test-race: clean-testcache rustdeps go test $(GO_TAGS) ./... -race -benchmarks: vm core-rust ## benchmarking +benchmarks: rustdeps ## benchmarking go test $(GO_TAGS) ./... -run=^# -bench=. -benchmem -test-cover: vm core-rust ## tests with coverage +test-cover: rustdeps ## tests with coverage mkdir -p coverage go test $(GO_TAGS) -coverpkg=./... -coverprofile=coverage/coverage.out -covermode=atomic ./... go tool cover -html=coverage/coverage.out -o coverage/coverage.html @@ -72,6 +77,7 @@ format: ## run go formatter clean: ## clean project builds $(MAKE) -C vm/rust clean $(MAKE) -C core/rust clean + $(MAKE) -C starknet/rust clean @rm -rf ./build help: ## show this help diff --git a/clients/feeder/testdata/integration/class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json b/clients/feeder/testdata/integration/class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json new file mode 100644 index 0000000000..dec6fe2357 --- /dev/null +++ b/clients/feeder/testdata/integration/class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json @@ -0,0 +1 @@ +{"contract_class_version": "0.1.0", "sierra_program": ["0x1", "0x3", "0x0", "0x2", "0x3", "0x1", "0xe2", "0x1e", "0x22", "0x52616e6765436865636b", "0x800000000000000100000000000000000000000000000000", "0x66656c74323532", "0x800000000000000700000000000000000000000000000000", "0x537472756374", "0x800000000000000700000000000000000000000000000002", "0x0", "0x1166fe35572d4e7764dac0caf1fd7fc591901fd01156db2561a07b68ab8dca2", "0x1", "0x4172726179", "0x800000000000000300000000000000000000000000000001", "0x456e756d", "0x800000000000000300000000000000000000000000000003", "0x90d0203c41ad646d024845257a6eceb2f8b59b29ce7420dd518053d2edeedc", "0x3", "0x800000000000000f00000000000000000000000000000001", "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", "0x800000000000000f00000000000000000000000000000002", "0x5", "0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672", "0x7", "0xcc5e86243f861d2d64b08c35db21013e773ac5cf10097946fe0011304886d5", "0x6", "0x8", "0x101dc0399934cc08fa0d6f6f2daead4e4a38cabeea1c743e1fc28d2d6e58e99", "0x53746f7261676541646472657373", "0x53746f726167654261736541646472657373", "0xb9335defd94e5e96aa3800559657f59a04e99ff4fd1ff45a8468aad6a76fab", "0x800000000000000f00000000000000000000000000000003", "0xd", "0x27bcae603ddc397773f055e1ca3447ac62f33b0339a55bb6239b3df1ba74d07", "0xe", "0x426f78", "0x800000000000000700000000000000000000000000000001", "0x800000000000000700000000000000000000000000000003", "0x29d7d57c04a880978e7b3689f6218e507f3be17588744b58dc17762447ad0e7", "0x10", "0x10203be321c62a7bd4c060d69539c1fbe065baa9e253c74d2cc48be163e259", "0x12", "0x536e617073686f74", "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", "0x14", "0x15", "0xd6c011282de9709059ecf1ced60e1257e797ff9960a6fea50905ea78471212", "0xc438bf085f4d250e9ee7f0a03300edb9fef994a93ccc666669b5419441893b", "0x17", "0x18", "0x1e0b3df82519e243577f3b3a00b0d6e77a110a23f4858d8e920000a81afdbce", "0x19", "0x4275696c74696e436f737473", "0x53797374656d", "0x506564657273656e", "0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6", "0x16", "0x753332", "0x11c6d8087e00642489f92d2821ad6ebd6532ad1a3b6d12833da6d6810391511", "0x4761734275696c74696e", "0x76", "0x7265766f6b655f61705f747261636b696e67", "0x77697468647261775f676173", "0x6272616e63685f616c69676e", "0x73746f72655f74656d70", "0x66756e6374696f6e5f63616c6c", "0x2", "0x656e756d5f6d61746368", "0x20", "0x7374727563745f6465636f6e737472756374", "0x61727261795f6c656e", "0x736e617073686f745f74616b65", "0x1f", "0x64726f70", "0x7533325f636f6e7374", "0x72656e616d65", "0x7533325f6571", "0x61727261795f6e6577", "0x66656c743235325f636f6e7374", "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", "0x61727261795f617070656e64", "0x7374727563745f636f6e737472756374", "0x656e756d5f696e6974", "0x1e", "0x1d", "0x21", "0x1c", "0x6765745f6275696c74696e5f636f737473", "0x1b", "0x77697468647261775f6761735f616c6c", "0x1a", "0x4f7574206f6620676173", "0x4661696c656420746f20646573657269616c697a6520706172616d202332", "0x4661696c656420746f20646573657269616c697a6520706172616d202331", "0x4", "0x13", "0x61727261795f736e617073686f745f706f705f66726f6e74", "0x11", "0x6a756d70", "0x756e626f78", "0xf", "0x73746f726167655f616464726573735f66726f6d5f62617365", "0x73746f726167655f77726974655f73797363616c6c", "0xa", "0x9", "0x73746f726167655f726561645f73797363616c6c", "0x35fe13a5db37080bfbfae639e6c19be9719e0fbdd4db062eb83cceb4d85a7fe", "0x706564657273656e", "0xad292db4ff05a993c318438c1b6c8a8303266af2da151aa28ccece6726f1f1", "0xc", "0x1e6", "0xffffffffffffffff", "0x7f", "0xb", "0x6f", "0x5e", "0x27", "0x23", "0x24", "0x25", "0x26", "0x28", "0x29", "0x4e", "0x2a", "0x2b", "0x2c", "0x2d", "0x2e", "0x34", "0x35", "0x36", "0x37", "0x38", "0x39", "0x3a", "0x2f", "0x30", "0x31", "0x32", "0x33", "0x3b", "0x46", "0x3c", "0x3d", "0x3e", "0x3f", "0x40", "0x41", "0x42", "0x43", "0x44", "0x45", "0x47", "0x48", "0x49", "0x4a", "0x4b", "0x4c", "0x4d", "0x4f", "0x50", "0x51", "0x52", "0x53", "0x54", "0x55", "0x56", "0x57", "0x58", "0x59", "0x5a", "0x5b", "0x5c", "0x5d", "0x5f", "0x60", "0x61", "0x62", "0x63", "0x64", "0x65", "0x66", "0x67", "0x68", "0x69", "0x6a", "0x6b", "0x6c", "0x6d", "0x6e", "0x70", "0x71", "0x72", "0x73", "0x74", "0x75", "0x77", "0x78", "0x79", "0xfd", "0xed", "0xb0", "0xde", "0xd6", "0x113", "0x118", "0x122", "0x140", "0x15d", "0x17c", "0x181", "0x18e", "0x1a6", "0x1ab", "0x1b8", "0x1d4", "0x1e0", "0x8e", "0x10c", "0x129", "0x149", "0x165", "0x16b", "0x197", "0x1c0", "0x1ce", "0x1da", "0x1244", "0x11071205110710050f0909090e070d0c09090b0a0909080706050403020100", "0x1a0f09130919070d0c1809170916070d0c0f09150911070d05140710051309", "0x2407230c09092221180920091f070d0c13091e0911071d051c071005041b04", "0x706052a09290706050f0922281809270926070d0c09091107060513092509", "0x1809310930070d0c13092f0911071d052e091e092d071d052c0710052b0911", "0x73c073b3a0239130909093807230c04371809360935070d0c023402330432", "0x4746090945090909442b090943420909410709093e400f093f2b09093e073d", "0x93e4d40094c0909094b09090947074a4609093e4609094907400948460909", "0x9093e5309093e5209093e0940510940501809094f1509094f0909094e0909", "0x93f2f09093e2f09094f2e09094f1e09094f07575609093e07555109093e54", "0x40510940503609094f2b09094f0f0909470f09094531090947580909410f0f", "0x93f2f0909472f0909455b40094c5a40094c2b090947130909475940094c07", "0x405f0940500909095e130f093f0f09093e09090945270909435d0909415c0f", "0x949090909615f09094109405f0940501309094f07605f09093e2a09093e07", "0x41170f093f1e09093e2f0909430940420940504209093e0740420940500909", "0x940580940502e0909475809093e0740580940503109094f20090943620909", "0x909451309093e09405d0940505d09093e07405d0940502709094f150f093f", "0x93f650909490940650940506509093e07406509405007640763180f093f1e", "0x940501e0909476209093e0740620940502009094f1709094366090941660f", "0x94c650f093f5c09094909405c0940505c09093e07405c0940500767094062", "0x40660940501709094f650909416b09093e076a0769400909434009094f6840", "0x13406d404009400907076d090707076c5c0909410940660940506609093e07", "0x913076566406d096f095c076f096d095c090f07076d090740071815406e17", "0x725096d0966090f07076d090740071e09706b096d406509170713096d0913", "0x6d0920091507076d090740072709715f096d40620917076220406d0925095c", "0x6d09076f07076d092b096507362b406d092a0966072a096d095d0918075d09", "0x931096b0758096d0936096b07076d092f096507312f406d092e0966072e09", "0x5f096207076d090740070772076d40565840200758096d0958091e0756096d", "0x96d095209270752096d09075f0754096d09072507076d096b096207076d09", "0x94209360742096d095146402b0746096d09072a0751096d095254405d0752", "0xf09310774096d0917092f0773096d091309130700096d0907092e0753096d", "0x96d09075607076d090740077675747300130976096d095309580775096d09", "0x7076d090740077b7a40797877406d407217130f520772096d097209540772", "0x77f096d09770913077e096d097d7c4042077d096d090746077c096d090751", "0x83096d097e09530782096d090f09310781096d0907092e0780096d0978092f", "0x8786136d098584838281807f15000785096d095f09270784096d096b092707", "0x9072507076d098b097407076d090740078d098c8b096d408a0973078a8988", "0x9109770791096d0990097207076d098f097607908f406d098e0975078e096d", "0x92f0795096d098609130794096d0988092e0793096d099209780792096d09", "0x74007978c969594130997096d09930958078c096d098909310796096d0987", "0x87092f079a096d098609130799096d0988092e0798096d098d093607076d09", "0x90740079d9c9b9a9913099d096d09980958079c096d09890931079b096d09", "0x79e096d09077a0779096d09072507076d096b096207076d095f096207076d", "0x96d099fa0402b07a0096d09072a079f096d099e79405d079e096d099e0927", "0x6d097b092f07a4096d097a091307a3096d0907092e07a2096d09a1093607a1", "0x76d09074007a7a6a5a4a31309a7096d09a2095807a6096d090f093107a509", "0x77d07a8096d09072507076d096b096207076d0920097c07076d0927097b07", "0x402b07ab096d09072a07aa096d09a9a8405d07a9096d09a9092707a9096d09", "0x7ae096d0913091307ad096d0907092e0771096d09ac093607ac096d09aaab", "0x7b1b0afaead1309b1096d0971095807b0096d090f093107af096d0917092f", "0x6d09077e07b2096d09072507076d0966097c07076d091e097b07076d090740", "0xb4b5402b07b5096d09072a07b4096d09b3b2405d07b3096d09b3092707b309", "0x92f07b9096d0913091307b8096d0907092e07b7096d09b6093607b6096d09", "0x74007bcbbbab9b81309bc096d09b7095807bb096d090f093107ba096d0917", "0x96d09bd092707bd096d09077a0770096d09072507076d095c097c07076d09", "0x9c0093607c0096d09bebf402b07bf096d09072a07be096d09bd70405d07bd", "0xf093107c3096d0918092f073a096d0915091307c2096d0907092e07c1096d", "0x404009400907076d09070707c5c4c33ac21309c5096d09c1095807c4096d09", "0x6566406d096f095c076f096d095c090f07076d09074007181540c61713406d", "0x6d0966091507076d090740071e09c76b096d406509170713096d0913091307", "0x6d09076f07076d09250965075f25406d096209660762096d09200918072009", "0x92a096b072b096d095f096b07076d095d0965072a5d406d09270966072709", "0x6b096207076d0907400707c8076d40362b4020072b096d092b091e0736096d", "0x92f2e405d072f096d092f0927072f096d09075f072e096d09072507076d09", "0x7092e0754096d095609360756096d093158402b0758096d09072a0731096d", "0x9580742096d090f09310746096d0917092f0751096d091309130752096d09", "0x6d090009540700096d09075607076d090740075342465152130953096d0954", "0x772096d09075107076d09074007767540c97473406d400017130f52070009", "0x76d097a0987077b7a406d097809860778096d09777240420777096d090746", "0x96d090f0931078a096d0907092e0789096d0974092f0788096d0973091307", "0x7d7c136d0981807f8a898817880781096d096b09270780096d097b0953077f", "0x82098a0784096d09072507076d090740078309ca82096d408709890787867e", "0x9800790096d098d092707076d098b0962078d8b406d0985097f0785096d09", "0x9392406d098e097507076d098f097b078f8e406d09919040810791096d0984", "0x96096d099509780795096d099409770794096d0993097207076d0992097607", "0x96d098609310798096d097d092f0797096d097c0913078c096d097e092e07", "0x79b096d0983093607076d090740079a9998978c13099a096d099609580799", "0x9e096d098609310779096d097d092f079d096d097c0913079c096d097e092e", "0x72507076d096b096207076d090740079f9e799d9c13099f096d099b095807", "0x72a07a2096d09a1a0405d07a1096d09a1092707a1096d09077a07a0096d09", "0x1307a6096d0907092e07a5096d09a4093607a4096d09a2a3402b07a3096d09", "0x9aa096d09a5095807a9096d090f093107a8096d0976092f07a7096d097509", "0x6d09072507076d0966097c07076d091e097b07076d09074007aaa9a8a7a613", "0x6d09072a0771096d09acab405d07ac096d09ac092707ac096d09077e07ab09", "0x13091307b0096d0907092e07af096d09ae093607ae096d0971ad402b07ad09", "0xb01309b4096d09af095807b3096d090f093107b2096d0917092f07b1096d09", "0xb6096d09077a07b5096d09072507076d095c097c07076d09074007b4b3b2b1", "0x6d09b7b8402b07b8096d09072a07b7096d09b6b5405d07b6096d09b6092707", "0x918092f07bc096d0915091307bb096d0907092e07ba096d09b9093607b909", "0x907091507bebd70bcbb1309be096d09ba095807bd096d090f09310770096d", "0x840713096d090f098307076d090740075c09cb0f40406d400909820709096d", "0x6d09078d07076d0907400707cc09078b0715096d091309850717096d094009", "0x91709720715096d096609850717096d095c09840766096d0918098e071809", "0x99007076d090740076b09cd6f096d4015098f0765096d0965090f0765096d", "0x930725096d0965090f0762096d092009920720096d091e0991071e096d096f", "0x727096d09078d07076d096b097b07076d090740075f2540095f096d096209", "0x5c0995072b2a40092b096d095d0993072a096d0965090f075d096d09270994", "0x310725096d0940092e0762096d0909092f0720096d09070913071815406d09", "0x72a096d09170927075d096d091309270727096d09150996075f096d090f09", "0x740073609ce2b096d401e0997071e6b6f6566136d092a5d275f256220158c", "0x182e40420731096d09078d07076d092f097b072f2e406d092b099807076d09", "0x2f0752096d096609130754096d0956099a0756096d09315840990758096d09", "0x953096d0954099b0742096d096b09310746096d096f092e0751096d096509", "0x6609130700096d0936099d07076d0918099c07076d09074007534246515213", "0x99b0776096d096b09310775096d096f092e0774096d0965092f0773096d09", "0x91307076d0915099c071517406d095c0995077276757473130972096d0900", "0x960725096d090f09310762096d0940092e0720096d0909092f071e096d0907", "0x6b6f656618136d09275f2562201e17790727096d09130927075f096d091709", "0x6d092b099e072b096d095d098a07076d090740072a09cf5d096d406b098907", "0x965092e0731096d0966092f072f096d09180913072e096d0936099f073609", "0x6d09074007545658312f130954096d092e09a00756096d096f09310758096d", "0x6d0965092e0746096d0966092f0751096d091809130752096d092a09a10707", "0x6d09070991070053424651130900096d095209a00753096d096f0931074209", "0x95c09a20713096d090f0980075c096d09078d070f096d094009405d074009", "0x96d0940092e076b096d09070913071815406d095c09a3071713400917096d", "0x76f65660f6d0962201e6b5ca40762096d091309270720096d09180996071e", "0x4017255f0f0913a6075f096d095f091e075f096d09076f0725096d096f09a5", "0x72f096d092e09a7072e096d09078d07076d09074007362b2a0fd05d27406d", "0x400707d109078b0756096d092f09a80758096d095d09310731096d0927092f", "0x9a80758096d092b09310731096d092a092f0754096d093609a907076d0907", "0x9d246096d405209ac0752096d095109ab0751096d095609aa0756096d0954", "0x96d090009ae0700096d09531540ad0753096d0946097107076d0907400742", "0x6d095809310776096d0965092e0775096d0931092f0774096d096609130773", "0x7076d091509b007076d090740077772767574130977096d097309af077209", "0x7c096d0965092e077b096d0931092f077a096d096609130778096d094209b1", "0x66096d09070913077e7d7c7b7a13097e096d097809af077d096d0958093107", "0x6b6f65665ca4076b096d09130927076f096d095c09960765096d0940092e07", "0xb20720096d0920091e0720096d09076f071e096d091809a5071815170f6d09", "0x72b096d095f09b307076d090740072a5d270fd35f25620f6d401e200f095c", "0x400707d409078b072f096d092b09b4072e096d092509310736096d0962092f", "0x9b4072e096d095d09310736096d0927092f0731096d092a09b507076d0907", "0x9d554096d405809890758096d095609b70756096d092f09b6072f096d0931", "0x42096d0946099f0746096d0951099e0751096d0954098a07076d0907400752", "0x96d092e09310773096d0915092e0700096d0936092f0753096d0917091307", "0x776096d095209a107076d090740077574730053130975096d094209a00774", "0x7a096d092e09310778096d0915092e0777096d0936092f0772096d09170913", "0xb9075c096d0907b807076d094009b0077b7a78777213097b096d097609a007", "0x406d090f17090fbb0717096d091709270717096d091309ba0713096d095c09", "0x650740bc0765096d096509270765096d096609ba0766096d091809b9071815", "0xf0962096d096b09700720096d0915092e071e096d096f0913076b6f406d09", "0x9bf070f096d090909be07076d090740074009d609096d400709bd0762201e", "0x2b0717096d09072a07076d0907400713090913096d095c09c0075c096d090f", "0x400709c20766090966096d091809c00718096d091509c10715096d09401740", "0x9a0075c096d090f099f070f096d0909099e07076d090740074009d709096d", "0x715096d094017402b0717096d09072a07076d0907400713090913096d095c", "0x5154530752132b54530752136f66090966096d091809a00718096d091509a1", "0xd907422b402b09d85c0f4009075154530752132b5453075213075c0f400907", "0x713092f5452530717da17135c0f40090758545253071309092f5452530715", "0x53071309091e5452530715dc0907130f400f0940db135c0f4009075d545253", "0xde135c0f4009075d5452530713091e5452530717dd17135c0f400907625452", "0xe1075d095c09e00766096509df0f4009076b52070f091e52075c"], "entry_points_by_type": {"CONSTRUCTOR": [], "EXTERNAL": [{"selector": "0x17c00f03de8b5bd58d2016b59d251c13056b989171c5852949903bc043bc27", "function_idx": 1}, {"selector": "0x1d7377b4b2053672e38039a02d909f73c4e538c9fddbb7e97aadf700cb9a01a", "function_idx": 0}], "L1_HANDLER": []}, "abi": "[{\"type\": \"impl\", \"name\": \"Map\", \"interface_name\": \"map::IMap\"}, {\"type\": \"interface\", \"name\": \"map::IMap\", \"items\": [{\"type\": \"function\", \"name\": \"put\", \"inputs\": [{\"name\": \"key\", \"type\": \"core::felt252\"}, {\"name\": \"value\", \"type\": \"core::felt252\"}], \"outputs\": [], \"state_mutability\": \"external\"}, {\"type\": \"function\", \"name\": \"get\", \"inputs\": [{\"name\": \"key\", \"type\": \"core::felt252\"}], \"outputs\": [{\"type\": \"core::felt252\"}], \"state_mutability\": \"view\"}]}, {\"type\": \"event\", \"name\": \"map::Map::Event\", \"kind\": \"enum\", \"variants\": []}]"} \ No newline at end of file diff --git a/clients/feeder/testdata/integration/compiled_class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json b/clients/feeder/testdata/integration/compiled_class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json new file mode 100644 index 0000000000..b4889cb15c --- /dev/null +++ b/clients/feeder/testdata/integration/compiled_class/0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b.json @@ -0,0 +1 @@ +{"entry_points_by_type": {"EXTERNAL": [{"selector": "0x17c00f03de8b5bd58d2016b59d251c13056b989171c5852949903bc043bc27", "offset": 157, "builtins": ["pedersen", "range_check"]}, {"selector": "0x1d7377b4b2053672e38039a02d909f73c4e538c9fddbb7e97aadf700cb9a01a", "offset": 0, "builtins": ["pedersen", "range_check"]}], "L1_HANDLER": [], "CONSTRUCTOR": []}, "prime": "0x800000000000011000000000000000000000000000000000000000000000001", "bytecode": ["0xa0680017fff8000", "0x7", "0x482680017ffa8000", "0xffffffffffffffffffffffffffffc856", "0x400280007ff97fff", "0x10780017fff7fff", "0x88", "0x4825800180007ffa", "0x37aa", "0x400280007ff97fff", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x1104800180018000", "0x11d", "0x482680017ff98000", "0x1", "0x20680017fff7ffd", "0x6e", "0x48127ffb7fff8000", "0x48127ffb7fff8000", "0x1104800180018000", "0x115", "0x20680017fff7ffe", "0x59", "0x48307ffc80007ffd", "0x4824800180007fff", "0x0", "0x20680017fff7fff", "0x4", "0x10780017fff7fff", "0x11", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x48127feb7fff8000", "0x48127fda7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x1104800180018000", "0x214", "0x482480017fff8000", "0x213", "0x480080007fff8000", "0x480080007fff8000", "0x482480017fff8000", "0x0", "0xa0680017fff8000", "0x8", "0x48307ffe80007fd7", "0x482480017fff8000", "0x100000000000000000000000000000000", "0x400080007fe57fff", "0x10780017fff7fff", "0x23", "0x48307ffe80007fd7", "0x400080007fe67fff", "0x482480017fe68000", "0x1", "0x48127ffe7fff8000", "0x480a7ff87fff8000", "0x480a7ffb7fff8000", "0x48127fe17fff8000", "0x48127ff07fff8000", "0x1104800180018000", "0x106", "0x20680017fff7ffd", "0xd", "0x40780017fff7fff", "0x1", "0x48127ffa7fff8000", "0x48127ff77fff8000", "0x48127ff77fff8000", "0x48127ff87fff8000", "0x480680017fff8000", "0x0", "0x48127ffa7fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x48127ffb7fff8000", "0x48127ff87fff8000", "0x48127ff87fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4f7574206f6620676173", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x482480017fe28000", "0x1", "0x48127fd17fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4661696c656420746f20646573657269616c697a6520706172616d202332", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x48127fed7fff8000", "0x48127fdc7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4661696c656420746f20646573657269616c697a6520706172616d202331", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x48127ffc7fff8000", "0x48127feb7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4f7574206f6620676173", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x482680017ff98000", "0x1", "0x480a7ffa7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0xa0680017fff8000", "0x7", "0x482680017ffa8000", "0xffffffffffffffffffffffffffffcdce", "0x400280007ff97fff", "0x10780017fff7fff", "0x77", "0x4825800180007ffa", "0x3232", "0x400280007ff97fff", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x1104800180018000", "0x80", "0x482680017ff98000", "0x1", "0x20680017fff7ffd", "0x5d", "0x48307ffb80007ffc", "0x4824800180007fff", "0x0", "0x20680017fff7fff", "0x4", "0x10780017fff7fff", "0x11", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x48127ffa7fff8000", "0x48127fe97fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x1104800180018000", "0x17d", "0x482480017fff8000", "0x17c", "0x480080007fff8000", "0x480080007fff8000", "0x482480017fff8000", "0x0", "0xa0680017fff8000", "0x8", "0x48307ffe80007fe6", "0x482480017fff8000", "0x100000000000000000000000000000000", "0x400080007ff47fff", "0x10780017fff7fff", "0x27", "0x48307ffe80007fe6", "0x400080007ff57fff", "0x482480017ff58000", "0x1", "0x48127ffe7fff8000", "0x480a7ff87fff8000", "0x480a7ffb7fff8000", "0x48127ff07fff8000", "0x1104800180018000", "0x8e", "0x20680017fff7ffd", "0x12", "0x40780017fff7fff", "0x1", "0x48127ffe7fff8000", "0x48127ffe7fff8000", "0x48127ffd7fff8000", "0x1104800180018000", "0xa1", "0x48127ff37fff8000", "0x48127ff07fff8000", "0x48127ff07fff8000", "0x48127ff17fff8000", "0x480680017fff8000", "0x0", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x48127ffb7fff8000", "0x48127ff87fff8000", "0x48127ff87fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4f7574206f6620676173", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x482480017ff18000", "0x1", "0x48127fe07fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4661696c656420746f20646573657269616c697a6520706172616d202331", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x48127ffc7fff8000", "0x48127feb7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", "0x4f7574206f6620676173", "0x400080007ffe7fff", "0x480a7ff87fff8000", "0x482680017ff98000", "0x1", "0x480a7ffa7fff8000", "0x480a7ffb7fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x482480017ff88000", "0x1", "0x208b7fff7fff7ffe", "0x48297ffc80007ffd", "0x20680017fff7fff", "0x4", "0x10780017fff7fff", "0xa", "0x482680017ffc8000", "0x1", "0x480a7ffd7fff8000", "0x480680017fff8000", "0x0", "0x480a7ffc7fff8000", "0x10780017fff7fff", "0x8", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x480680017fff8000", "0x1", "0x480680017fff8000", "0x0", "0x48127ffc7fff8000", "0x48127ffc7fff8000", "0x20680017fff7ffc", "0x8", "0x48127ffe7fff8000", "0x48127ffe7fff8000", "0x480680017fff8000", "0x0", "0x480080007ffa8000", "0x208b7fff7fff7ffe", "0x48127ffe7fff8000", "0x48127ffe7fff8000", "0x480680017fff8000", "0x1", "0x480680017fff8000", "0x0", "0x208b7fff7fff7ffe", "0x480a7ff87fff8000", "0x480a7ff97fff8000", "0x480a7ffa7fff8000", "0x480a7ffb7fff8000", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x1104800180018000", "0x39", "0x20680017fff7ffd", "0xd", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x208b7fff7fff7ffe", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x480a7ff97fff8000", "0x480a7ffa7fff8000", "0x480a7ffb7fff8000", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x1104800180018000", "0x57", "0x20680017fff7ffd", "0xc", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x400380007ffd7ffb", "0x480a7ffc7fff8000", "0x482680017ffd8000", "0x1", "0x208b7fff7fff7ffe", "0x480a7ff87fff8000", "0x480a7ffa7fff8000", "0x480a7ffc7fff8000", "0x1104800180018000", "0x70", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x53746f726167655772697465", "0x400280007ffb7fff", "0x400380017ffb7ff9", "0x400280027ffb7ffe", "0x400280037ffb7ffd", "0x400380047ffb7ffd", "0x480280067ffb8000", "0x20680017fff7fff", "0xd", "0x480280057ffb8000", "0x482680017ffb8000", "0x7", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x10780017fff7fff", "0x9", "0x480280057ffb8000", "0x482680017ffb8000", "0x9", "0x480680017fff8000", "0x1", "0x480280077ffb8000", "0x480280087ffb8000", "0x1104800180018000", "0x78", "0x20680017fff7ffd", "0xd", "0x48127ff07fff8000", "0x48127ff57fff8000", "0x48127fef7fff8000", "0x48127ff47fff8000", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x208b7fff7fff7ffe", "0x48127ff07fff8000", "0x48127ff57fff8000", "0x48127fef7fff8000", "0x48127ff47fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x480a7ff97fff8000", "0x480a7ffb7fff8000", "0x480a7ffd7fff8000", "0x1104800180018000", "0x35", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x53746f7261676552656164", "0x400280007ffc7fff", "0x400380017ffc7ffa", "0x400280027ffc7ffe", "0x400280037ffc7ffd", "0x480280057ffc8000", "0x20680017fff7fff", "0xc", "0x480280047ffc8000", "0x482680017ffc8000", "0x7", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480280067ffc8000", "0x10780017fff7fff", "0x9", "0x480280047ffc8000", "0x482680017ffc8000", "0x8", "0x480680017fff8000", "0x1", "0x480280067ffc8000", "0x480280077ffc8000", "0x1104800180018000", "0x4d", "0x20680017fff7ffd", "0xc", "0x48127ff07fff8000", "0x48127ff57fff8000", "0x48127fef7fff8000", "0x48127ff47fff8000", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x48127ff07fff8000", "0x48127ff57fff8000", "0x48127fef7fff8000", "0x48127ff47fff8000", "0x480680017fff8000", "0x1", "0x48127ff97fff8000", "0x48127ff97fff8000", "0x208b7fff7fff7ffe", "0x480680017fff8000", "0x35fe13a5db37080bfbfae639e6c19be9719e0fbdd4db062eb83cceb4d85a7fe", "0x400280007ffc7fff", "0x400380017ffc7ffd", "0x480280027ffc8000", "0xa0680017fff8005", "0xe", "0x4824800180057ffe", "0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00", "0x484480017ffe8000", "0x110000000000000000", "0x48307ffe7fff8003", "0x480280007ffb7ffc", "0x480280017ffb7ffc", "0x482480017ffb7ffd", "0xffffffffffffffeefffffffffffffeff", "0x400280027ffb7ffc", "0x10780017fff7fff", "0x11", "0x48127ffe7fff8005", "0x484480017ffe8000", "0x8000000000000000000000000000000", "0x48307ffe7fff8003", "0x480280007ffb7ffd", "0x482480017ffc7ffe", "0xf0000000000000000000000000000100", "0x480280017ffb7ffd", "0x400280027ffb7ff9", "0x402480017ffd7ff9", "0xffffffffffffffffffffffffffffffff", "0x20680017fff7ffd", "0x4", "0x402780017fff7fff", "0x1", "0x482680017ffb8000", "0x3", "0x482680017ffc8000", "0x3", "0x48127ffd7fff8000", "0x208b7fff7fff7ffe", "0x20780017fff7ffb", "0x9", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x208b7fff7fff7ffe", "0x480680017fff8000", "0x1", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x208b7fff7fff7ffe", "0x20780017fff7ffb", "0x8", "0x480680017fff8000", "0x0", "0x480680017fff8000", "0x0", "0x480a7ffd7fff8000", "0x208b7fff7fff7ffe", "0x480680017fff8000", "0x1", "0x480a7ffc7fff8000", "0x480a7ffd7fff8000", "0x208b7fff7fff7ffe"], "hints": [[0, [{"TestLessThanOrEqual": {"lhs": {"Immediate": "0x37aa"}, "rhs": {"Deref": {"register": "FP", "offset": -6}}, "dst": {"register": "AP", "offset": 0}}}]], [31, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [54, [{"TestLessThanOrEqual": {"lhs": {"Deref": {"register": "AP", "offset": -1}}, "rhs": {"Deref": {"register": "AP", "offset": -40}}, "dst": {"register": "AP", "offset": 0}}}]], [75, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [95, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [111, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [126, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [141, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [157, [{"TestLessThanOrEqual": {"lhs": {"Immediate": "0x3232"}, "rhs": {"Deref": {"register": "FP", "offset": -6}}, "dst": {"register": "AP", "offset": 0}}}]], [182, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [205, [{"TestLessThanOrEqual": {"lhs": {"Deref": {"register": "AP", "offset": -1}}, "rhs": {"Deref": {"register": "AP", "offset": -25}}, "dst": {"register": "AP", "offset": 0}}}]], [225, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [250, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [266, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [281, [{"AllocSegment": {"dst": {"register": "AP", "offset": 0}}}]], [410, [{"SystemCall": {"system": {"Deref": {"register": "FP", "offset": -5}}}}]], [468, [{"SystemCall": {"system": {"Deref": {"register": "FP", "offset": -4}}}}]], [516, [{"TestLessThan": {"lhs": {"Deref": {"register": "AP", "offset": -1}}, "rhs": {"Immediate": "0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00"}, "dst": {"register": "AP", "offset": 5}}}]], [520, [{"LinearSplit": {"value": {"Deref": {"register": "AP", "offset": 4}}, "scalar": {"Immediate": "0x110000000000000000"}, "max_x": {"Immediate": "0xffffffffffffffffffffffffffffffff"}, "x": {"register": "AP", "offset": -2}, "y": {"register": "AP", "offset": -1}}}]], [531, [{"LinearSplit": {"value": {"Deref": {"register": "AP", "offset": 4}}, "scalar": {"Immediate": "0x8000000000000000000000000000000"}, "max_x": {"Immediate": "0xfffffffffffffffffffffffffffffffe"}, "x": {"register": "AP", "offset": -2}, "y": {"register": "AP", "offset": -1}}}]]], "pythonic_hints": [[0, ["memory[ap + 0] = 14250 <= memory[fp + -6]"]], [31, ["memory[ap + 0] = segments.add()"]], [54, ["memory[ap + 0] = memory[ap + -1] <= memory[ap + -40]"]], [75, ["memory[ap + 0] = segments.add()"]], [95, ["memory[ap + 0] = segments.add()"]], [111, ["memory[ap + 0] = segments.add()"]], [126, ["memory[ap + 0] = segments.add()"]], [141, ["memory[ap + 0] = segments.add()"]], [157, ["memory[ap + 0] = 12850 <= memory[fp + -6]"]], [182, ["memory[ap + 0] = segments.add()"]], [205, ["memory[ap + 0] = memory[ap + -1] <= memory[ap + -25]"]], [225, ["memory[ap + 0] = segments.add()"]], [250, ["memory[ap + 0] = segments.add()"]], [266, ["memory[ap + 0] = segments.add()"]], [281, ["memory[ap + 0] = segments.add()"]], [410, ["syscall_handler.syscall(syscall_ptr=memory[fp + -5])"]], [468, ["syscall_handler.syscall(syscall_ptr=memory[fp + -4])"]], [516, ["memory[ap + 5] = memory[ap + -1] < 3618502788666131106986593281521497120414687020801267626233049500247285300992"]], [520, ["\n(value, scalar) = (memory[ap + 4], 313594649253062377472)\nx = min(value // scalar, 340282366920938463463374607431768211455)\ny = value - x * scalar\nmemory[ap + -2] = x\nmemory[ap + -1] = y\n"]], [531, ["\n(value, scalar) = (memory[ap + 4], 10633823966279326983230456482242756608)\nx = min(value // scalar, 340282366920938463463374607431768211454)\ny = value - x * scalar\nmemory[ap + -2] = x\nmemory[ap + -1] = y\n"]]], "compiler_version": "2.4.0"} \ No newline at end of file diff --git a/starknet/compiler.go b/starknet/compiler.go new file mode 100644 index 0000000000..3e006a66a3 --- /dev/null +++ b/starknet/compiler.go @@ -0,0 +1,48 @@ +package starknet + +//#include +//#include +//#include +// extern char* compileSierraToCasm(char* sierra_json); +// extern void freeCstr(char* ptr); +// +// #cgo vm_debug LDFLAGS: -L./rust/target/debug -ljuno_starknet_compiler_rs -ldl -lm +// #cgo !vm_debug LDFLAGS: -L./rust/target/release -ljuno_starknet_compiler_rs -ldl -lm +import "C" + +import ( + "encoding/json" + "errors" + "unsafe" +) + +func Compile(sierra *SierraDefinition) (*CompiledClass, error) { + sierraJSON, err := json.Marshal(SierraDefinition{ + EntryPoints: sierra.EntryPoints, + Program: sierra.Program, + Version: sierra.Version, + }) + if err != nil { + return nil, err + } + + sierraJSONCstr := C.CString(string(sierraJSON)) + defer func() { + C.free(unsafe.Pointer(sierraJSONCstr)) + }() + + casmJSONOrErrorCstr := C.compileSierraToCasm(sierraJSONCstr) + casmJSONOrError := C.GoString(casmJSONOrErrorCstr) + C.freeCstr(casmJSONOrErrorCstr) + + var casmClass CompiledClass + if err = json.Unmarshal([]byte(casmJSONOrError), &casmClass); err != nil { + var syntaxErr *json.SyntaxError + if errors.As(err, &syntaxErr) { + return nil, errors.New(casmJSONOrError) + } + return nil, err + } + + return &casmClass, nil +} diff --git a/starknet/compiler_test.go b/starknet/compiler_test.go new file mode 100644 index 0000000000..afa1ac4b33 --- /dev/null +++ b/starknet/compiler_test.go @@ -0,0 +1,40 @@ +package starknet_test + +import ( + "context" + "testing" + + "github.com/NethermindEth/juno/adapters/sn2core" + "github.com/NethermindEth/juno/clients/feeder" + "github.com/NethermindEth/juno/starknet" + "github.com/NethermindEth/juno/utils" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCompile(t *testing.T) { + t.Run("zero sierra", func(t *testing.T) { + _, err := starknet.Compile(&starknet.SierraDefinition{}) + require.Error(t, err) + }) + + t.Run("ok", func(t *testing.T) { + cl := feeder.NewTestClient(t, utils.Integration) + classHash := utils.HexToFelt(t, "0xc6c634d10e2cc7b1db6b4403b477f05e39cb4900fd5ea0156d1721dbb6c59b") + + classDef, err := cl.ClassDefinition(context.Background(), classHash) + require.NoError(t, err) + compiledDef, err := cl.CompiledClassDefinition(context.Background(), classHash) + require.NoError(t, err) + + expectedCompiled, err := sn2core.AdaptCompiledClass(compiledDef) + require.NoError(t, err) + + res, err := starknet.Compile(classDef.V1) + require.NoError(t, err) + + gotCompiled, err := sn2core.AdaptCompiledClass(res) + require.NoError(t, err) + assert.Equal(t, expectedCompiled.Hash(), gotCompiled.Hash()) + }) +} diff --git a/starknet/rust/.gitignore b/starknet/rust/.gitignore new file mode 100644 index 0000000000..9ce42caa92 --- /dev/null +++ b/starknet/rust/.gitignore @@ -0,0 +1,9 @@ +/target + + +# Added by cargo +# +# already existing elements were commented out + +#/target +/Cargo.lock diff --git a/starknet/rust/Cargo.toml b/starknet/rust/Cargo.toml new file mode 100644 index 0000000000..68d17c9bba --- /dev/null +++ b/starknet/rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "juno-starknet-compiler-rs" +version = "0.0.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = "1.0.171" +serde_json = { version = "1.0.96", features = ["raw_value"] } +cairo-lang-starknet = "=2.4.0" + +[lib] +crate-type = ["staticlib"] diff --git a/starknet/rust/Makefile b/starknet/rust/Makefile new file mode 100644 index 0000000000..1342be6da2 --- /dev/null +++ b/starknet/rust/Makefile @@ -0,0 +1,23 @@ +all: + cargo build --release + +debug: + cargo build + +check: + cargo check --release + +lint: + cargo clippy + +fix: + cargo fix --lib -p juno-starknet-compiler-rs --allow-dirty --allow-staged + +clean: + cargo clean + +format: + cargo fmt + +install-rustfmt: + cargo install rustfmt \ No newline at end of file diff --git a/starknet/rust/src/lib.rs b/starknet/rust/src/lib.rs new file mode 100644 index 0000000000..4eb4d5ce7c --- /dev/null +++ b/starknet/rust/src/lib.rs @@ -0,0 +1,39 @@ +use std::ffi::{c_char, CStr, CString}; +use cairo_lang_starknet::casm_contract_class::CasmContractClass; + +#[no_mangle] +pub extern "C" fn compileSierraToCasm(sierra_json: *const c_char) -> *mut c_char { + let sierra_json_str = unsafe { CStr::from_ptr(sierra_json) }.to_str().unwrap(); + + let sierra_class = + serde_json::from_str(sierra_json_str).map_err(|err| err.to_string()); + if let Err(e) = sierra_class { + return raw_cstr(e) + } + + let casm_class = CasmContractClass::from_contract_class(sierra_class.unwrap(), true) + .map_err(|err| err.to_string()); + if let Err(e) = casm_class { + return raw_cstr(e) + } + + let casm_json = serde_json::to_string(&casm_class.unwrap()); + if let Err(e) = casm_json { + return raw_cstr(e.to_string()) + } + return raw_cstr(casm_json.unwrap()) +} + +fn raw_cstr(str: String) -> *mut c_char { + CString::new(str).unwrap().into_raw() +} + +#[no_mangle] +pub extern "C" fn freeCstr(ptr: *mut c_char) { + unsafe { + if ptr.is_null() { + return; + } + let _ = CString::from_raw(ptr); + }; +}