Skip to content

Commit b2c5657

Browse files
committed
Debug attempt hyperledger-solang#1
1 parent 88bf853 commit b2c5657

5 files changed

Lines changed: 85 additions & 2 deletions

File tree

‎Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ wasmi = "0.11"
5656
rand = "0.7"
5757
sha2 = "0.10"
5858
# solana_rbpf makes api changes in patch versions
59-
solana_rbpf = "=0.2.31"
59+
# solana_rbpf = "=0.2.31"
60+
solana_rbpf = {path = "../rbpf"}
6061
byteorder = "1.4"
6162
assert_cmd = "2.0"
6263
bincode = "1.3"

‎stdlib/bpf/solana.bc‎

0 Bytes
Binary file not shown.

‎stdlib/solana.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,23 @@ uint64_t account_data_alloc(SolAccountInfo *ai, uint32_t size, uint32_t *res)
548548
uint32_t account_data_len(void *data, uint32_t offset)
549549
{
550550
// Nothing to do
551-
if (!offset)
551+
if (!offset) {
552+
// sol_log("zero offset");
552553
return 0;
554+
}
553555

554556
offset -= sizeof(struct chunk);
555557

558+
// char s[10] = {'j'};
559+
// s[9] = '\0';
560+
// uint32_t p = offset;
561+
// uint8_t idx = 8;
562+
// while(p > 0 && idx >= 0) {
563+
// uint8_t g = p % 10;
564+
// s[idx--] = '0' + g;
565+
// p /= 10;
566+
// }
567+
// sol_log_(&s, 10);
556568
struct chunk *chunk = data + offset;
557569

558570
return chunk->length;

‎tests/solana.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,7 @@ impl VirtualMachine {
13921392
println!("input: {}", hex::encode(&calldata));
13931393

13941394
let res = self.execute(&calldata, seeds);
1395+
std::println!("{:?}", res);
13951396
assert!(matches!(res, Ok(0)));
13961397

13971398
if let Some((_, return_data)) = &self.return_data {

‎tests/solana_tests/arrays.rs‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,3 +892,72 @@ fn array_literal() {
892892
])]
893893
);
894894
}
895+
896+
#[test]
897+
fn access_violation() {
898+
let mut vm = build_solidity(
899+
r#"
900+
contract Testing {
901+
902+
struct NonConstantStruct {
903+
string[] b;
904+
}
905+
906+
string[] vec_2;
907+
NonConstantStruct[] complex_array;
908+
function fn1() public {
909+
vec_2.push("tea");
910+
}
911+
912+
function fn2() public {
913+
vec_2.push("coffee");
914+
}
915+
916+
function fn3() public {
917+
NonConstantStruct memory ss = NonConstantStruct(vec_2);
918+
complex_array.push(ss);
919+
}
920+
921+
function fn4() public {
922+
vec_2.pop();
923+
}
924+
925+
function fn5() public {
926+
vec_2.pop();
927+
}
928+
929+
function fn6() public {
930+
vec_2.push("cortado");
931+
}
932+
933+
function fn7() public {
934+
vec_2.push("cappuccino");
935+
}
936+
937+
function fn8() public {
938+
NonConstantStruct memory sr = NonConstantStruct(vec_2);
939+
complex_array.push(sr);
940+
}
941+
}
942+
"#
943+
);
944+
945+
vm.constructor("Testing", &[]);
946+
std::println!("Calling fn1");
947+
let _ = vm.function("fn1", &[], &[], None);
948+
std::println!("Calling fn2");
949+
let _ = vm.function("fn2", &[], &[], None);
950+
std::println!("Calling fn3");
951+
let _ = vm.function("fn3", &[], &[], None);
952+
std::println!("Calling fn4");
953+
let _ = vm.function("fn4", &[], &[], None);
954+
std::println!("Calling fn5");
955+
let _ = vm.function("fn5", &[], &[], None);
956+
std::println!("Calling fn6");
957+
let _ = vm.function("fn6", &[], &[], None);
958+
std::println!("Calling fn7");
959+
let _ = vm.function("fn7", &[], &[], None);
960+
std::println!("Calling fn8");
961+
let _ = vm.function("fn8", &[], &[], None);
962+
963+
}

0 commit comments

Comments
 (0)