From 4a0e3f624f42816cb4ca687d3ff9bba8e1a6bf19 Mon Sep 17 00:00:00 2001 From: Cyrill Leutwiler Date: Wed, 18 Dec 2024 08:25:03 +0100 Subject: [PATCH] [pallet-revive] implement the call data copy API (#6880) This PR implements the call data copy API by adjusting the input method. Closes #6770 --------- Signed-off-by: xermicus Co-authored-by: command-bot <> --- prdoc/pr_6880.prdoc | 14 +++++ .../fixtures/contracts/call_data_copy.rs | 53 +++++++++++++++++ .../fixtures/contracts/common/src/lib.rs | 5 +- .../rpc/examples/js/pvm/ErrorTester.polkavm | Bin 8919 -> 7289 bytes .../rpc/examples/js/pvm/EventExample.polkavm | Bin 4104 -> 2631 bytes .../rpc/examples/js/pvm/Flipper.polkavm | Bin 1842 -> 1754 bytes .../rpc/examples/js/pvm/FlipperCaller.polkavm | Bin 5803 -> 4723 bytes .../rpc/examples/js/pvm/PiggyBank.polkavm | Bin 6470 -> 5269 bytes .../frame/revive/src/benchmarking/mod.rs | 37 +++++++++--- substrate/frame/revive/src/tests.rs | 16 +++++ substrate/frame/revive/src/wasm/runtime.rs | 56 ++++++++++++++---- substrate/frame/revive/src/weights.rs | 35 ++++++++--- substrate/frame/revive/uapi/src/flags.rs | 2 +- substrate/frame/revive/uapi/src/host.rs | 18 ++++-- .../frame/revive/uapi/src/host/riscv64.rs | 15 ++--- 15 files changed, 210 insertions(+), 41 deletions(-) create mode 100644 prdoc/pr_6880.prdoc create mode 100644 substrate/frame/revive/fixtures/contracts/call_data_copy.rs diff --git a/prdoc/pr_6880.prdoc b/prdoc/pr_6880.prdoc new file mode 100644 index 000000000000..9d59382f0e0b --- /dev/null +++ b/prdoc/pr_6880.prdoc @@ -0,0 +1,14 @@ +title: '[pallet-revive] implement the call data copy API' +doc: +- audience: Runtime Dev + description: |- + This PR implements the call data copy API by adjusting the input method. + + Closes #6770 +crates: +- name: pallet-revive-fixtures + bump: major +- name: pallet-revive + bump: major +- name: pallet-revive-uapi + bump: major \ No newline at end of file diff --git a/substrate/frame/revive/fixtures/contracts/call_data_copy.rs b/substrate/frame/revive/fixtures/contracts/call_data_copy.rs new file mode 100644 index 000000000000..ccf1664058e8 --- /dev/null +++ b/substrate/frame/revive/fixtures/contracts/call_data_copy.rs @@ -0,0 +1,53 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Expects a call data of [0xFF; 32] and executes the test vectors from +//! [https://www.evm.codes/?fork=cancun#37] and some additional tests. + +#![no_std] +#![no_main] + +extern crate common; +use uapi::{HostFn, HostFnImpl as api}; + +const TEST_DATA: [u8; 32] = [ + 255, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +]; + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn deploy() {} + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn call() { + let mut buf = [0; 32]; + + api::call_data_copy(&mut &mut buf[..], 0); + assert_eq!(buf, [255; 32]); + + api::call_data_copy(&mut &mut buf[..8], 31); + assert_eq!(buf, TEST_DATA); + + api::call_data_copy(&mut &mut buf[..], 32); + assert_eq!(buf, [0; 32]); + + let mut buf = [255; 32]; + api::call_data_copy(&mut &mut buf[..], u32::MAX); + assert_eq!(buf, [0; 32]); +} diff --git a/substrate/frame/revive/fixtures/contracts/common/src/lib.rs b/substrate/frame/revive/fixtures/contracts/common/src/lib.rs index abfba282bec1..1666cdf85ede 100644 --- a/substrate/frame/revive/fixtures/contracts/common/src/lib.rs +++ b/substrate/frame/revive/fixtures/contracts/common/src/lib.rs @@ -121,8 +121,9 @@ macro_rules! input { // e.g input!(buffer, 512, var1: u32, var2: [u8], ); ($buffer:ident, $size:expr, $($rest:tt)*) => { let mut $buffer = [0u8; $size]; - let $buffer = &mut &mut $buffer[..]; - $crate::api::input($buffer); + let input_size = $crate::u64_output!($crate::api::call_data_size,); + let $buffer = &mut &mut $buffer[..$size.min(input_size as usize)]; + $crate::api::call_data_copy($buffer, 0); input!(@inner $buffer, 0, $($rest)*); }; diff --git a/substrate/frame/revive/rpc/examples/js/pvm/ErrorTester.polkavm b/substrate/frame/revive/rpc/examples/js/pvm/ErrorTester.polkavm index ffdbbe2f9c4b52b7a37a159bc88e2bdac706c561..af60be273d74d130967cd91c903ef85de1bf69bd 100644 GIT binary patch literal 7289 zcmc&&4R9OBb-p_sum|jc*aLrVZ%IiIe6k=l{zY<)oDanaY#9IHHsQhq|wr*3w83~mlWPo z28H*nhjIs$Iw&b9ZBQO+@9Nsz(cas>`Jo*<`!eXT|4@H&z`tT8m{XU_6T`lObCnhVyoziej_>=0R>eK2QYFY3z!QTe&Ec=%-U#Ke788XNzvRRwcV&SL5 zjpf_RpQ)Ivc&FlLm20Yk^e*}tn(8lmjL0YyxK9oUg80dOcc+IHY456V-|RhiK|?@B z&+%TMKkqn)-$tyQ_fs){+4bzyBbyjzr!toVpDx&%+ zUKB!~lhGhd?<0XX-$N*AcM_>@P=GmPMfNvo0i{BakP-xa1P{#Q)fVN|Gazrs$aW|Q z%FxbdDf`BIAtVc;1IUW9Uls^-IhydEMdn4Ta!$0WE{IO0AOT3ryA1ciD4(}KDEncb zvH~bAZ`N|C7~oCI8!qnF$`G*##68q=dr<0(h_ccoYGUWT;%yBVpC0}8E~vlpi)ZA` zKGa~)jSqe^fExByKVwd-p@x5ib}6_Bm?B;eF-5#SWZzZoPAZChpU~w~Y6%WFsfrih zMQBpB9U`{HhK07+ekeI%H&V{@AL8d^?FFFG9snDptDXeueMRYDtk@k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zYp>jM!JDhOY$P=-W~&lzMN`99FX_BpdGNCArOteF?YEt4O4+-(VT^EXu6k~-KZytD V%})b=$2aO0=DrCNDJ{O0`#(LIA`$=q diff --git a/substrate/frame/revive/rpc/examples/js/pvm/EventExample.polkavm b/substrate/frame/revive/rpc/examples/js/pvm/EventExample.polkavm index 4b013b35852e668fd21ef7ce1dbd61936d7433bd..67f02042c784cdc354e1b2507ecbe67ab1f59050 100644 GIT binary patch literal 2631 zcmcIlUu+yl8K2!-@9h1ty>~v}jwg=2u{Lm*HspxX#w|r0maEO_5ul9iT`>Y9TL1LNv55eL?|VEL8DSP=zR@&7b4j zb)7sA@y6=DnVXsK`+fgsM#r8;=&1nmJ`SVbOrZ^w^2O6eK0l+DW)AOLd;Lu8-471= z9{Tc|Cr?B^KG^>AkA|YS`v(V~tt4jtAuOJeT-gqwUZ6cdNuaL+rGa#yBh&f(B%EAh4TGXerEdU{nebcV7Mz|_NY;qnX~36jiPaEe$JTAPtF?i$7het8S|6Y^Uoij zpFW&7Jiy{~{fyf6 zy~X{W`!i?pOMH!glmC#HeUJMpzP-X5!cAeH_%(4{+z?Cn@3=?WC1uMU3$lPa178;) zM%=zrj~R7|uk=Ssn_oEy8vy}#p@0-ee8P#wFw9v;z$wHV6*##6uM3gNG3%6SudCK~ zRr{K1yb>(@I$*uRRj(zks)@=$>>n}8{_H|Hc-pLT=1)2KYWBUp%l~Y96#EZ6_@o#6 zDSxRIHk!fUHS=Q2SPjYV^Xsin|Hoa(3~%W2px&L-V{x-P6$x)fikyH2NtF4$ttp&D zJg-s?3^%tx0S>RF^`lI8?!% z_!|OV1b9&noCHl7mXrC?A_5FS68t0Kfb<07vD7Z$DdYnrF}%$m$^w6nfSE~vu?_ZJ zl#VCvc47f>CZv)R`~s5U$PBA3UA}?z?hlY2yN=B6O$1SLy@Yt^IVa%G4=cg~pL2~F z;lf99myuOci(bXQ{i6^6)>rxVwtIyKxmS3wdylZ3!<7ywLVC--$mKg2_j}>wtDcGX zOpm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+A#94K0P^_PE_xpUHeN4v>pgsQzNCVxnTy42^EggZ{>0 zH4+}r)Yrp1{3{yl(fSGy6ozU~wj7UD+#iH-d%}jn^+Mn#L?N&Z;qiZwx-LwVQpKJ# z6SIx=6M(9ys~^t51o&rS^%>B{4vl6ls}Gk~gtf?hbF#BfRD{Y~S|9{3f!DS*OoYE( WU$2eYyTak`gV?&KTN=vCrGEkjk_2@C diff --git a/substrate/frame/revive/rpc/examples/js/pvm/Flipper.polkavm b/substrate/frame/revive/rpc/examples/js/pvm/Flipper.polkavm index 7fb299e464dd75177e916f6631f6fa7dd7cf3ea9..ebb06b6949e3856a1e367e99c1c7481fdc32e6ae 100644 GIT binary patch literal 1754 zcmbVMUuYaf7@wV++nK#wb9$L9 zB2V&8=L)C1fvJhy$;n}FV!|5=$MM;NB;Y-pk%zqT!q|-bQF8*HHS=g5okOcAA$3aq z(x~*Yw1{uu!O-WSW-?Bi!kKV3Y|Yf4Q3;Jj-XIZ#q!-U0^p+W3*qbPB9C{T35kebK z1SI43>7+*CZA}xZBkV1}huWwC`SH89dcbac$=2HZ#!MozTl|jl7#;IN$ zmr@#45$=|C6rwVfRienM{BVcmmPTlXFkM!eyG7{@L>Q193-t$&zTlBX_%v*(dd=Cs zI!Ff*_EQ_Mc{|Uo_uUkCQ>vR{F2%)O8h1vyb6s^-xl>`zT6CF3uhZxPjnTIVodbGV zjr{hQQq#$+xHyM^gD|4>#v?3=FlD=7KPUuD;rKuK(XS!DiBQMqkVqgNu+)F?I7SJQ zd~jAG3PCD-^5goJt$vT}#_y1=eS`eQ4Fo3DR3?hR^$-&URFVjIRFfKEFs(_g>a<6A z)qz7ibPe01D$eVK^-6Im|2pli{PN?sM=|X_@@x6vy$2SIfFuX4~ech^#YqUiDMIgZ)p%k%ZUqEcP=**&?(z1cXizQnyWn z`X)d4i_%9@U0!{@I8ru zKf=a-X$Dj8?3Z)J96A-c|@ z6=mfz^x){C9=)ZET-IS6V-FE7!dg2IZ6t;_Xz%+;JXE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L@g)UwiYy?4d$zwPV2E|n=H(x+U)Rj-hJFB>L%ioe|Z zW|<><-j06~4g~hRcK`A#=QuN{*$s2ZZa4$T0cH@d&LEd&^$fDKIb_x3ki}-uBSf#d zdEJVjgoNal9LhQTZ!391aZ8!ig>nw_}U1TN|~?9?;5 zlhG#_tz)#7QO0NuqZ*?sqm zY1On^%ss-k;XAD~*w7jh!Rr5!{as|stUGW279i~$(ETq`l%3%^WYZmw$}xks^iUU2 z?IfuBn2L`X%T`8hWy)3@Tj_VxfTG|lzP5ieiv_;3G%#BY7>~`NU>249Y4Ui1ChIe6 zdQ2^5s*z1+lwDEb5(%%>rYpiftP|2)`aiCCu)$Bp(}LW%2upw7uvASK5;Xi-Uo9&X3f5ymP-VFBUlyZwk*~wfk k7YjD#Uynu`8}oX;H`r*zp^RnOc(!d{X!p7HHXWls01Lvaxc~qF diff --git a/substrate/frame/revive/rpc/examples/js/pvm/FlipperCaller.polkavm b/substrate/frame/revive/rpc/examples/js/pvm/FlipperCaller.polkavm index f112ca275df4ba33a26faa9c69efdd8d5292a98e..56ae81c7e5b06c34b302d3f1158ae48c4ec29092 100644 GIT binary patch literal 4723 zcmcInYj7LY6~6oM-j#M`trSaMHV#(Y^^**^CA6kMN4Ns-%8p0K#ua<3iJe$z*ES?^ z9##@Mb*FAEr#up2upQ7eO&$E0wxpEQA%TuN?KGjl4AaT9^hX)D(+B(_ffk&1&#vt_ zlrT`H)#&VM@7{aPJ?DJixks_KbqH)wtnlj zO}!oIRBvkA_TC4V*I)f?Pu-g8=vluoxD{4e4?M7aTgQf;l(WJfS=6(mqi1_+{kGnY z2e;mz>g`Q+7WnALRMy_WV>fV}sm(o`c5?gr*3gfwO``!cgyv8srBm(H7Ai@P(J#~Q z&?}hh**3PQprfFayOH}dm&7H!#d}?=T#vf;yME@XcOP&+>wa6P634|~i0eGhd4BK7 z6do)5TVbL12Jg+@_|C#z5{td=J6ShE)J=PCO^x#OV5z@v?luS_uNBDj%^Fgj5vVnSRc0X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Nh(+#FjhepD~gh-4prf#BoVgPn1Y>g2cK@rS#Kh4K)x5 zlqM3T^p<4FSpVxtP8rDn{1fkKuRe}D@6v&iVMMnidy=W>^T!RjbXItJ;iaJ^YYULA;cLb)4cfaZO#tCrk*^Xo>UMi7|{)kQ_V1(Kp_o~sB zmZQZYQ6D{1I_pgqjpUXs$ur%?1A$a2od6TpO@kP2Fml6vswd^Fk_L-9eKoZtlMT6HA;+ diff --git a/substrate/frame/revive/rpc/examples/js/pvm/PiggyBank.polkavm b/substrate/frame/revive/rpc/examples/js/pvm/PiggyBank.polkavm index 4423c605f746aa424937c84a10dfb9a4f7b6f8e5..416577ad8f23e9229df7580011424dea4ec4f21f 100644 GIT binary patch literal 5269 zcmcIne{3Abb>7|EyP5l?n>&%*-O))pUYFE~a2>XA+N)yJXM(Zrh>E?Q2;s1cgN`CE zySHR)hN8tKsRC>&gGVV&#VZYwbPg2^y5bKcb^a(s$!e;`0ZdZ=s6h%CMVc~58~Bf) zR?{R_Y+CA@J<_z=SU?Swz~kP|&b;~Nz3+W9lRb5U<6ddtoIf6M|B&Ktb189hBfwfj zun1TT>`Abvz@7p7W3ba;7T9^PDX_lY!9ixH`+G-vPxrkrG`9CP_(E_0-rL#oc!|B0 zhK9Zp*4EGwP;nK*9!_V&x{^UCwaJJMtc)H$r7Dko7{N)!%de01&oDr;L$IrRm z!52%XM}~W!Kl`Q9@NlW$9TsK|iEO@^7Ega^Xz+zG&tHBcF3db>a2L2~?wed#=n(RP zC461@5BG=eL9~j_<8kk+-aFn_U&;5J|0Vxl`@iG&2i5{T!F$2ceXs3Hhh7W)n6!j{ zJDeNaH%>$p@;xj1IFA3^#Xl&`VPWcUWOVBbzYh&Q5$)%EnB#<_c0&__XU-N;j1x*z z@L})Qe$EWv)<{xoY}c9+W@9Q6-in;#MI>Sm5o$$*IYE%RU145oLWC2Jdt#gmd60*Q zUJvp7lsCh%hZ=c@(;Dw`TGKjbHg0j?BiAINl!#*&sYQ3C!WZH58aa zA@m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AjaFHl*44U^QDiVg`e(UA6jVHB~bYXS3Ores5N*ZtEJ{ht_w6m{-Bz;e*wb844cG zg(s4swotll!mLf7Fw<=}Cm&C>C6gj%t)9FmX--t#U%V}QIAzujq-wcr&D^@hOmEuo zd@`B5sjZe|-qgT_R+#j$YU=B4hnJgWz4z6!Tj42mS!#6M@o^&<=D zTST}6gWLl%C6hR~X;WKUa3aZK%6`dLa%O14Ox8}+*s80wBiUzGjo^;9$(`~*$5(y= zp$TtF*2Hwx9rf^uG=%1U)+iNfTjkgR*}afq-8%ibxT@7~y3H{UpSbP*`OMZoJ;7$^*pN)Eb|UAA iL&xw2*p1Ids&UZtz8Xy9It5z;Xi2(P5aCj5EBAlUKU0_h diff --git a/substrate/frame/revive/src/benchmarking/mod.rs b/substrate/frame/revive/src/benchmarking/mod.rs index 1fb4d7ab58a4..1947d310baf2 100644 --- a/substrate/frame/revive/src/benchmarking/mod.rs +++ b/substrate/frame/revive/src/benchmarking/mod.rs @@ -362,10 +362,10 @@ mod benchmarks { // We just call a dummy contract to measure the overhead of the call extrinsic. // The size of the data has no influence on the costs of this extrinsic as long as the contract - // won't call `seal_input` in its constructor to copy the data to contract memory. + // won't call `seal_call_data_copy` in its constructor to copy the data to contract memory. // The dummy contract used here does not do this. The costs for the data copy is billed as - // part of `seal_input`. The costs for invoking a contract of a specific size are not part - // of this benchmark because we cannot know the size of the contract when issuing a call + // part of `seal_call_data_copy`. The costs for invoking a contract of a specific size are not + // part of this benchmark because we cannot know the size of the contract when issuing a call // transaction. See `call_with_code_per_byte` for this. #[benchmark(pov_mode = Measured)] fn call() -> Result<(), BenchmarkError> { @@ -853,6 +853,29 @@ mod benchmarks { assert_eq!(U256::from_little_endian(&memory[..]), runtime.ext().get_weight_price(weight)); } + #[benchmark(pov_mode = Measured)] + fn seal_copy_to_contract(n: Linear<0, { limits::code::BLOB_BYTES - 4 }>) { + let mut setup = CallSetup::::default(); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + let mut memory = memory!(n.encode(), vec![0u8; n as usize],); + let result; + #[block] + { + result = runtime.write_sandbox_output( + memory.as_mut_slice(), + 4, + 0, + &vec![42u8; n as usize], + false, + |_| None, + ); + } + assert_ok!(result); + assert_eq!(&memory[..4], &n.encode()); + assert_eq!(&memory[4..], &vec![42u8; n as usize]); + } + #[benchmark(pov_mode = Measured)] fn seal_call_data_load() { let mut setup = CallSetup::::default(); @@ -869,18 +892,18 @@ mod benchmarks { } #[benchmark(pov_mode = Measured)] - fn seal_input(n: Linear<0, { limits::code::BLOB_BYTES - 4 }>) { + fn seal_call_data_copy(n: Linear<0, { limits::code::BLOB_BYTES }>) { let mut setup = CallSetup::::default(); let (mut ext, _) = setup.ext(); let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![42u8; n as usize]); - let mut memory = memory!(n.to_le_bytes(), vec![0u8; n as usize],); + let mut memory = memory!(vec![0u8; n as usize],); let result; #[block] { - result = runtime.bench_input(memory.as_mut_slice(), 4, 0); + result = runtime.bench_call_data_copy(memory.as_mut_slice(), 0, n, 0); } assert_ok!(result); - assert_eq!(&memory[4..], &vec![42u8; n as usize]); + assert_eq!(&memory[..], &vec![42u8; n as usize]); } #[benchmark(pov_mode = Measured)] diff --git a/substrate/frame/revive/src/tests.rs b/substrate/frame/revive/src/tests.rs index 27ec7948e8fd..7ca08303316e 100644 --- a/substrate/frame/revive/src/tests.rs +++ b/substrate/frame/revive/src/tests.rs @@ -4364,6 +4364,22 @@ fn call_data_size_api_works() { }); } +#[test] +fn call_data_copy_api_works() { + let (code, _) = compile_module("call_data_copy").unwrap(); + + ExtBuilder::default().existential_deposit(100).build().execute_with(|| { + let _ = ::Currency::set_balance(&ALICE, 1_000_000); + + // Create fixture: Constructor does nothing + let Contract { addr, .. } = + builder::bare_instantiate(Code::Upload(code)).build_and_unwrap_contract(); + + // Call fixture: Expects an input of [255; 32] and executes tests. + assert_ok!(builder::call(addr).data(vec![255; 32]).build()); + }); +} + #[test] fn static_data_limit_is_enforced() { let (oom_rw_trailing, _) = compile_module("oom_rw_trailing").unwrap(); diff --git a/substrate/frame/revive/src/wasm/runtime.rs b/substrate/frame/revive/src/wasm/runtime.rs index 648a1621c198..8f944b530e86 100644 --- a/substrate/frame/revive/src/wasm/runtime.rs +++ b/substrate/frame/revive/src/wasm/runtime.rs @@ -65,6 +65,13 @@ pub trait Memory { /// - designated area is not within the bounds of the sandbox memory. fn write(&mut self, ptr: u32, buf: &[u8]) -> Result<(), DispatchError>; + /// Zero the designated location in the sandbox memory. + /// + /// Returns `Err` if one of the following conditions occurs: + /// + /// - designated area is not within the bounds of the sandbox memory. + fn zero(&mut self, ptr: u32, len: u32) -> Result<(), DispatchError>; + /// Read designated chunk from the sandbox memory. /// /// Returns `Err` if one of the following conditions occurs: @@ -162,6 +169,10 @@ impl Memory for [u8] { bound_checked.copy_from_slice(buf); Ok(()) } + + fn zero(&mut self, ptr: u32, len: u32) -> Result<(), DispatchError> { + <[u8] as Memory>::write(self, ptr, &vec![0; len as usize]) + } } impl Memory for polkavm::RawInstance { @@ -174,6 +185,10 @@ impl Memory for polkavm::RawInstance { fn write(&mut self, ptr: u32, buf: &[u8]) -> Result<(), DispatchError> { self.write_memory(ptr, buf).map_err(|_| Error::::OutOfBounds.into()) } + + fn zero(&mut self, ptr: u32, len: u32) -> Result<(), DispatchError> { + self.zero_memory(ptr, len).map_err(|_| Error::::OutOfBounds.into()) + } } impl PolkaVmInstance for polkavm::RawInstance { @@ -269,6 +284,8 @@ pub enum RuntimeCosts { CopyToContract(u32), /// Weight of calling `seal_call_data_load``. CallDataLoad, + /// Weight of calling `seal_call_data_copy`. + CallDataCopy(u32), /// Weight of calling `seal_caller`. Caller, /// Weight of calling `seal_call_data_size`. @@ -431,10 +448,11 @@ impl Token for RuntimeCosts { use self::RuntimeCosts::*; match *self { HostFn => cost_args!(noop_host_fn, 1), - CopyToContract(len) => T::WeightInfo::seal_input(len), + CopyToContract(len) => T::WeightInfo::seal_copy_to_contract(len), CopyFromContract(len) => T::WeightInfo::seal_return(len), CallDataSize => T::WeightInfo::seal_call_data_size(), CallDataLoad => T::WeightInfo::seal_call_data_load(), + CallDataCopy(len) => T::WeightInfo::seal_call_data_copy(len), Caller => T::WeightInfo::seal_caller(), Origin => T::WeightInfo::seal_origin(), IsContract => T::WeightInfo::seal_is_contract(), @@ -1276,18 +1294,34 @@ pub mod env { } /// Stores the input passed by the caller into the supplied buffer. - /// See [`pallet_revive_uapi::HostFn::input`]. + /// See [`pallet_revive_uapi::HostFn::call_data_copy`]. #[stable] - fn input(&mut self, memory: &mut M, out_ptr: u32, out_len_ptr: u32) -> Result<(), TrapReason> { - if let Some(input) = self.input_data.take() { - self.write_sandbox_output(memory, out_ptr, out_len_ptr, &input, false, |len| { - Some(RuntimeCosts::CopyToContract(len)) - })?; - self.input_data = Some(input); - Ok(()) - } else { - Err(Error::::InputForwarded.into()) + fn call_data_copy( + &mut self, + memory: &mut M, + out_ptr: u32, + out_len: u32, + offset: u32, + ) -> Result<(), TrapReason> { + self.charge_gas(RuntimeCosts::CallDataCopy(out_len))?; + + let Some(input) = self.input_data.as_ref() else { + return Err(Error::::InputForwarded.into()); + }; + + let start = offset as usize; + if start >= input.len() { + memory.zero(out_ptr, out_len)?; + return Ok(()); } + + let end = start.saturating_add(out_len as usize).min(input.len()); + memory.write(out_ptr, &input[start..end])?; + + let bytes_written = (end - start) as u32; + memory.zero(out_ptr.saturating_add(bytes_written), out_len - bytes_written)?; + + Ok(()) } /// Stores the U256 value at given call input `offset` into the supplied buffer. diff --git a/substrate/frame/revive/src/weights.rs b/substrate/frame/revive/src/weights.rs index e8fec31b19e5..94bd0397a0d5 100644 --- a/substrate/frame/revive/src/weights.rs +++ b/substrate/frame/revive/src/weights.rs @@ -86,7 +86,8 @@ pub trait WeightInfo { fn seal_now() -> Weight; fn seal_weight_to_fee() -> Weight; fn seal_call_data_load() -> Weight; - fn seal_input(n: u32, ) -> Weight; + fn seal_copy_to_contract(n: u32, ) -> Weight; + fn seal_call_data_copy(n: u32, ) -> Weight; fn seal_return(n: u32, ) -> Weight; fn seal_terminate(n: u32, ) -> Weight; fn seal_deposit_event(t: u32, n: u32, ) -> Weight; @@ -533,12 +534,22 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(295_000, 0) } /// The range of component `n` is `[0, 262140]`. - fn seal_input(n: u32, ) -> Weight { + fn seal_copy_to_contract(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 475_000 picoseconds. - Weight::from_parts(427_145, 0) + // Minimum execution time: 369_000 picoseconds. + Weight::from_parts(544_048, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(200, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 262144]`. + fn seal_call_data_copy(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 244_000 picoseconds. + Weight::from_parts(123_748, 0) // Standard Error: 0 .saturating_add(Weight::from_parts(114, 0).saturating_mul(n.into())) } @@ -1382,12 +1393,22 @@ impl WeightInfo for () { Weight::from_parts(295_000, 0) } /// The range of component `n` is `[0, 262140]`. - fn seal_input(n: u32, ) -> Weight { + fn seal_copy_to_contract(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 475_000 picoseconds. - Weight::from_parts(427_145, 0) + // Minimum execution time: 369_000 picoseconds. + Weight::from_parts(544_048, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(200, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 262144]`. + fn seal_call_data_copy(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 244_000 picoseconds. + Weight::from_parts(123_748, 0) // Standard Error: 0 .saturating_add(Weight::from_parts(114, 0).saturating_mul(n.into())) } diff --git a/substrate/frame/revive/uapi/src/flags.rs b/substrate/frame/revive/uapi/src/flags.rs index 763a89d6c030..6a0f47c38c2c 100644 --- a/substrate/frame/revive/uapi/src/flags.rs +++ b/substrate/frame/revive/uapi/src/flags.rs @@ -38,7 +38,7 @@ bitflags! { /// /// A forwarding call will consume the current contracts input. Any attempt to /// access the input after this call returns will lead to [`Error::InputForwarded`]. - /// It does not matter if this is due to calling `seal_input` or trying another + /// It does not matter if this is due to calling `call_data_copy` or trying another /// forwarding call. Consider using [`Self::CLONE_INPUT`] in order to preserve /// the input. const FORWARD_INPUT = 0b0000_0001; diff --git a/substrate/frame/revive/uapi/src/host.rs b/substrate/frame/revive/uapi/src/host.rs index aa3203697898..505ec0a82f07 100644 --- a/substrate/frame/revive/uapi/src/host.rs +++ b/substrate/frame/revive/uapi/src/host.rs @@ -245,18 +245,28 @@ pub trait HostFn: private::Sealed { hash_fn!(keccak_256, 32); - /// Stores the input passed by the caller into the supplied buffer. + /// Stores the input data passed by the caller into the supplied `output` buffer, + /// starting from the given input data `offset`. + /// + /// The `output` buffer is guaranteed to always be fully populated: + /// - If the call data (starting from the given `offset`) is larger than the `output` buffer, + /// only what fits into the `output` buffer is written. + /// - If the `output` buffer size exceeds the call data size (starting from `offset`), remaining + /// bytes in the `output` buffer are zeroed out. + /// - If the provided call data `offset` is out-of-bounds, the whole `output` buffer is zeroed + /// out. /// /// # Note /// /// This function traps if: - /// - the input is larger than the available space. /// - the input was previously forwarded by a [`call()`][`Self::call()`]. + /// - the `output` buffer is located in an PolkaVM invalid memory range. /// /// # Parameters /// - /// - `output`: A reference to the output data buffer to write the input data. - fn input(output: &mut &mut [u8]); + /// - `output`: A reference to the output data buffer to write the call data. + /// - `offset`: The offset index into the call data from where to start copying. + fn call_data_copy(output: &mut [u8], offset: u32); /// Stores the U256 value at given `offset` from the input passed by the caller /// into the supplied buffer. diff --git a/substrate/frame/revive/uapi/src/host/riscv64.rs b/substrate/frame/revive/uapi/src/host/riscv64.rs index d5a695262a24..40de12b25f36 100644 --- a/substrate/frame/revive/uapi/src/host/riscv64.rs +++ b/substrate/frame/revive/uapi/src/host/riscv64.rs @@ -62,7 +62,7 @@ mod sys { pub fn delegate_call(ptr: *const u8) -> ReturnCode; pub fn instantiate(ptr: *const u8) -> ReturnCode; pub fn terminate(beneficiary_ptr: *const u8); - pub fn input(out_ptr: *mut u8, out_len_ptr: *mut u32); + pub fn call_data_copy(out_ptr: *mut u8, out_len: u32, offset: u32); pub fn call_data_load(out_ptr: *mut u8, offset: u32); pub fn seal_return(flags: u32, data_ptr: *const u8, data_len: u32); pub fn caller(out_ptr: *mut u8); @@ -381,14 +381,6 @@ impl HostFn for HostFnImpl { ret_code.into() } - fn input(output: &mut &mut [u8]) { - let mut output_len = output.len() as u32; - { - unsafe { sys::input(output.as_mut_ptr(), &mut output_len) }; - } - extract_from_slice(output, output_len as usize); - } - fn call_data_load(out_ptr: &mut [u8; 32], offset: u32) { unsafe { sys::call_data_load(out_ptr.as_mut_ptr(), offset) }; } @@ -474,6 +466,11 @@ impl HostFn for HostFnImpl { ret_code.into_u32() } + fn call_data_copy(output: &mut [u8], offset: u32) { + let len = output.len() as u32; + unsafe { sys::call_data_copy(output.as_mut_ptr(), len, offset) }; + } + #[cfg(feature = "unstable-api")] fn call_runtime(call: &[u8]) -> Result { let ret_code = unsafe { sys::call_runtime(call.as_ptr(), call.len() as u32) };