From 3ecba4e783196620b3e78a6f52b314463d953e09 Mon Sep 17 00:00:00 2001 From: bishalbikram Date: Mon, 30 Dec 2024 01:43:06 +0545 Subject: [PATCH] chore: upgrade soroban-sdk version and rlp --- contracts/soroban/Cargo.lock | 452 ++++++++++-------- contracts/soroban/Cargo.toml | 6 +- contracts/soroban/contracts/intent/Cargo.toml | 2 +- .../soroban/contracts/intent/src/fill.rs | 4 +- .../soroban/contracts/intent/src/helpers.rs | 6 +- .../contracts/intent/src/test/cancel.rs | 8 +- .../soroban/contracts/intent/src/test/fill.rs | 6 +- .../contracts/intent/src/test/types.rs | 4 +- .../contracts/intent/src/types/swap_order.rs | 4 +- contracts/soroban/libs/soroban-rlp/Cargo.toml | 12 - .../soroban/libs/soroban-rlp/src/decoder.rs | 160 ------- .../soroban/libs/soroban-rlp/src/encoder.rs | 100 ---- contracts/soroban/libs/soroban-rlp/src/lib.rs | 8 - .../soroban/libs/soroban-rlp/src/test.rs | 3 - .../libs/soroban-rlp/src/test/decoder.rs | 104 ---- .../libs/soroban-rlp/src/test/encoder.rs | 226 --------- .../libs/soroban-rlp/src/test/utils.rs | 45 -- .../soroban/libs/soroban-rlp/src/utils.rs | 107 ----- 18 files changed, 278 insertions(+), 979 deletions(-) delete mode 100644 contracts/soroban/libs/soroban-rlp/Cargo.toml delete mode 100644 contracts/soroban/libs/soroban-rlp/src/decoder.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/encoder.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/lib.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/test.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/test/decoder.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/test/encoder.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/test/utils.rs delete mode 100644 contracts/soroban/libs/soroban-rlp/src/utils.rs diff --git a/contracts/soroban/Cargo.lock b/contracts/soroban/Cargo.lock index 808964ae..b0a8bf14 100644 --- a/contracts/soroban/Cargo.lock +++ b/contracts/soroban/Cargo.lock @@ -4,18 +4,18 @@ version = 3 [[package]] name = "addr2line" -version = "0.21.0" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "android-tzdata" @@ -43,23 +43,23 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets", ] [[package]] @@ -82,9 +82,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" @@ -107,6 +107,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes-lit" version = "0.0.5" @@ -121,9 +127,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.94" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -133,9 +142,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -152,15 +161,15 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -200,9 +209,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c" +checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" dependencies = [ "quote", "syn", @@ -210,16 +219,15 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.2" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest", "fiat-crypto", - "platforms", "rustc_version", "subtle", "zeroize", @@ -238,9 +246,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.8" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ "darling_core", "darling_macro", @@ -248,9 +256,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.8" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", @@ -262,9 +270,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.8" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", @@ -331,7 +339,6 @@ dependencies = [ "elliptic-curve", "rfc6979", "signature", - "spki", ] [[package]] @@ -346,23 +353,24 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", "rand_core", "serde", "sha2", + "subtle", "zeroize", ] [[package]] name = "either" -version = "1.11.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -376,7 +384,6 @@ dependencies = [ "ff", "generic-array", "group", - "pkcs8", "rand_core", "sec1", "subtle", @@ -413,9 +420,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fnv" @@ -436,9 +443,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -449,9 +456,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "group" @@ -472,9 +479,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hex" @@ -502,9 +509,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -542,12 +549,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.15.2", "serde", ] @@ -576,31 +583,30 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ + "once_cell", "wasm-bindgen", ] [[package]] name = "k256" -version = "0.13.1" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "once_cell", "sha2", - "signature", ] [[package]] @@ -614,44 +620,43 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ - "adler", + "adler2", ] [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -664,9 +669,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-derive" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", @@ -675,43 +680,54 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "object" -version = "0.32.2" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "p256" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pkcs8" @@ -723,12 +739,6 @@ dependencies = [ "spki", ] -[[package]] -name = "platforms" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" - [[package]] name = "powerfmt" version = "0.2.0" @@ -737,34 +747,46 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "prettyplease" -version = "0.2.15" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", "syn", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -811,24 +833,24 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "sec1" @@ -839,31 +861,30 @@ dependencies = [ "base16ct", "der", "generic-array", - "pkcs8", "subtle", "zeroize", ] [[package]] name = "semver" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -872,26 +893,27 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_with" -version = "3.7.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "d6b6f7f2fcb69f747921f79f3926bd1e203fce4fef62c268dd3abfb6d86029aa" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.2.6", + "indexmap 2.7.0", "serde", "serde_derive", "serde_json", @@ -901,9 +923,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.7.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655" +checksum = "8d00caa5193a3c8362ac2b73be6b9e768aa5a4b2f721d8f4b339600c3cb51f8e" dependencies = [ "darling", "proc-macro2", @@ -932,6 +954,12 @@ dependencies = [ "keccak", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -950,9 +978,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "soroban-builtin-sdk-macros" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc32c6e817f3ca269764ec0d7d14da6210b74a5bf14d4e745aa3ee860558900" +checksum = "2f57a68ef8777e28e274de0f3a88ad9a5a41d9a2eb461b4dd800b086f0e83b80" dependencies = [ "itertools", "proc-macro2", @@ -962,9 +990,9 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c14e18d879c520ff82612eaae0590acaf6a7f3b977407e1abb1c9e31f94c7814" +checksum = "2fd1c89463835fe6da996318156d39f424b4f167c725ec692e5a7a2d4e694b3d" dependencies = [ "arbitrary", "crate-git-revision", @@ -976,13 +1004,14 @@ dependencies = [ "soroban-wasmi", "static_assertions", "stellar-xdr", + "wasmparser", ] [[package]] name = "soroban-env-guest" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5122ca2abd5ebcc1e876a96b9b44f87ce0a0e06df8f7c09772ddb58b159b7454" +checksum = "6bfb2536811045d5cd0c656a324cbe9ce4467eb734c7946b74410d90dea5d0ce" dependencies = [ "soroban-env-common", "static_assertions", @@ -990,13 +1019,16 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "114a0fa0d0cc39d0be16b1ee35b6e5f4ee0592ddcf459bde69391c02b03cf520" +checksum = "2b7a32c28f281c423189f1298960194f0e0fc4eeb72378028171e556d8cd6160" dependencies = [ "backtrace", "curve25519-dalek", + "ecdsa", "ed25519-dalek", + "elliptic-curve", + "generic-array", "getrandom", "hex-literal", "hmac", @@ -1004,8 +1036,10 @@ dependencies = [ "num-derive", "num-integer", "num-traits", + "p256", "rand", "rand_chacha", + "sec1", "sha2", "sha3", "soroban-builtin-sdk-macros", @@ -1013,13 +1047,14 @@ dependencies = [ "soroban-wasmi", "static_assertions", "stellar-strkey", + "wasmparser", ] [[package]] name = "soroban-env-macros" -version = "20.3.0" +version = "21.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b13e3f8c86f812e0669e78fcb3eae40c385c6a9dd1a4886a1de733230b4fcf27" +checksum = "242926fe5e0d922f12d3796cd7cd02dd824e5ef1caa088f45fce20b618309f64" dependencies = [ "itertools", "proc-macro2", @@ -1032,9 +1067,9 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "20.5.0" +version = "21.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a54708f44890e0546180db6b4f530e2a88d83b05a9b38a131caa21d005e25a" +checksum = "e6edf92749fd8399b417192d301c11f710b9cdce15789a3d157785ea971576fa" dependencies = [ "serde", "serde_json", @@ -1047,21 +1082,24 @@ dependencies = [ [[package]] name = "soroban-rlp" version = "0.1.0" +source = "git+http://github.com/icon-project/xcall-multi?branch=main#74bd6086e3abe350b34c31f5601de81de3081324" dependencies = [ "soroban-sdk", ] [[package]] name = "soroban-sdk" -version = "20.5.0" +version = "21.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fc8be9068dd4e0212d8b13ad61089ea87e69ac212c262914503a961c8dc3a3" +checksum = "7dcdf04484af7cc731a7a48ad1d9f5f940370edeea84734434ceaf398a6b862e" dependencies = [ "arbitrary", "bytes-lit", "ctor", + "derive_arbitrary", "ed25519-dalek", "rand", + "rustc_version", "serde", "serde_json", "soroban-env-guest", @@ -1073,9 +1111,9 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "20.5.0" +version = "21.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db20def4ead836663633f58d817d0ed8e1af052c9650a04adf730525af85b964" +checksum = "0974e413731aeff2443f2305b344578b3f1ffd18335a7ba0f0b5d2eb4e94c9ce" dependencies = [ "crate-git-revision", "darling", @@ -1093,9 +1131,9 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "20.5.0" +version = "21.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eefeb5d373b43f6828145d00f0c5cc35e96db56a6671ae9614f84beb2711cab" +checksum = "c2c70b20e68cae3ef700b8fa3ae29db1c6a294b311fba66918f90cb8f9fd0a1a" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -1105,9 +1143,9 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "20.5.0" +version = "21.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3152bca4737ef734ac37fe47b225ee58765c9095970c481a18516a2b287c7a33" +checksum = "a2dafbde981b141b191c6c036abc86097070ddd6eaaa33b273701449501e43d3" dependencies = [ "prettyplease", "proc-macro2", @@ -1167,9 +1205,9 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "20.1.0" +version = "21.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e59cdf3eb4467fb5a4b00b52e7de6dca72f67fac6f9b700f55c95a5d86f09c9d" +checksum = "2675a71212ed39a806e415b0dbf4702879ff288ec7f5ee996dda42a135512b50" dependencies = [ "arbitrary", "base64 0.13.1", @@ -1183,21 +1221,21 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.39" +version = "2.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" dependencies = [ "proc-macro2", "quote", @@ -1206,18 +1244,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.55" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.55" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -1226,9 +1264,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", @@ -1247,9 +1285,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -1263,15 +1301,15 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -1281,23 +1319,23 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn", @@ -1306,9 +1344,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1316,9 +1354,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -1329,9 +1367,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "wasmi_arena" @@ -1353,18 +1391,19 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.88.0" +version = "0.116.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8cf7dd82407fe68161bedcd57fde15596f32ebf6e9b3bdbf3ae1da20e38e5e" +checksum = "a58e28b80dd8340cb07b8242ae654756161f6fc8d0038123d679b7b99964fa50" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.7.0", + "semver", ] [[package]] name = "wasmparser-nostd" -version = "0.100.1" +version = "0.100.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9157cab83003221bfd385833ab587a039f5d6fa7304854042ba358a3b09e0724" +checksum = "d5a015fe95f3504a94bb1462c717aae75253e39b9dd6c3fb1062c934535c64aa" dependencies = [ "indexmap-nostd", ] @@ -1380,9 +1419,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1396,54 +1435,75 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/contracts/soroban/Cargo.toml b/contracts/soroban/Cargo.toml index cddad916..5569a2ac 100644 --- a/contracts/soroban/Cargo.toml +++ b/contracts/soroban/Cargo.toml @@ -1,12 +1,12 @@ [workspace] resolver = "2" members = [ - "contracts/*", - "libs/*" + "contracts/*" ] [workspace.dependencies] -soroban-sdk = "20.5.0" +soroban-sdk = "21.7.4" +soroban-rlp = { git = "http://github.com/icon-project/xcall-multi", branch = "main" } [profile.release] opt-level = "z" diff --git a/contracts/soroban/contracts/intent/Cargo.toml b/contracts/soroban/contracts/intent/Cargo.toml index 0a7b7127..27375e8c 100644 --- a/contracts/soroban/contracts/intent/Cargo.toml +++ b/contracts/soroban/contracts/intent/Cargo.toml @@ -10,7 +10,7 @@ doctest = false [dependencies] soroban-sdk = { workspace = true } -soroban-rlp = { path = "../../libs/soroban-rlp" } +soroban-rlp = { workspace = true } [dev-dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/contracts/soroban/contracts/intent/src/fill.rs b/contracts/soroban/contracts/intent/src/fill.rs index 6ff52d70..1de22dd2 100644 --- a/contracts/soroban/contracts/intent/src/fill.rs +++ b/contracts/soroban/contracts/intent/src/fill.rs @@ -14,7 +14,7 @@ pub fn fill_order( sender.require_auth(); let order_bytes = order.encode(&env); - let order_hash = env.crypto().keccak256(&order_bytes); + let order_hash = helpers::hash_data(&env, &order_bytes); if storage::order_finished(&env, &order_hash) { return Err(ContractError::OrderAlreadyFilled); @@ -50,7 +50,7 @@ pub fn fill_order( pub fn resolve_fill(env: &Env, src_network: String, fill: OrderFill) -> Result<(), ContractError> { let order = storage::get_order(&env, fill.id())?; - if order.get_hash(&env) != env.crypto().keccak256(&fill.order_bytes()) { + if order.get_hash(&env) != helpers::hash_data(&env, &fill.order_bytes()) { return Err(ContractError::OrderMismatched); } diff --git a/contracts/soroban/contracts/intent/src/helpers.rs b/contracts/soroban/contracts/intent/src/helpers.rs index a2f55722..427a85a1 100644 --- a/contracts/soroban/contracts/intent/src/helpers.rs +++ b/contracts/soroban/contracts/intent/src/helpers.rs @@ -1,4 +1,4 @@ -use soroban_sdk::{token, Address, Env}; +use soroban_sdk::{token, Address, Bytes, BytesN, Env}; use crate::{error::ContractError, storage}; @@ -20,3 +20,7 @@ pub fn transfer_token(env: &Env, token: &Address, from: &Address, to: &Address, let token_client = token::Client::new(&env, &token); token_client.transfer(&from, &to, &(amount as i128)); } + +pub fn hash_data(e: &Env, data: &Bytes) -> BytesN<32> { + e.crypto().keccak256(data).to_bytes() +} diff --git a/contracts/soroban/contracts/intent/src/test/cancel.rs b/contracts/soroban/contracts/intent/src/test/cancel.rs index 7f61de53..52944169 100644 --- a/contracts/soroban/contracts/intent/src/test/cancel.rs +++ b/contracts/soroban/contracts/intent/src/test/cancel.rs @@ -9,7 +9,7 @@ use super::setup::TestContext; use crate::{ contract::IntentClient, event::{Message, OrderCancelled}, - storage, + helpers, storage, types::{Cancel, MessageType, OrderFill, OrderMessage}, }; @@ -125,7 +125,7 @@ fn test_resolve_cancel_in_same_source_and_destination_chain() { ctx.env.as_contract(&ctx.contract, || { let order_bytes = order.encode(&ctx.env); - let order_hash = ctx.env.crypto().keccak256(&order_bytes); + let order_hash = helpers::hash_data(&ctx.env, &order_bytes); let filled_order = storage::order_finished(&ctx.env, &order_hash); assert_eq!(filled_order, true); }); @@ -168,7 +168,7 @@ fn test_resolve_cancel_with_invalid_network_id() { let receipt = client.get_receipt(&src_network, &conn_sn); assert_eq!(receipt, true); - let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env)); + let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env)); ctx.env.as_contract(&ctx.contract, || { let filled_order = storage::order_finished(&ctx.env, &order_hash); assert_eq!(filled_order, true) @@ -182,7 +182,7 @@ fn test_resolve_cancel_for_already_filled_order() { ctx.init_context(&client); let order = ctx.get_dummy_swap(ctx.dst_nid.clone()); - let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env)); + let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env)); ctx.env.as_contract(&ctx.contract, || { storage::store_finished_order(&ctx.env, &order_hash); }); diff --git a/contracts/soroban/contracts/intent/src/test/fill.rs b/contracts/soroban/contracts/intent/src/test/fill.rs index 9c0ca721..8ee9a6c9 100644 --- a/contracts/soroban/contracts/intent/src/test/fill.rs +++ b/contracts/soroban/contracts/intent/src/test/fill.rs @@ -9,7 +9,7 @@ use super::setup::TestContext; use crate::{ contract::IntentClient, event::{Message, OrderFilled}, - storage, + helpers, storage, types::{MessageType, OrderFill, OrderMessage}, }; @@ -24,7 +24,7 @@ fn test_fill_for_already_finished_order() { ctx.env.as_contract(&ctx.contract, || { let order_bytes = order.encode(&ctx.env); - let order_hash = ctx.env.crypto().keccak256(&order_bytes); + let order_hash = helpers::hash_data(&ctx.env, &order_bytes); storage::store_finished_order(&ctx.env, &order_hash); }); @@ -126,7 +126,7 @@ fn test_fill_order() { ] ); - let order_hash = ctx.env.crypto().keccak256(&order.encode(&ctx.env)); + let order_hash = helpers::hash_data(&ctx.env, &order.encode(&ctx.env)); let finished_order = client.get_finished_order(&order_hash); assert_eq!(finished_order, true); diff --git a/contracts/soroban/contracts/intent/src/test/types.rs b/contracts/soroban/contracts/intent/src/test/types.rs index 01c3ec67..ed67453f 100644 --- a/contracts/soroban/contracts/intent/src/test/types.rs +++ b/contracts/soroban/contracts/intent/src/test/types.rs @@ -78,7 +78,7 @@ fn test_swap_order_decode_1() { 900, Bytes::new(&env), ); - let expected = bytes!(&env, 0xf900a601963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378203e89a307839316134373238623531373438346630663631306465376282038480); + let expected = bytes!(&env, 0xf8a601963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378203e89a307839316134373238623531373438346630663631306465376282038480); assert_eq!(swap_order.encode(&env), expected) } @@ -99,6 +99,6 @@ fn test_swap_order_decode_2() { 900 * 10_u128.pow(7), bytes!(&env, 0x6c449988e2f33302803c93f8287dc1d8cb33848a), ); - let expected = bytes!(&env, 0xf900c701963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378c033b2e3c9fd0803ce80000009a3078393161343732386235313734383466306636313064653762850218711a00946c449988e2f33302803c93f8287dc1d8cb33848a); + let expected = bytes!(&env, 0xf8c701963078626536343532643464366336316365653937643388457468657265756d87506f6c79676f6e983078336533366564646436356532333932323265376536379c30786432633632313862383735343537613431623666623739363465a43078313433353533343065383537393132313838623766323032643535303232323438378c033b2e3c9fd0803ce80000009a3078393161343732386235313734383466306636313064653762850218711a00946c449988e2f33302803c93f8287dc1d8cb33848a); assert_eq!(swap_order.encode(&env), expected) } diff --git a/contracts/soroban/contracts/intent/src/types/swap_order.rs b/contracts/soroban/contracts/intent/src/types/swap_order.rs index b9da1a40..5d7215a9 100644 --- a/contracts/soroban/contracts/intent/src/types/swap_order.rs +++ b/contracts/soroban/contracts/intent/src/types/swap_order.rs @@ -1,5 +1,5 @@ -use soroban_sdk::{contracttype, vec, Bytes, BytesN, Env, String, Vec}; use soroban_rlp::{decoder, encoder}; +use soroban_sdk::{contracttype, vec, Bytes, BytesN, Env, String, Vec}; #[contracttype] #[derive(Debug, Clone, PartialEq)] @@ -110,7 +110,7 @@ impl SwapOrder { } pub fn get_hash(&self, e: &Env) -> BytesN<32> { - e.crypto().keccak256(&self.encode(&e)) + e.crypto().keccak256(&self.encode(&e)).to_bytes() } pub fn encode(&self, e: &Env) -> Bytes { diff --git a/contracts/soroban/libs/soroban-rlp/Cargo.toml b/contracts/soroban/libs/soroban-rlp/Cargo.toml deleted file mode 100644 index de8642c8..00000000 --- a/contracts/soroban/libs/soroban-rlp/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "soroban-rlp" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -crate-type = ["cdylib", "rlib"] -doctest = false - -[dependencies] -soroban-sdk = { workspace = true } diff --git a/contracts/soroban/libs/soroban-rlp/src/decoder.rs b/contracts/soroban/libs/soroban-rlp/src/decoder.rs deleted file mode 100644 index 59f933f5..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/decoder.rs +++ /dev/null @@ -1,160 +0,0 @@ -use super::utils::*; -use soroban_sdk::{vec, Bytes, Env, String, Vec}; - -pub fn decode(env: &Env, bytes: Bytes) -> Bytes { - assert!(bytes.len() > 0); - - let rlp_byte = bytes.get(0).unwrap(); - - #[allow(unused_comparisons)] - let decoded = if rlp_byte == 0x80 || rlp_byte == 0xc0 { - Bytes::new(&env) - } else if rlp_byte < 0x80 { - bytes - } else if rlp_byte < 0xb8 { - let data_len = rlp_byte - 0x80; - slice_vector(&env, bytes, 1, data_len as u64) - } else if rlp_byte > 0xb7 && rlp_byte < 0xc0 { - let data_bytes_len = rlp_byte - 0xb7; - let len_bytes = slice_vector(&env, bytes.clone(), 1, data_bytes_len as u64); - - let data_len = bytes_to_u64(len_bytes.clone()); - let data_start = len_bytes.len() + 1; - - slice_vector(&env, bytes, data_start as u64, data_len) - } else if rlp_byte > 0xc0 && rlp_byte <= 0xf7 { - let data_len = rlp_byte - 0xc0; - slice_vector(&env, bytes, 1, data_len as u64) - } else if rlp_byte > 0xf7 && rlp_byte <= 0xff { - let data_bytes_len = rlp_byte - 0xf7; - let len_bytes = slice_vector(&env, bytes.clone(), 1, data_bytes_len as u64); - - let data_len = bytes_to_u64(len_bytes.clone()); - let data_start = len_bytes.len() + 1; - - slice_vector(&env, bytes, data_start as u64, data_len) - } else { - panic!("invalid rlp byte length") - }; - - decoded -} - -pub fn decode_list(env: &Env, list: Bytes) -> Vec { - let data_len = decode_length(&env, list.clone(), 0xc0); - let start = list.len() as u64 - data_len; - let encoded = slice_vector(&env, list, start, data_len); - - let mut decoded: Vec = Vec::new(&env); - let mut i = 0; - while i < encoded.len() { - let byte = encoded.get(i).unwrap(); - - #[allow(unused_comparisons)] - if byte == 0x80 || byte == 0xc0 { - decoded.push_back(Bytes::new(&env)); - i = i + 1; - } else if byte < 0x80 { - let mut singleton = Bytes::new(&env); - singleton.push_back(byte); - decoded.push_back(singleton); - i = i + 1; - } else if byte > 0x80 && byte < 0xB8 { - let len = (byte - 0x80) as u64; - decoded.push_back(slice_vector(&env, encoded.clone(), i as u64 + 1, len)); - i = i + (len as u32 + 1); - } else if byte > 0xc0 && byte < 0xf7 { - let len = (byte - 0xc0) as u64; - decoded.push_back(slice_vector(&env, encoded.clone(), i as u64, len + 1)); - i = i + (len as u32 + 1) - } else if byte > 0xb7 && byte < 0xc0 { - let data_bytes_len = (byte - 0xb7) as u64; - let len_bytes = slice_vector(&env, encoded.clone(), i as u64 + 1, data_bytes_len); - let len = bytes_to_u64(len_bytes); - decoded.push_back(slice_vector( - &env, - encoded.clone(), - i as u64 + data_bytes_len + 1, - len, - )); - i = i + (data_bytes_len + len + 1) as u32 - } else if byte > 0xf7 && byte <= 0xff { - let data_bytes_len = (byte - 0xf7) as u64; - let len_bytes = slice_vector(&env, encoded.clone(), i as u64 + 1, data_bytes_len); - let len = bytes_to_u64(len_bytes); - if byte == 0xf8 && len == 0 { - decoded.push_back(Bytes::new(&env)); - } else { - decoded.push_back(slice_vector( - &env, - encoded.clone(), - i as u64, - data_bytes_len + len + 1, - )); - } - i = i + (data_bytes_len + len + 1) as u32 - } else { - panic!("invalid rlp byte length") - } - } - decoded -} - -pub fn decode_length(env: &Env, bytes: Bytes, offset: u8) -> u64 { - let bytes_len = bytes.len(); - - let len = if bytes_len == 0 { - 0 - } else if bytes_len < 56 { - (bytes.get(0).unwrap() - offset) as u64 - } else { - let len = bytes.get(0).unwrap() - offset - 55; - let len_bytes = slice_vector(env, bytes, 1, len as u64); - bytes_to_u64(len_bytes) - }; - - len -} - -pub fn decode_bool(bytes: Bytes) -> bool { - if bytes.len() > 0 && bytes.get(0).unwrap() == 1 { - return true; - } - - false -} - -pub fn decode_u8(env: &Env, bytes: Bytes) -> u8 { - decode(&env, bytes).get(0).unwrap_or(0) -} - -pub fn decode_u32(env: &Env, bytes: Bytes) -> u32 { - let decoded = decode(&env, bytes); - bytes_to_u32(decoded) -} - -pub fn decode_u64(env: &Env, bytes: Bytes) -> u64 { - let decoded = decode(&env, bytes); - bytes_to_u64(decoded) -} - -pub fn decode_u128(env: &Env, bytes: Bytes) -> u128 { - let decoded = decode(&env, bytes); - bytes_to_u128(decoded) -} - -pub fn decode_string(env: &Env, bytes: Bytes) -> String { - let decoded = decode(&env, bytes); - bytes_to_string(&env, decoded) -} - -pub fn decode_strings(env: &Env, bytes: Bytes) -> Vec { - let list = decode_list(&env, bytes); - - let mut strings: Vec = vec![&env]; - for byte in list { - strings.push_back(bytes_to_string(&env, byte)) - } - - strings -} diff --git a/contracts/soroban/libs/soroban-rlp/src/encoder.rs b/contracts/soroban/libs/soroban-rlp/src/encoder.rs deleted file mode 100644 index 97e932ac..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/encoder.rs +++ /dev/null @@ -1,100 +0,0 @@ -use super::utils::*; -use soroban_sdk::{bytes, vec, Bytes, Env, String, Vec}; - -pub fn encode(env: &Env, bytes: Bytes) -> Bytes { - let len = bytes.len(); - - let encoded = if len == 0 { - bytes!(&env, 0x80) - } else if len == 1 && bytes.get(0).unwrap() < 128 { - bytes - } else { - let mut res = encode_length(&env, len as u64, 0x80); - res.append(&bytes); - res - }; - - encoded -} - -pub fn encode_list(env: &Env, list: Vec, raw: bool) -> Bytes { - let mut res = Bytes::new(&env); - if list.len() == 0 { - res.push_back(0xc0); - } else { - for bytes in list { - if raw == true { - res.append(&encode(&env, bytes.clone())) - } else { - res.append(&bytes) - } - } - let len = res.len(); - let mut len_buffer = encode_length(&env, len as u64, 0xc0); - - len_buffer.append(&res); - res = len_buffer - } - res -} - -pub fn encode_length(env: &Env, len: u64, offset: u8) -> Bytes { - let mut len_info = Bytes::new(&env); - - if len < 56 { - let len_u8 = len as u8; - len_info.push_back(len_u8 + offset) - } else { - let mut bytes_length = u64_to_bytes(&env, len); - let rlp_bytes_len = bytes_length.len() as u8; - len_info.push_back(rlp_bytes_len + offset + 55); - len_info.append(&mut bytes_length); - } - - len_info -} - -pub fn encode_bool(env: &Env, value: bool) -> Bytes { - if value == true { - return bytes!(env, 0x01); - } - - bytes!(env, 0x00) -} - -pub fn encode_u8(env: &Env, num: u8) -> Bytes { - let mut bytes = Bytes::new(&env); - bytes.push_back(num); - - encode(&env, bytes) -} - -pub fn encode_u32(env: &Env, num: u32) -> Bytes { - let bytes = u32_to_bytes(&env, num); - encode(&env, bytes) -} - -pub fn encode_u64(env: &Env, num: u64) -> Bytes { - let bytes = u64_to_bytes(&env, num); - encode(&env, bytes) -} - -pub fn encode_u128(env: &Env, num: u128) -> Bytes { - let bytes = u128_to_bytes(&env, num); - encode(&env, bytes) -} - -pub fn encode_string(env: &Env, value: String) -> Bytes { - let bytes = string_to_bytes(&env, value); - encode(&env, bytes) -} - -pub fn encode_strings(env: &Env, values: Vec) -> Bytes { - let mut list: Vec = vec![&env]; - - for value in values { - list.push_back(encode_string(&env, value)); - } - - encode_list(&env, list, false) -} diff --git a/contracts/soroban/libs/soroban-rlp/src/lib.rs b/contracts/soroban/libs/soroban-rlp/src/lib.rs deleted file mode 100644 index c0cc9cc6..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![no_std] - -pub mod decoder; -pub mod encoder; -mod utils; - -#[cfg(test)] -mod test; diff --git a/contracts/soroban/libs/soroban-rlp/src/test.rs b/contracts/soroban/libs/soroban-rlp/src/test.rs deleted file mode 100644 index 017e17e8..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/test.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod decoder; -mod encoder; -mod utils; diff --git a/contracts/soroban/libs/soroban-rlp/src/test/decoder.rs b/contracts/soroban/libs/soroban-rlp/src/test/decoder.rs deleted file mode 100644 index 9dcd860d..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/test/decoder.rs +++ /dev/null @@ -1,104 +0,0 @@ -use soroban_sdk::{bytes, vec, Bytes, Env, String, Vec}; - -use crate::decoder::*; -use crate::encoder; - -#[test] -fn test_decode_u32() { - let env = Env::default(); - - let bytes = bytes!(&env, 0x843548668C); - let decoded = decode_u32(&env, bytes); - assert_eq!(decoded, 893937292); - - let bytes = bytes!(&env, 0x830DA3F1); - let decoded = decode_u32(&env, bytes); - assert_eq!(decoded, 893937) -} - -#[test] -fn test_decode_u64() { - let env = Env::default(); - - let bytes = bytes!(&env, 0x88FFFFFFFFFFFFFFFF); - let decoded = decode_u64(&env, bytes); - assert_eq!(decoded, 18446744073709551615) -} - -#[test] -fn test_decode_u128() { - let env = Env::default(); - - let bytes = bytes!(&env, 0x90FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); - let decoded = decode_u128(&env, bytes); - assert_eq!(decoded, 340282366920938463463374607431768211455) -} - -#[test] -fn test_decode_string_with_less_bytes() { - let env = Env::default(); - - let str = String::from_str(&env, "soroban-rlp"); - let encoded = encoder::encode_string(&env, str.clone()); - let decoded = decode_string(&env, encoded); - assert_eq!(str, decoded) -} - -#[test] -fn test_decode_string_with_longer_bytes() { - let env = Env::default(); - - let str = String::from_str( - &env, - "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", - ); - let encoded = encoder::encode_string(&env, str.clone()); - let decoded = decode_string(&env, encoded); - assert_eq!(str, decoded) -} - -#[test] -fn test_decode_strings() { - let env = Env::default(); - let string_list = vec![ - &env, - String::from_str( - &env, - "Lorem ipsum dolor sit amet, consectetur adipiscing elit", - ), - String::from_str( - &env, - "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ", - ), - ]; - - let encoded = encoder::encode_strings(&env, string_list.clone()); - let decoded = decode_strings(&env, encoded); - - assert_eq!(string_list, decoded) -} - -#[test] -fn test_decode_list() { - let env = Env::default(); - - let str_1 = String::from_str(&env, "Integer quis auctor elit sed vulputate mi sit."); - let str_2 = String::from_str(&env, "Tincidunt nunc pulvinar sapien et ligula"); - let str_3 = String::from_str(&env, "Sed adipiscing diam donec adipiscing tristique"); - - let mut list: Vec = vec![&env]; - list.push_back(encoder::encode_u8(&env, 245)); - list.push_back(encoder::encode_u128( - &env, - 180593171625979951495805181356371083263, - )); - list.push_back(encoder::encode_u32(&env, 24196199)); - list.push_back(encoder::encode_u64(&env, 103921887687475199)); - list.push_back(encoder::encode_strings(&env, vec![&env, str_1, str_2])); - list.push_back(encoder::encode_string(&env, str_3)); - - let encoded = encoder::encode_list(&env, list.clone(), true); - let decoded = decode_list(&env, encoded); - - assert_eq!(list, decoded) -} diff --git a/contracts/soroban/libs/soroban-rlp/src/test/encoder.rs b/contracts/soroban/libs/soroban-rlp/src/test/encoder.rs deleted file mode 100644 index 09e85ef8..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/test/encoder.rs +++ /dev/null @@ -1,226 +0,0 @@ -use soroban_sdk::{bytes, vec, Bytes, Env, String, Vec}; - -use crate::encoder::*; -use crate::utils::*; - -#[test] -fn test_encode_u8() { - let env = Env::default(); - - let encoded = encode_u8(&env, 100); - assert_eq!(encoded, bytes!(&env, 0x64)) -} - -#[test] -fn test_encode_u32() { - let env = Env::default(); - - let encoded = encode_u32(&env, 2000022458); - assert_eq!(encoded, bytes!(&env, 0x847735EBBA)); -} - -#[test] -fn test_encode_u64() { - let env = Env::default(); - - let encoded = encode_u64(&env, 1999999999999999999); - assert_eq!(encoded, bytes!(&env, 0x881BC16D674EC7FFFF)); - - let encoded = encode_u64(&env, 199999999); - assert_eq!(encoded, bytes!(&env, 0x840BEBC1FF)) -} - -#[test] -fn test_encode_u128() { - let env = Env::default(); - - let encoded = encode_u128(&env, 199999999999999999999999999999999999999); - assert_eq!( - encoded, - bytes!(&env, 0x910096769950B50D88F41314447FFFFFFFFF) - ) -} - -#[test] -fn test_encode_string_with_smaller_bytes_length() { - let env = Env::default(); - - let str = "soroban-rlp"; - let encoded = encode_string(&env, String::from_str(&env, str)); - let str_bytes_slice = b"soroban-rlp"; - - let expected_rlp_byte = 139; - let mut expected_bytes = Bytes::new(&env); - expected_bytes.push_back(expected_rlp_byte); - expected_bytes.extend_from_slice(str_bytes_slice); - - assert_eq!(encoded, expected_bytes) -} - -#[test] -fn test_encode_string_with_larger_bytes_length() { - let env = Env::default(); - - let encoded = encode_string(&env, String::from_str(&env, "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s")); - - let expected_rlp_byte = 185; - let str_bytes_slice = b"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"; - let mut expected_bytes = Bytes::new(&env); - expected_bytes.push_back(expected_rlp_byte); - expected_bytes.push_back(0); - expected_bytes.push_back(0x97); - expected_bytes.extend_from_slice(str_bytes_slice); - - assert_eq!(encoded, expected_bytes) -} - -#[test] -fn test_encode_strings() { - let env = Env::default(); - let strings = vec![ - &env, - String::from_str(&env, "alice"), - String::from_str(&env, "bob"), - ]; - - let encoded = encode_strings(&env, strings); - - let mut expected_encode = Bytes::new(&env); - expected_encode.push_back(0xc0 + 10); - expected_encode.push_back(0x85); - expected_encode.extend_from_slice(b"alice"); - expected_encode.push_back(0x83); - expected_encode.extend_from_slice(b"bob"); - - assert_eq!(encoded, expected_encode); - assert_eq!(encoded.len(), 11); -} - -#[test] -fn test_encode_strings_with_longer_bytes() { - let env = Env::default(); - let strings = vec![ - &env, - String::from_str(&env, "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."), - String::from_str(&env, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."), - String::from_str(&env, "Egestas maecenas pharetra convallis posuere morbi. Velit laoreet id donec ultrices tincidunt arcu non sodales neque.") - ]; - - let encoded = encode_strings(&env, strings); - - let rlp_byte = 0xf7 + 2; - let mut expected_encode = Bytes::new(&env); - - // rlp byte and data length bytes - expected_encode.push_back(rlp_byte); - expected_encode.extend_from_array(&[0x01, 0x71]); - - // strings - let string_rlp_byte = 0xb7 + 1; - let string_len_byte = 0x7c; - expected_encode.extend_from_array(&[string_rlp_byte, string_len_byte]); - expected_encode.extend_from_slice(b"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."); - - let string_len_byte = 0x7b; - expected_encode.extend_from_array(&[string_rlp_byte, string_len_byte]); - expected_encode.extend_from_slice(b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); - - let string_len_byte = 0x74; - expected_encode.extend_from_array(&[string_rlp_byte, string_len_byte]); - expected_encode.extend_from_slice(b"Egestas maecenas pharetra convallis posuere morbi. Velit laoreet id donec ultrices tincidunt arcu non sodales neque."); - - assert_eq!(encoded, expected_encode); - // assert_eq!(encoded.len(), 376); -} - -#[test] -fn test_encode_list_empty() { - let env = Env::default(); - - let list: Vec = vec![&env]; - let encoded = encode_list(&env, list, true); - - assert_eq!(encoded, bytes!(&env, 0xc0)) -} - -#[test] -fn test_encode_list_with_smaller_bytes() { - let env = Env::default(); - - let mut list: Vec = vec![&env]; - let short_str = String::from_str(&env, "soroban-rlp"); - list.push_back(u32_to_bytes(&env, 4294967295)); - list.push_back(string_to_bytes(&env, short_str.clone())); - - let encoded = encode_list(&env, list, true); - - let expected_rlp_byte = 0xc0 + 18; - let mut expected_bytes = Bytes::new(&env); - expected_bytes.push_back(expected_rlp_byte); - expected_bytes.append(&encode_u32(&env, 4294967295)); - expected_bytes.append(&encode_string(&env, short_str)); - - assert_eq!(encoded, expected_bytes) -} - -#[test] -fn test_encode_list_with_longer_bytes() { - let env = Env::default(); - - let str_1 = String::from_str(&env, "Integer quis auctor elit sed vulputate mi sit."); - let str_2 = String::from_str(&env, "Tincidunt nunc pulvinar sapien et ligula"); - let str_3 = String::from_str(&env, "Sed adipiscing diam donec adipiscing tristique"); - - let mut list: Vec = vec![&env]; - list.push_back(encode_u8(&env, 245)); - list.push_back(encode_u32(&env, 24196199)); - list.push_back(encode_u64(&env, 103921887687475199)); - list.push_back(encode_u128(&env, 180593171625979951495805181356371083263)); - list.push_back(encode_strings(&env, vec![&env, str_1, str_2])); - list.push_back(encode_string(&env, str_3)); - - let encoded = encode_list(&env, list, false); - - let mut expected_bytes = Bytes::new(&env); - - // rlp and data len bytes - let rlp_byte = 0xf7 + 2; - let data_len_byte = 0xAA + 1; - expected_bytes.extend_from_array(&[rlp_byte, 0, data_len_byte]); - - // u8 - expected_bytes.extend_from_array(&[0x81, 0xF5]); - - // u32 - expected_bytes.extend_from_array(&[0x84, 0x01, 0x71, 0x34, 0x67]); - - // u64 - expected_bytes.extend_from_array(&[0x88, 0x01, 0x71, 0x34, 0x67, 0xff, 0xff, 0xff, 0xff]); - - // u128 - expected_bytes.extend_from_array(&[ - 0x91, 0x00, 0x87, 0xdc, 0xfa, 0xcd, 0x87, 0x98, 0x27, 0x36, 0xcd, 0xef, 0xcd, 0xef, 0xff, - 0xff, 0xff, 0xff, - ]); - - // strings - let array_rlp_byte = 0xf7 + 1; - let total_rlp_bytes_in_array = 2; - let strings_len_byte = 0x56 + total_rlp_bytes_in_array; - expected_bytes.extend_from_array(&[array_rlp_byte, strings_len_byte]); - - let rlp_byte = 0x80 + 46; - expected_bytes.push_back(rlp_byte); - expected_bytes.extend_from_slice(b"Integer quis auctor elit sed vulputate mi sit."); - - let rlp_byte = 0x80 + 40; - expected_bytes.push_back(rlp_byte); - expected_bytes.extend_from_slice(b"Tincidunt nunc pulvinar sapien et ligula"); - - // string - let rlp_byte = 0x80 + 46; - expected_bytes.push_back(rlp_byte); - expected_bytes.extend_from_slice(b"Sed adipiscing diam donec adipiscing tristique"); - - assert_eq!(encoded, expected_bytes); -} diff --git a/contracts/soroban/libs/soroban-rlp/src/test/utils.rs b/contracts/soroban/libs/soroban-rlp/src/test/utils.rs deleted file mode 100644 index 4d1f8b65..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/test/utils.rs +++ /dev/null @@ -1,45 +0,0 @@ -use crate::utils::*; -use soroban_sdk::{bytes, Env}; - -#[test] -fn test_u32_to_bytes() { - let env = Env::default(); - - let num = 0x12345678; - let bytes = u32_to_bytes(&env, num); - let expected_num = bytes_to_u32(bytes); - - assert_eq!(num, expected_num) -} - -#[test] -fn test_u64_to_bytes() { - let env = Env::default(); - - let num: u64 = 18446744073709551615; - let bytes = u64_to_bytes(&env, num); - let expected_num = bytes_to_u64(bytes); - - assert_eq!(num, expected_num) -} - -#[test] -fn test_u128_to_bytes() { - let env = Env::default(); - - let num: u128 = 340282366920938463463374607431768211455; - let bytes = u128_to_bytes(&env, num); - let expected_num = bytes_to_u128(bytes); - - assert_eq!(num, expected_num) -} - -#[test] -fn test_slice_vector() { - let env = Env::default(); - - let bytes = u128_to_bytes(&env, 1844674407); - let slice = slice_vector(&env, bytes.clone(), 1, 2); - - assert_eq!(slice, bytes!(&env, 0xF37F)); -} diff --git a/contracts/soroban/libs/soroban-rlp/src/utils.rs b/contracts/soroban/libs/soroban-rlp/src/utils.rs deleted file mode 100644 index ecce1d9c..00000000 --- a/contracts/soroban/libs/soroban-rlp/src/utils.rs +++ /dev/null @@ -1,107 +0,0 @@ -use soroban_sdk::{ - bytes, - xdr::{FromXdr, ToXdr}, - Bytes, Env, String, -}; - -pub fn u32_to_bytes(env: &Env, number: u32) -> Bytes { - let bytes = Bytes::from_slice(&env, &number.to_be_bytes()); - to_signed_bytes(&env, bytes) -} - -pub fn u64_to_bytes(env: &Env, number: u64) -> Bytes { - let bytes = Bytes::from_slice(&env, &number.to_be_bytes()); - to_signed_bytes(&env, bytes) -} - -pub fn u128_to_bytes(env: &Env, number: u128) -> Bytes { - let bytes = Bytes::from_slice(&env, &number.to_be_bytes()); - to_signed_bytes(&env, bytes) -} - -pub fn to_signed_bytes(env: &Env, bytes: Bytes) -> Bytes { - let truncated = truncate_zeros(&env, bytes); - let first_byte = truncated.get(0).unwrap_or(0); - - if first_byte >= 128 { - let mut prefix = bytes!(&env, 0x00); - prefix.append(&truncated); - prefix - } else { - truncated - } -} - -pub fn truncate_zeros(env: &Env, bytes: Bytes) -> Bytes { - let mut i = 0; - let mut started = false; - let mut result = Bytes::new(&env); - - while i < bytes.len() { - let val = bytes.get(i).unwrap(); - if val > 0 || started { - started = true; - result.push_back(val); - } - i = i + 1; - } - - result -} - -pub fn bytes_to_u32(bytes: Bytes) -> u32 { - let mut num = 0; - for byte in bytes.iter() { - num = (num << 8) | byte as u32; - } - num -} - -pub fn bytes_to_u64(bytes: Bytes) -> u64 { - let mut num = 0; - for byte in bytes.iter() { - num = (num << 8) | byte as u64; - } - num -} - -pub fn bytes_to_u128(bytes: Bytes) -> u128 { - let mut num = 0; - for byte in bytes.iter() { - num = (num << 8) | byte as u128 - } - num -} - -pub fn slice_vector(env: &Env, arr: Bytes, start: u64, length: u64) -> Bytes { - let mut sliced = Bytes::new(&env); - let mut start = start; - let end = start + length; - - while start < end { - let item = arr.get(start as u32).unwrap(); - sliced.push_back(item); - start += 1; - } - sliced -} - -pub fn string_to_bytes(env: &Env, value: String) -> Bytes { - let mut start_index = 8; - let end_index = start_index + value.len(); - let string_xdr = value.to_xdr(&env); - - let mut bytes = Bytes::new(&env); - while start_index < end_index { - bytes.push_back(string_xdr.get(start_index).unwrap()); - start_index += 1; - } - bytes -} - -pub fn bytes_to_string(env: &Env, bytes: Bytes) -> String { - let mut bytes_xdr = bytes.to_xdr(&env); - bytes_xdr.set(3, 14); - - String::from_xdr(&env, &bytes_xdr).unwrap() -}