@@ -3258,7 +3258,7 @@ fn link_stx_burn_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error
3258
3258
amount_hi : i64 ,
3259
3259
principal_offset : i32 ,
3260
3260
principal_length : i32 | {
3261
- let amount = ( amount_hi as u128 ) << 64 | ( amount_lo as u128 ) ;
3261
+ let amount = ( amount_hi as u128 ) << 64 | ( ( amount_lo as u64 ) as u128 ) ;
3262
3262
3263
3263
// Get the memory from the caller
3264
3264
let memory = caller
@@ -3358,7 +3358,7 @@ fn link_stx_transfer_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), E
3358
3358
recipient_length : i32 ,
3359
3359
memo_offset : i32 ,
3360
3360
memo_length : i32 | {
3361
- let amount = ( amount_hi as u128 ) << 64 | ( amount_lo as u128 ) ;
3361
+ let amount = ( amount_hi as u128 ) << 64 | ( ( amount_lo as u64 ) as u128 ) ;
3362
3362
3363
3363
// Get the memory from the caller
3364
3364
let memory = caller
@@ -3624,7 +3624,7 @@ fn link_ft_burn_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error>
3624
3624
let token_name = ClarityName :: try_from ( name. clone ( ) ) ?;
3625
3625
3626
3626
// Compute the amount
3627
- let amount = ( amount_hi as u128 ) << 64 | ( amount_lo as u128 ) ;
3627
+ let amount = ( amount_hi as u128 ) << 64 | ( ( amount_lo as u64 ) as u128 ) ;
3628
3628
3629
3629
// Read the sender principal from the Wasm memory
3630
3630
let value = read_from_wasm (
@@ -3754,7 +3754,7 @@ fn link_ft_mint_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error>
3754
3754
let token_name = ClarityName :: try_from ( name. clone ( ) ) ?;
3755
3755
3756
3756
// Compute the amount
3757
- let amount = ( amount_hi as u128 ) << 64 | ( amount_lo as u128 ) ;
3757
+ let amount = ( amount_hi as u128 ) << 64 | ( ( amount_lo as u64 ) as u128 ) ;
3758
3758
3759
3759
// Read the sender principal from the Wasm memory
3760
3760
let value = read_from_wasm (
@@ -3804,7 +3804,9 @@ fn link_ft_mint_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error>
3804
3804
3805
3805
// This `expect` is safe because the `checked_increase_token_supply` call above
3806
3806
// would have failed if the addition would have overflowed.
3807
- let final_to_bal = to_bal. checked_add ( amount) . expect ( "FT overflow" ) ;
3807
+ let final_to_bal = to_bal
3808
+ . checked_add ( amount)
3809
+ . ok_or ( Error :: Runtime ( RuntimeErrorType :: ArithmeticOverflow , None ) ) ?;
3808
3810
3809
3811
caller
3810
3812
. data_mut ( )
@@ -3882,7 +3884,7 @@ fn link_ft_transfer_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Er
3882
3884
let token_name = ClarityName :: try_from ( name. clone ( ) ) ?;
3883
3885
3884
3886
// Compute the amount
3885
- let amount = ( amount_hi as u128 ) << 64 | ( amount_lo as u128 ) ;
3887
+ let amount = ( amount_hi as u128 ) << 64 | ( ( amount_lo as u64 ) as u128 ) ;
3886
3888
3887
3889
// Read the sender principal from the Wasm memory
3888
3890
let value = read_from_wasm (
@@ -4034,8 +4036,8 @@ fn link_nft_get_owner_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(),
4034
4036
|mut caller : Caller < ' _ , ClarityWasmContext > ,
4035
4037
name_offset : i32 ,
4036
4038
name_length : i32 ,
4037
- asset_offset : i32 ,
4038
- asset_length : i32 ,
4039
+ mut asset_offset : i32 ,
4040
+ mut asset_length : i32 ,
4039
4041
return_offset : i32 ,
4040
4042
_return_length : i32 | {
4041
4043
// Get the memory from the caller
@@ -4064,6 +4066,10 @@ fn link_nft_get_owner_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(),
4064
4066
let expected_asset_type = & nft_metadata. key_type ;
4065
4067
4066
4068
// Read in the NFT identifier from the Wasm memory
4069
+ if is_in_memory_type ( expected_asset_type) {
4070
+ ( asset_offset, asset_length) =
4071
+ read_indirect_offset_and_length ( memory, & mut caller, asset_offset) ?;
4072
+ }
4067
4073
let asset = read_from_wasm (
4068
4074
memory,
4069
4075
& mut caller,
@@ -4130,8 +4136,8 @@ fn link_nft_burn_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error
4130
4136
|mut caller : Caller < ' _ , ClarityWasmContext > ,
4131
4137
name_offset : i32 ,
4132
4138
name_length : i32 ,
4133
- asset_offset : i32 ,
4134
- asset_length : i32 ,
4139
+ mut asset_offset : i32 ,
4140
+ mut asset_length : i32 ,
4135
4141
sender_offset : i32 ,
4136
4142
sender_length : i32 | {
4137
4143
// Get the memory from the caller
@@ -4161,6 +4167,10 @@ fn link_nft_burn_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error
4161
4167
let expected_asset_type = & nft_metadata. key_type ;
4162
4168
4163
4169
// Read in the NFT identifier from the Wasm memory
4170
+ if is_in_memory_type ( expected_asset_type) {
4171
+ ( asset_offset, asset_length) =
4172
+ read_indirect_offset_and_length ( memory, & mut caller, asset_offset) ?;
4173
+ }
4164
4174
let asset = read_from_wasm (
4165
4175
memory,
4166
4176
& mut caller,
@@ -4265,8 +4275,8 @@ fn link_nft_mint_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error
4265
4275
|mut caller : Caller < ' _ , ClarityWasmContext > ,
4266
4276
name_offset : i32 ,
4267
4277
name_length : i32 ,
4268
- asset_offset : i32 ,
4269
- asset_length : i32 ,
4278
+ mut asset_offset : i32 ,
4279
+ mut asset_length : i32 ,
4270
4280
recipient_offset : i32 ,
4271
4281
recipient_length : i32 | {
4272
4282
// Get the memory from the caller
@@ -4296,6 +4306,10 @@ fn link_nft_mint_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error
4296
4306
let expected_asset_type = & nft_metadata. key_type ;
4297
4307
4298
4308
// Read in the NFT identifier from the Wasm memory
4309
+ if is_in_memory_type ( expected_asset_type) {
4310
+ ( asset_offset, asset_length) =
4311
+ read_indirect_offset_and_length ( memory, & mut caller, asset_offset) ?;
4312
+ }
4299
4313
let asset = read_from_wasm (
4300
4314
memory,
4301
4315
& mut caller,
@@ -4389,8 +4403,8 @@ fn link_nft_transfer_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), E
4389
4403
|mut caller : Caller < ' _ , ClarityWasmContext > ,
4390
4404
name_offset : i32 ,
4391
4405
name_length : i32 ,
4392
- asset_offset : i32 ,
4393
- asset_length : i32 ,
4406
+ mut asset_offset : i32 ,
4407
+ mut asset_length : i32 ,
4394
4408
sender_offset : i32 ,
4395
4409
sender_length : i32 ,
4396
4410
recipient_offset : i32 ,
@@ -4422,6 +4436,10 @@ fn link_nft_transfer_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), E
4422
4436
let expected_asset_type = & nft_metadata. key_type ;
4423
4437
4424
4438
// Read in the NFT identifier from the Wasm memory
4439
+ if is_in_memory_type ( expected_asset_type) {
4440
+ ( asset_offset, asset_length) =
4441
+ read_indirect_offset_and_length ( memory, & mut caller, asset_offset) ?;
4442
+ }
4425
4443
let asset = read_from_wasm (
4426
4444
memory,
4427
4445
& mut caller,
@@ -5849,21 +5867,45 @@ fn link_secp256k1_recover_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<
5849
5867
. and_then ( |export| export. into_memory ( ) )
5850
5868
. ok_or ( Error :: Wasm ( WasmError :: MemoryNotFound ) ) ?;
5851
5869
5870
+ let ret_ty = TypeSignature :: new_response ( BUFF_33 . clone ( ) , TypeSignature :: UIntType ) ?;
5871
+ let repr_size = get_type_size ( & ret_ty) ;
5872
+
5852
5873
// Read the message bytes from the memory
5853
5874
let msg_bytes = read_bytes_from_wasm ( memory, & mut caller, msg_offset, msg_length) ?;
5875
+ // To match the interpreter behavior, if the message is the
5876
+ // wrong length, throw a runtime type error.
5877
+ if msg_bytes. len ( ) != 32 {
5878
+ return Err ( CheckErrors :: TypeValueError (
5879
+ BUFF_32 . clone ( ) ,
5880
+ Value :: buff_from ( msg_bytes) ?,
5881
+ )
5882
+ . into ( ) ) ;
5883
+ }
5854
5884
5855
5885
// Read the signature bytes from the memory
5856
5886
let sig_bytes = read_bytes_from_wasm ( memory, & mut caller, sig_offset, sig_length) ?;
5887
+ // To match the interpreter behavior, if the signature is the
5888
+ // wrong length, return a Clarity error.
5889
+ if sig_bytes. len ( ) != 65 || sig_bytes[ 64 ] > 3 {
5890
+ let result = Value :: err_uint ( 2 ) ;
5891
+ write_to_wasm (
5892
+ caller,
5893
+ memory,
5894
+ & ret_ty,
5895
+ return_offset,
5896
+ return_offset + repr_size,
5897
+ & result,
5898
+ true ,
5899
+ ) ?;
5900
+ return Ok ( ( ) ) ;
5901
+ }
5857
5902
5858
5903
let result = match secp256k1_recover ( & msg_bytes, & sig_bytes) {
5859
5904
Ok ( pubkey) => Value :: okay ( Value :: buff_from ( pubkey. to_vec ( ) ) . unwrap ( ) ) . unwrap ( ) ,
5860
5905
_ => Value :: err_uint ( 1 ) ,
5861
5906
} ;
5862
5907
5863
5908
// Write the result to the return buffer
5864
- let ret_ty =
5865
- TypeSignature :: new_response ( BUFF_33 . clone ( ) , TypeSignature :: UIntType ) . unwrap ( ) ;
5866
- let repr_size = get_type_size ( & ret_ty) ;
5867
5909
write_to_wasm (
5868
5910
caller,
5869
5911
memory,
@@ -5910,12 +5952,38 @@ fn link_secp256k1_verify_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(
5910
5952
5911
5953
// Read the message bytes from the memory
5912
5954
let msg_bytes = read_bytes_from_wasm ( memory, & mut caller, msg_offset, msg_length) ?;
5955
+ // To match the interpreter behavior, if the message is the
5956
+ // wrong length, throw a runtime type error.
5957
+ if msg_bytes. len ( ) != 32 {
5958
+ return Err ( CheckErrors :: TypeValueError (
5959
+ BUFF_32 . clone ( ) ,
5960
+ Value :: buff_from ( msg_bytes) ?,
5961
+ )
5962
+ . into ( ) ) ;
5963
+ }
5913
5964
5914
5965
// Read the signature bytes from the memory
5915
5966
let sig_bytes = read_bytes_from_wasm ( memory, & mut caller, sig_offset, sig_length) ?;
5967
+ // To match the interpreter behavior, if the signature is the
5968
+ // wrong length, return a Clarity error.
5969
+ if sig_bytes. len ( ) < 64
5970
+ || sig_bytes. len ( ) > 65
5971
+ || sig_bytes. len ( ) == 65 && sig_bytes[ 64 ] > 3
5972
+ {
5973
+ return Ok ( 0i32 ) ;
5974
+ }
5916
5975
5917
5976
// Read the public-key bytes from the memory
5918
5977
let pk_bytes = read_bytes_from_wasm ( memory, & mut caller, pk_offset, pk_length) ?;
5978
+ // To match the interpreter behavior, if the public key is the
5979
+ // wrong length, throw a runtime type error.
5980
+ if pk_bytes. len ( ) != 33 {
5981
+ return Err ( CheckErrors :: TypeValueError (
5982
+ BUFF_33 . clone ( ) ,
5983
+ Value :: buff_from ( pk_bytes) ?,
5984
+ )
5985
+ . into ( ) ) ;
5986
+ }
5919
5987
5920
5988
Ok ( secp256k1_verify ( & msg_bytes, & sig_bytes, & pk_bytes) . map_or ( 0i32 , |_| 1i32 ) )
5921
5989
} ,
0 commit comments