Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 7ec5494

Browse files
edg-lfannyguthmann
authored andcommitted
fix wrong from_address in deprecated execute_constructor_entry_point (#1041)
* fix wrong from_address in deprecated execute_constructor_entry_point * fix test * fix another test
1 parent d4fcd9d commit 7ec5494

File tree

2 files changed

+129
-75
lines changed

2 files changed

+129
-75
lines changed

src/syscalls/deprecated_business_logic_syscall_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
272272
.map_err(|_| StateError::ExecutionEntryPoint())?;
273273

274274
if let Some(call_info) = call_info.call_info {
275-
self.events.extend(call_info.events);
275+
self.internal_calls.push(call_info);
276276
}
277277

278278
Ok(())

tests/syscalls.rs

Lines changed: 128 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use cairo_vm::{
1010
},
1111
};
1212
use num_traits::{Num, One, Zero};
13+
use pretty_assertions_sorted::{assert_eq, assert_eq_sorted};
1314
use starknet_in_rust::{
1415
definitions::{
1516
block_context::{BlockContext, StarknetChainId},
@@ -170,8 +171,8 @@ fn test_contract<'a>(
170171
accessed_storage_keys.collect()
171172
);
172173
assert_eq!(result.calldata, calldata);
173-
assert_eq!(result.retdata, return_data.into());
174-
assert_eq!(result.internal_calls, internal_calls.into());
174+
assert_eq_sorted!(result.retdata, return_data.into());
175+
assert_eq_sorted!(result.internal_calls, internal_calls.into());
175176
assert_eq!(result.execution_resources, execution_resources);
176177

177178
assert_eq!(result.gas_consumed, 0);
@@ -906,13 +907,20 @@ fn deploy_with_constructor_syscall() {
906907
10,
907908
)
908909
.unwrap();
910+
let entry_point_selector = Felt252::from_str_radix(
911+
"1159040026212278395030414237414753050475174923702621880048416706425641521556",
912+
10,
913+
)
914+
.unwrap();
909915

910916
let deploy_class_hash = [2u8; 32];
917+
let caller_address = Address(11111.into());
918+
911919
test_contract(
912920
"starknet_programs/syscalls.json",
913921
"test_deploy_with_constructor",
914922
[1; 32],
915-
Address(11111.into()),
923+
caller_address.clone(),
916924
Address(0.into()),
917925
BlockContext::default(),
918926
None,
@@ -931,7 +939,26 @@ fn deploy_with_constructor_syscall() {
931939
0.into(),
932940
550.into(),
933941
],
934-
[],
942+
[CallInfo {
943+
caller_address,
944+
call_type: Some(CallType::Call),
945+
contract_address: Address(deploy_address.clone()),
946+
class_hash: Some(deploy_class_hash),
947+
entry_point_selector: Some(entry_point_selector),
948+
entry_point_type: Some(EntryPointType::Constructor),
949+
calldata: [550.into()].to_vec(),
950+
execution_resources: ExecutionResources {
951+
n_steps: 40,
952+
n_memory_holes: 0,
953+
..Default::default()
954+
},
955+
accessed_storage_keys: HashSet::<[u8; 32]>::from([[
956+
2, 63, 76, 85, 114, 157, 43, 172, 36, 175, 107, 126, 158, 121, 114, 77, 194, 27,
957+
162, 147, 169, 199, 107, 53, 94, 246, 206, 221, 169, 114, 215, 255,
958+
]]),
959+
storage_read_values: [0.into()].to_vec(),
960+
..Default::default()
961+
}],
935962
[deploy_address],
936963
ExecutionResources {
937964
n_steps: 84,
@@ -982,86 +1009,113 @@ fn test_deploy_and_call_contract_syscall() {
9821009
new_constant.clone(),
9831010
],
9841011
[
985-
// Invoke storage_var_and_constructor.cairo mult_constant function
986-
CallInfo {
987-
caller_address: Address(11111.into()),
988-
call_type: Some(CallType::Call),
989-
contract_address: deploy_address.clone(),
990-
code_address: None,
991-
class_hash: Some(deploy_class_hash),
992-
entry_point_selector: Some(
993-
Felt252::from_str_radix(
994-
"1576037374104670872807053137865113122553607263175471701007015754752102201893",
995-
10,
996-
)
997-
.unwrap(),
998-
),
999-
entry_point_type: Some(EntryPointType::External),
1000-
calldata: vec![4.into()],
1001-
retdata: vec![(constructor_constant.clone() * Felt252::new(4))],
1002-
storage_read_values: vec![constructor_constant.clone()],
1003-
accessed_storage_keys: HashSet::from([constant_storage_key]),
1004-
execution_resources: ExecutionResources {
1005-
n_steps: 52,
1012+
// constructor
1013+
CallInfo {
1014+
caller_address: Address(11111.into()),
1015+
call_type: Some(CallType::Call),
1016+
contract_address: deploy_address.clone(),
1017+
code_address: None,
1018+
class_hash: Some(deploy_class_hash),
1019+
entry_point_selector: Some(
1020+
Felt252::from_str_radix(
1021+
"1159040026212278395030414237414753050475174923702621880048416706425641521556",
1022+
10,
1023+
)
1024+
.unwrap(),
1025+
),
1026+
entry_point_type: Some(EntryPointType::Constructor),
1027+
calldata: vec![550.into()],
1028+
retdata: vec![],
1029+
storage_read_values: vec![0.into()],
1030+
accessed_storage_keys: HashSet::from([constant_storage_key]),
1031+
execution_resources: ExecutionResources {
1032+
n_steps: 40,
1033+
..Default::default()
1034+
},
10061035
..Default::default()
10071036
},
1008-
..Default::default()
1009-
},
1010-
// Invoke storage_var_and_constructor.cairo set_constant function
1011-
CallInfo {
1012-
caller_address: Address(11111.into()),
1013-
call_type: Some(CallType::Call),
1014-
contract_address: deploy_address.clone(),
1015-
code_address: None,
1016-
class_hash: Some(deploy_class_hash),
1017-
entry_point_selector: Some(
1018-
Felt252::from_str_radix(
1019-
"1201037417712951658445715615949920673423990292207294106968654696818998525373",
1020-
10,
1021-
)
1022-
.unwrap(),
1023-
),
1024-
entry_point_type: Some(EntryPointType::External),
1025-
calldata: vec![new_constant.clone()],
1026-
retdata: vec![],
1027-
storage_read_values: vec![constructor_constant],
1028-
accessed_storage_keys: HashSet::from([constant_storage_key]),
1029-
execution_resources: ExecutionResources {
1030-
n_steps: 40,
1037+
// Invoke storage_var_and_constructor.cairo mult_constant function
1038+
CallInfo {
1039+
caller_address: Address(11111.into()),
1040+
call_type: Some(CallType::Call),
1041+
contract_address: deploy_address.clone(),
1042+
code_address: None,
1043+
class_hash: Some(deploy_class_hash),
1044+
entry_point_selector: Some(
1045+
Felt252::from_str_radix(
1046+
"1576037374104670872807053137865113122553607263175471701007015754752102201893",
1047+
10,
1048+
)
1049+
.unwrap(),
1050+
),
1051+
entry_point_type: Some(EntryPointType::External),
1052+
calldata: vec![4.into()],
1053+
retdata: vec![(constructor_constant.clone() * Felt252::new(4))],
1054+
storage_read_values: vec![constructor_constant.clone()],
1055+
accessed_storage_keys: HashSet::from([constant_storage_key]),
1056+
execution_resources: ExecutionResources {
1057+
n_steps: 52,
1058+
..Default::default()
1059+
},
10311060
..Default::default()
10321061
},
1033-
..Default::default()
1034-
},
1035-
// Invoke storage_var_and_constructor.cairo get_constant function
1036-
CallInfo {
1037-
caller_address: Address(11111.into()),
1038-
call_type: Some(CallType::Call),
1039-
contract_address: deploy_address,
1040-
code_address: None,
1041-
class_hash: Some(deploy_class_hash),
1042-
entry_point_selector: Some(
1043-
Felt252::from_str_radix(
1044-
"915547745133109687566886827729966789818200062539892992518817034473866315209",
1045-
10,
1046-
)
1047-
.unwrap(),
1048-
),
1049-
entry_point_type: Some(EntryPointType::External),
1050-
calldata: vec![],
1051-
retdata: vec![new_constant.clone()],
1052-
storage_read_values: vec![new_constant.clone()],
1053-
accessed_storage_keys: HashSet::from([constant_storage_key]),
1054-
execution_resources: ExecutionResources {
1055-
n_steps: 46,
1062+
// Invoke storage_var_and_constructor.cairo set_constant function
1063+
CallInfo {
1064+
caller_address: Address(11111.into()),
1065+
call_type: Some(CallType::Call),
1066+
contract_address: deploy_address.clone(),
1067+
code_address: None,
1068+
class_hash: Some(deploy_class_hash),
1069+
entry_point_selector: Some(
1070+
Felt252::from_str_radix(
1071+
"1201037417712951658445715615949920673423990292207294106968654696818998525373",
1072+
10,
1073+
)
1074+
.unwrap(),
1075+
),
1076+
entry_point_type: Some(EntryPointType::External),
1077+
calldata: vec![new_constant.clone()],
1078+
retdata: vec![],
1079+
storage_read_values: vec![constructor_constant],
1080+
accessed_storage_keys: HashSet::from([constant_storage_key]),
1081+
execution_resources: ExecutionResources {
1082+
n_steps: 40,
1083+
..Default::default()
1084+
},
10561085
..Default::default()
10571086
},
1058-
..Default::default()
1059-
} ],
1087+
// Invoke storage_var_and_constructor.cairo get_constant function
1088+
CallInfo {
1089+
caller_address: Address(11111.into()),
1090+
call_type: Some(CallType::Call),
1091+
contract_address: deploy_address,
1092+
code_address: None,
1093+
class_hash: Some(deploy_class_hash),
1094+
entry_point_selector: Some(
1095+
Felt252::from_str_radix(
1096+
"915547745133109687566886827729966789818200062539892992518817034473866315209",
1097+
10,
1098+
)
1099+
.unwrap(),
1100+
),
1101+
entry_point_type: Some(EntryPointType::External),
1102+
calldata: vec![],
1103+
retdata: vec![new_constant.clone()],
1104+
storage_read_values: vec![new_constant.clone()],
1105+
accessed_storage_keys: HashSet::from([constant_storage_key]),
1106+
execution_resources: ExecutionResources {
1107+
n_steps: 46,
1108+
..Default::default()
1109+
},
1110+
..Default::default()
1111+
}
1112+
],
10601113
[new_constant],
10611114
ExecutionResources {
10621115
n_steps: 325,
10631116
n_memory_holes: 2,
1064-
builtin_instance_counter: HashMap::default()},
1117+
builtin_instance_counter: HashMap::default()
1118+
},
10651119
);
10661120
}
10671121

0 commit comments

Comments
 (0)