diff --git a/__mocks__/cairo/cairo260/hello260.cairo b/__mocks__/cairo/cairo260/hello260.cairo new file mode 100644 index 000000000..f34f5dcb3 --- /dev/null +++ b/__mocks__/cairo/cairo260/hello260.cairo @@ -0,0 +1,27 @@ +// Cairo 2.6.0 +#[starknet::interface] +trait IHelloStarknet { + fn set_name(ref self: TContractState, name1: felt252); + fn get_name(self: @TContractState) -> felt252; +} + + +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + name: felt252, + } + + #[abi(embed_v0)] + impl HelloStarknetImpl of super::IHelloStarknet { + fn set_name(ref self: ContractState, name1: felt252) { + assert(name1 != '', 'Enter a name'); + self.name.write(name1); + } + + fn get_name(self: @ContractState) -> felt252 { + self.name.read() + } + } +} \ No newline at end of file diff --git a/__mocks__/cairo/cairo260/hello260.casm b/__mocks__/cairo/cairo260/hello260.casm new file mode 100644 index 000000000..2e87ed9a3 --- /dev/null +++ b/__mocks__/cairo/cairo260/hello260.casm @@ -0,0 +1,565 @@ +{ + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "compiler_version": "2.6.0", + "bytecode": [ + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0x100000000000000000000000000000000", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x95", + "0x4825800180007ffa", + "0x0", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0xa", + "0x482680017ffc8000", + "0x1", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x0", + "0x480280007ffc8000", + "0x10780017fff7fff", + "0x8", + "0x480a7ffc7fff8000", + "0x480a7ffd7fff8000", + "0x480680017fff8000", + "0x1", + "0x480680017fff8000", + "0x0", + "0x20680017fff7ffe", + "0x6d", + "0x48307ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ff77fff8000", + "0x48127ff57fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0xe9", + "0x482480017fff8000", + "0xe8", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff3", + "0x11bc", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff27fff", + "0x10780017fff7fff", + "0x3d", + "0x4824800180007ff3", + "0x11bc", + "0x400080007ff37fff", + "0x482480017ff38000", + "0x1", + "0x20680017fff7ff7", + "0x10", + "0x40780017fff7fff", + "0x2", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x456e7465722061206e616d65", + "0x400080007ffe7fff", + "0x48127ffa7fff8000", + "0x480a7ffb7fff8000", + "0x48127ffc7fff8000", + "0x482480017ffb8000", + "0x1", + "0x10780017fff7fff", + "0x20", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x361458367e696363fbcc70777d07ebbd2394e89fd0adcaf147faccd1d294d60", + "0x480680017fff8000", + "0x53746f726167655772697465", + "0x400280007ffb7fff", + "0x400280017ffb7ffb", + "0x400280027ffb7ffd", + "0x400280037ffb7ffe", + "0x400280047ffb7ff4", + "0x480280067ffb8000", + "0x20680017fff7fff", + "0xd", + "0x40780017fff7fff", + "0x1", + "0x48127ffa7fff8000", + "0x480280057ffb8000", + "0x482680017ffb8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x48127ffb7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x480280057ffb8000", + "0x482680017ffb8000", + "0x9", + "0x480280077ffb8000", + "0x480280087ffb8000", + "0x48127ff77fff8000", + "0x48127ffb7fff8000", + "0x48127ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x48127ffa7fff8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff08000", + "0x1", + "0x48127fee7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x400080007ffe7fff", + "0x48127ff87fff8000", + "0x48127ff67fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0xa0680017fff8000", + "0x7", + "0x482680017ffa8000", + "0x100000000000000000000000000000000", + "0x400280007ff97fff", + "0x10780017fff7fff", + "0x60", + "0x4825800180007ffa", + "0x0", + "0x400280007ff97fff", + "0x482680017ff98000", + "0x1", + "0x48297ffc80007ffd", + "0x20680017fff7fff", + "0x4", + "0x10780017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x400080007ffe7fff", + "0x48127ffc7fff8000", + "0x48127ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x55", + "0x482480017fff8000", + "0x54", + "0x480080007fff8000", + "0xa0680017fff8000", + "0x9", + "0x4824800180007ff8", + "0xd70", + "0x482480017fff8000", + "0x100000000000000000000000000000000", + "0x400080007ff77fff", + "0x10780017fff7fff", + "0x2b", + "0x4824800180007ff8", + "0xd70", + "0x400080007ff87fff", + "0x480680017fff8000", + "0x0", + "0x480680017fff8000", + "0x361458367e696363fbcc70777d07ebbd2394e89fd0adcaf147faccd1d294d60", + "0x482480017ff68000", + "0x1", + "0x480680017fff8000", + "0x53746f7261676552656164", + "0x400280007ffb7fff", + "0x400280017ffb7ffb", + "0x400280027ffb7ffc", + "0x400280037ffb7ffd", + "0x480280057ffb8000", + "0x20680017fff7fff", + "0x10", + "0x40780017fff7fff", + "0x1", + "0x480280067ffb8000", + "0x400080007ffe7fff", + "0x48127ffb7fff8000", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x7", + "0x480680017fff8000", + "0x0", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x48127ffd7fff8000", + "0x480280047ffb8000", + "0x482680017ffb8000", + "0x8", + "0x480680017fff8000", + "0x1", + "0x480280067ffb8000", + "0x480280077ffb8000", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482480017ff58000", + "0x1", + "0x48127ff37fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe", + "0x40780017fff7fff", + "0x1", + "0x480680017fff8000", + "0x4f7574206f6620676173", + "0x400080007ffe7fff", + "0x482680017ff98000", + "0x1", + "0x480a7ffa7fff8000", + "0x480a7ffb7fff8000", + "0x480680017fff8000", + "0x1", + "0x48127ffa7fff8000", + "0x482480017ff98000", + "0x1", + "0x208b7fff7fff7ffe" + ], + "bytecode_segment_lengths": [ + 169, + 116 + ], + "hints": [ + [ + 0, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x0" + }, + "rhs": { + "Deref": { + "register": "FP", + "offset": -6 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 38, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 57, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x11bc" + }, + "rhs": { + "Deref": { + "register": "AP", + "offset": -12 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 75, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 98, + [ + { + "SystemCall": { + "system": { + "Deref": { + "register": "FP", + "offset": -5 + } + } + } + } + ] + ], + [ + 101, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 125, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 140, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 154, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 169, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0x0" + }, + "rhs": { + "Deref": { + "register": "FP", + "offset": -6 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 186, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 205, + [ + { + "TestLessThanOrEqual": { + "lhs": { + "Immediate": "0xd70" + }, + "rhs": { + "Deref": { + "register": "AP", + "offset": -7 + } + }, + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 229, + [ + { + "SystemCall": { + "system": { + "Deref": { + "register": "FP", + "offset": -5 + } + } + } + } + ] + ], + [ + 232, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 255, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ], + [ + 270, + [ + { + "AllocSegment": { + "dst": { + "register": "AP", + "offset": 0 + } + } + } + ] + ] + ], + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0xf61980aeb34c9c7f823d576c10d00648fdab6c03a59b539ed0824be31da466", + "offset": 0, + "builtins": [ + "range_check" + ] + }, + { + "selector": "0x31341177714d81ad9ccd0c903211bc056a60e8af988d0fd918cc43874549653", + "offset": 169, + "builtins": [ + "range_check" + ] + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + } +} \ No newline at end of file diff --git a/__mocks__/cairo/cairo260/hello260.sierra.json b/__mocks__/cairo/cairo260/hello260.sierra.json new file mode 100644 index 000000000..ada16ae66 --- /dev/null +++ b/__mocks__/cairo/cairo260/hello260.sierra.json @@ -0,0 +1,293 @@ +{ + "sierra_program": [ + "0x1", + "0x5", + "0x0", + "0x2", + "0x6", + "0x0", + "0x97", + "0x69", + "0x18", + "0x52616e6765436865636b", + "0x800000000000000100000000000000000000000000000000", + "0x436f6e7374", + "0x800000000000000000000000000000000000000000000002", + "0x1", + "0xc", + "0x2", + "0x4661696c656420746f20646573657269616c697a6520706172616d202331", + "0x4f7574206f6620676173", + "0x4172726179", + "0x800000000000000300000000000000000000000000000001", + "0x536e617073686f74", + "0x800000000000000700000000000000000000000000000001", + "0x3", + "0x537472756374", + "0x800000000000000700000000000000000000000000000002", + "0x0", + "0x1baeba72e79e9db2587cf44fedb2f3700b2075a5e8e39a562584862c4b71f62", + "0x4", + "0x2ee1e2b1b89f8c495f200e4956278a4d47395fe262f27b52e5865c9524c08c3", + "0x5", + "0x8", + "0x753332", + "0x800000000000000700000000000000000000000000000000", + "0x53746f7261676541646472657373", + "0x53746f726167654261736541646472657373", + "0x456e7465722061206e616d65", + "0x66656c74323532", + "0x4e6f6e5a65726f", + "0x4275696c74696e436f737473", + "0x53797374656d", + "0x800000000000000f00000000000000000000000000000001", + "0x16a4c8d7c05909052238a862d8cc3e7975bf05a07b3a69c6b28951083a6d672", + "0x800000000000000300000000000000000000000000000003", + "0x10", + "0x456e756d", + "0x9931c641b913035ae674b400b61a51476d506bbe8bba2ff8a6272790aba9e6", + "0x6", + "0x11", + "0x496e70757420746f6f206c6f6e6720666f7220617267756d656e7473", + "0x800000000000000700000000000000000000000000000003", + "0x11c6d8087e00642489f92d2821ad6ebd6532ad1a3b6d12833da6d6810391511", + "0x14", + "0x426f78", + "0x4761734275696c74696e", + "0x36", + "0x7265766f6b655f61705f747261636b696e67", + "0x77697468647261775f676173", + "0x6272616e63685f616c69676e", + "0x7374727563745f6465636f6e737472756374", + "0x656e61626c655f61705f747261636b696e67", + "0x73746f72655f74656d70", + "0x61727261795f736e617073686f745f706f705f66726f6e74", + "0x756e626f78", + "0x72656e616d65", + "0x656e756d5f696e6974", + "0x15", + "0x6a756d70", + "0x7374727563745f636f6e737472756374", + "0x656e756d5f6d61746368", + "0x64697361626c655f61705f747261636b696e67", + "0x64726f70", + "0x16", + "0x61727261795f6e6577", + "0x636f6e73745f61735f696d6d656469617465", + "0x13", + "0x61727261795f617070656e64", + "0x12", + "0x17", + "0xf", + "0x6765745f6275696c74696e5f636f737473", + "0xe", + "0x77697468647261775f6761735f616c6c", + "0x647570", + "0x66656c743235325f69735f7a65726f", + "0xb", + "0xd", + "0x73746f726167655f626173655f616464726573735f636f6e7374", + "0x361458367e696363fbcc70777d07ebbd2394e89fd0adcaf147faccd1d294d60", + "0x73746f726167655f616464726573735f66726f6d5f62617365", + "0x7", + "0x9", + "0x73746f726167655f77726974655f73797363616c6c", + "0x736e617073686f745f74616b65", + "0x73746f726167655f726561645f73797363616c6c", + "0xde", + "0xffffffffffffffff", + "0x7c", + "0xa", + "0x6c", + "0x27", + "0x19", + "0x1a", + "0x1b", + "0x1c", + "0x1d", + "0x1e", + "0x1f", + "0x20", + "0x5e", + "0x21", + "0x22", + "0x23", + "0x3c", + "0x24", + "0x25", + "0x26", + "0x28", + "0x29", + "0x2a", + "0x55", + "0x2b", + "0x2c", + "0x2d", + "0x2e", + "0x2f", + "0x51", + "0x30", + "0x31", + "0x32", + "0x33", + "0x34", + "0x35", + "0x37", + "0x38", + "0x39", + "0x3a", + "0x3b", + "0x3d", + "0x3e", + "0x3f", + "0x40", + "0x41", + "0x42", + "0x43", + "0x44", + "0x45", + "0x46", + "0x47", + "0x48", + "0x49", + "0x4a", + "0x4b", + "0x4c", + "0x4d", + "0xd0", + "0x9f", + "0xc3", + "0xba", + "0x8a", + "0x80e", + "0x100f13051211100f0e050d0c06050b0a090706050403080706050403020100", + "0x1f181e06050d1d181c1b0706050403181a1819181711071605040315051411", + "0x1411200f28070605040327052605251122240e0523051411220f2111200f02", + "0x1105053411331505053211311130112f2e022d06050d2c2b0506052a112924", + "0x5053b113a3905053413050534110739050738060505370605053606050535", + "0x541060505400605053e3f05053e1305053e113d3905053c0507390507382b", + "0x50534450505340507440507382705053b2305053b06050543060505344205", + "0x4d05053e0e0505344c050541114b0605054a11494805053411474405053446", + "0x5053b0e05053e0e050554115352050534160505345105054111504f07054e", + "0x115611551505053e050505412b05053e070505411107440507382605053b15", + "0x57050e050e1111570511071151260758151307570705110705111157051111", + "0x1107114c054859520757071605261113055705130515111157051113111605", + "0x52055911480557054d0552114d055705060516110605570559055111115705", + "0x27055705114d111157051107111142051106112305570548054c1146055705", + "0x55707230546112305570544054c11460557054c0559114405570527054811", + "0x11231111570511071145055b3f39075707460526111157051107112b055a42", + "0x55705112b11115705420542111157053f05441111570539052711115705", + "0x5e0557051100115d0557055c000745115c0557055c053f115c055705113911", + "0x570515055e111305570513051511600557055f055d115f0557055d5e075c11", + "0x1111570511071160071513130560055705600560110705570507055f111505", + "0x130e6311610557056105621161055705116111115705450527111157051123", + "0x42075705420565111157051113111157051107116665076463620757076115", + "0x57054205421111570511071169056811570767056611620557056205151167", + "0x557056b6a0745116b0557056b053f116b0557051167116a055705112b1111", + "0x116f051106116e0557055b0569116d05570507055f116c05570563055e115b", + "0x116c117105570570055b1170055705116b1111570569056a11115705110711", + "0x7570742717207631570117105570571056e117205570572056d1172055705", + "0x57905711179055705112b111157051123111157051107117877760e757473", + "0x7c0576117c0557052e0574112e0557057b0573111157057a0572117b7a0757", + "0x560117405570574055f117305570573055e1162055705620515117d055705", + "0x570577055f116c05570576055e111157051107117d74736213057d0557057d", + "0x557056e7e075c117e0557051100111157051123116e055705780569116d05", + "0x57056d055f116c0557056c055e116205570562051511800557057f055d117f", + "0x2b1111570542054211115705110711806d6c62130580055705800560116d05", + "0x118205570581680745118105570581053f11810557051177116805570511", + "0x1165055705650515118505570584055d11840557058283075c118305570511", + "0x71185076665130585055705850560110705570507055f116605570566055e", + "0x86055705112b11115705460527111157052b05781111570511231111570511", + "0x890557051100118805570587860745118705570587053f1187055705117911", + "0x570515055e1113055705130515118b0557058a055d118a0557058889075c11", + "0x111157051107118b07151313058b0557058b0560110705570507055f111505", + "0x745118d0557058d053f118d0557051177118c055705112b111157050e057a", + "0x119105570590055d11900557058e8f075c118f0557051100118e0557058d8c", + "0x91055705910560110705570507055f115105570551055e1126055705260515", + "0x57051107115126079215130757070511070511115705111111910751261305", + "0x7114c05935952075707160526111305570513051511160557050e050e1111", + "0x5570511391106055705112b11115705590544111157055205271111570511", + "0x54846075c1146055705110011480557054d060745114d0557054d053f114d", + "0x7055f111505570515055e1113055705130515112705570523055d11230557", + "0x1157054c052711115705110711270715131305270557052705601107055705", + "0x113f3907942b420757074415130e6311440557054405621144055705116111", + "0x5c056d115c055705116c110005570545055b1145055705116b111157051107", + "0x5d0e5707005c072b137b1142055705420515110005570500056e115c055705", + "0x745115f0557055f053f1163055705112b111157051107116261600e955f5e", + "0x11690557056705731111570566057211676607570565057111650557055f63", + "0x5d0557055d055e1142055705420515116b0557056a0576116a055705690574", + "0x1100111157051107116b5e5d4213056b0557056b0560115e0557055e055f11", + "0x5e1142055705420515116d0557056c055d116c055705625b075c115b055705", + "0x1107116d61604213056d0557056d0560116105570561055f11600557056005", + "0x5706e0745117005570570053f11700557051177116e055705112b11115705", + "0x390515117405570573055d11730557057172075c1172055705110011710557", + "0x39130574055705740560110705570507055f113f0557053f055e1139055705", + "0x117705570511771176055705112b111157050e057a1111570511071174073f", + "0x557057879075c11790557051100117805570577760745117705570577053f", + "0x570507055f115105570551055e1126055705260515117b0557057a055d117a", + "0xe07051144464511131546451113077b07512613057b0557057b0560110705", + "0x960e0705114446451113154645111311" + ], + "sierra_program_debug_info": { + "type_names": [], + "libfunc_names": [], + "user_func_names": [] + }, + "contract_class_version": "0.1.0", + "entry_points_by_type": { + "EXTERNAL": [ + { + "selector": "0xf61980aeb34c9c7f823d576c10d00648fdab6c03a59b539ed0824be31da466", + "function_idx": 0 + }, + { + "selector": "0x31341177714d81ad9ccd0c903211bc056a60e8af988d0fd918cc43874549653", + "function_idx": 1 + } + ], + "L1_HANDLER": [], + "CONSTRUCTOR": [] + }, + "abi": [ + { + "type": "impl", + "name": "HelloStarknetImpl", + "interface_name": "hello::hello::IHelloStarknet" + }, + { + "type": "interface", + "name": "hello::hello::IHelloStarknet", + "items": [ + { + "type": "function", + "name": "set_name", + "inputs": [ + { + "name": "name1", + "type": "core::felt252" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_name", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "event", + "name": "hello::hello::HelloStarknet::Event", + "kind": "enum", + "variants": [] + } + ] +} diff --git a/__tests__/cairo1v2.test.ts b/__tests__/cairo1v2.test.ts index c057ca512..5e532dbaa 100644 --- a/__tests__/cairo1v2.test.ts +++ b/__tests__/cairo1v2.test.ts @@ -35,6 +35,8 @@ import { compiledC210Casm, compiledC240, compiledC240Casm, + compiledC260, + compiledC260Casm, compiledComplexSierra, compiledHelloSierra, compiledTuple, @@ -1164,4 +1166,16 @@ describe('Cairo 1', () => { }); }); }); + + describe('Cairo2.6.0 Sierra1.5.0', () => { + test('declare Sierra 1.5.0', async () => { + const declare260Response = await account.declare({ + contract: compiledC260, + casm: compiledC260Casm, + }); + expect(declare260Response.class_hash).toBe( + '0x6184f1a71cad4bd123ff8bb3b97dc9ec876ced6489d9479cfdaada81a2f06d6' + ); + }); + }); }); diff --git a/__tests__/config/fixtures.ts b/__tests__/config/fixtures.ts index 11729ac83..65bfd68f6 100644 --- a/__tests__/config/fixtures.ts +++ b/__tests__/config/fixtures.ts @@ -46,6 +46,8 @@ export const compiledC210 = readContractSierra('cairo/cairo210/cairo210.sierra') export const compiledC210Casm = readContractSierraCasm('cairo/cairo210/cairo210'); export const compiledC240 = readContractSierra('cairo/cairo240/string.sierra'); export const compiledC240Casm = readContractSierraCasm('cairo/cairo240/string'); +export const compiledC260 = readContractSierra('cairo/cairo260/hello260.sierra'); +export const compiledC260Casm = readContractSierraCasm('cairo/cairo260/hello260'); export const compiledTuple = readContractSierra('cairo/cairo253/tupleResponse.sierra'); export const compiledTupleCasm = readContractSierraCasm('cairo/cairo253/tupleResponse'); // StarknetId diff --git a/__tests__/utils/classHash.test.ts b/__tests__/utils/classHash.test.ts index 1707d9a6a..5e1c5d10d 100644 --- a/__tests__/utils/classHash.test.ts +++ b/__tests__/utils/classHash.test.ts @@ -5,6 +5,7 @@ import { getSelectorFromName, } from '../../src/utils/hash'; import { + compiledC260Casm, compiledErc20, compiledHashSierra, compiledHashSierraCasm, @@ -54,6 +55,13 @@ describe('Hash Tester', () => { ); }); + test('Hello - CompiledClassHash Cairo2.6.0 Sierra1.5.0', () => { + const compiledClassHash = computeCompiledClassHash(compiledC260Casm); + expect(compiledClassHash).toEqual( + '0x1725af24fbfa8050f4514651990b30e06bb9993e4e5c1051206f1bef218b1c6' + ); + }); + test('Hello - ClassHash', () => { const classHash = computeSierraContractClassHash(compiledHashSierra); expect(classHash).toEqual( diff --git a/src/types/lib/contract/sierra.ts b/src/types/lib/contract/sierra.ts index 9d7628c84..a0dcdc678 100644 --- a/src/types/lib/contract/sierra.ts +++ b/src/types/lib/contract/sierra.ts @@ -8,6 +8,7 @@ export type CairoAssembly = { bytecode: ByteCode; hints: any[]; pythonic_hints?: PythonicHints; + bytecode_segment_lengths?: number[]; // if Sierra >= v1.5.0 entry_points_by_type: EntryPointsByType; }; @@ -33,6 +34,10 @@ export type SierraContractClass = Omit BigInt(n)); + const bytecodeSegmentLengths: number[] = casm.bytecode_segment_lengths ?? []; + + let segmentStart = 0; + const hashLeaves = bytecodeSegmentLengths.flatMap((len) => { + const segment = byteCode.slice(segmentStart, (segmentStart += len)); + + return [BigInt(len), poseidonHashMany(segment)]; + }); + return 1n + poseidonHashMany(hashLeaves); +} + /** * Compute compiled class hash for contract (Cairo 1) * @returns format: hex-string @@ -198,7 +219,9 @@ export function computeCompiledClassHash(casm: CompiledSierraCasm) { const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR); // Hash bytecode. - const bytecode = poseidonHashMany(casm.bytecode.map((it: string) => BigInt(it))); + const bytecode = casm.bytecode_segment_lengths + ? hashByteCodeSegments(casm) + : poseidonHashMany(casm.bytecode.map((it: string) => BigInt(it))); return toHex( poseidonHashMany([ diff --git a/www/docs/guides/connect_network.md b/www/docs/guides/connect_network.md index eceb65e3d..1c3591048 100644 --- a/www/docs/guides/connect_network.md +++ b/www/docs/guides/connect_network.md @@ -35,10 +35,11 @@ On Starknet.js side, you have to select the proper version, to be in accordance | :---------------------------: | ---------------------------- | | v0.4.0 | Starknet.js v5.21.1 | | v0.5.0 | Starknet.js v5.23.0 | -| v0.5.1 | Starknet.js v5.29.0 & v6.0.0 | -| v0.6.0 | Starknet.js v6.0.0 | +| v0.5.1 | Starknet.js v5.29.0 & v6.3.0 | +| v0.6.0 | Starknet.js v6.3.0 | +| v0.7.0 | Starknet.js v6.3.0 | -Starknet.js v6.x.x will recognize automatically if you are connected to a v0.5.1 or a v0.6.0 rpc spec version. +[!NOTE] Each Starknet.js version 6.x.x is compatible with 3 rpc spec versions, and recognize automatically the spec version if not provided. With the `RpcProvider` class, you define the Starknet Rpc node to use.