@@ -840,7 +840,17 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
840840 bin. builder
841841 . build_store ( value, contract_args. value . unwrap ( ) )
842842 . unwrap ( ) ;
843- args. push ( value. into ( ) ) ;
843+ // smoelius: Value is little-endian and must be byte-swapped.
844+ let temp = bin. builder . build_alloca ( bin. value_type ( ) , "value" ) . unwrap ( ) ;
845+ call ! (
846+ "__leNtobeN" ,
847+ & [
848+ value. into( ) ,
849+ temp. into( ) ,
850+ i32_const!( bin. ns. value_length as u64 ) . into( )
851+ ]
852+ ) ;
853+ args. push ( temp. into ( ) )
844854 }
845855
846856 let gas = gas_calculation ( bin, contract_args. gas . unwrap ( ) ) ;
@@ -1221,6 +1231,10 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
12211231
12221232 timestamp. into ( )
12231233 }
1234+ Expression :: Builtin {
1235+ kind : Builtin :: Value ,
1236+ ..
1237+ } => self . value_transferred ( bin) . into ( ) ,
12241238 _ => unimplemented ! ( "{expr:?}" ) ,
12251239 }
12261240 }
@@ -1270,7 +1284,28 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
12701284
12711285 /// Return the value we received
12721286 fn value_transferred < ' b > ( & self , bin : & Binary < ' b > ) -> IntValue < ' b > {
1273- unimplemented ! ( )
1287+ emit_context ! ( bin) ;
1288+
1289+ let value = bin. builder . build_alloca ( bin. value_type ( ) , "value" ) . unwrap ( ) ;
1290+
1291+ call ! ( "msg_value" , & [ value. into( ) ] , "value_transferred" ) ;
1292+
1293+ // smoelius: `value` is big-endian and must be byte-swapped.
1294+ let temp = bin. builder . build_alloca ( bin. value_type ( ) , "value" ) . unwrap ( ) ;
1295+
1296+ call ! (
1297+ "__beNtoleN" ,
1298+ & [
1299+ value. into( ) ,
1300+ temp. into( ) ,
1301+ i32_const!( bin. ns. value_length as u64 ) . into( )
1302+ ]
1303+ ) ;
1304+
1305+ bin. builder
1306+ . build_load ( bin. value_type ( ) , temp, "value" )
1307+ . unwrap ( )
1308+ . into_int_value ( )
12741309 }
12751310
12761311 /// Terminate execution, destroy bin and send remaining funds to addr
0 commit comments