Skip to content

Commit

Permalink
Partially reverts LDC changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Aug 14, 2024
1 parent 7c3dae2 commit 1d55638
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 74 deletions.
40 changes: 0 additions & 40 deletions sway-lib-std/src/execution.sw
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,3 @@ pub fn run_external(load_target: ContractId) -> ! {
}
__jmp_mem()
}

pub fn run_external2(load_target1: ContractId, load_target2: ContractId) -> ! {
// Get lengths of both chunks
// Store load_target2 on the heap as it'll be overwritten with the first LDC we do.
// Save the old $ssp value as that's were the contract will be loaded.
// Shrink the stack since LDC wants $ssp == $sp
// Do the loads
// __jmp_mem jumps to $MEM[$hp], so set that up.
asm(
load_target1: load_target1,
load_target2: load_target2,
load_target2_heap,
heap_alloc_size,
length1,
length2,
ssp_saved,
cur_stack_size,
) {
csiz length1 load_target1;
csiz length2 load_target2;

addi heap_alloc_size zero i32;
aloc heap_alloc_size;
mcp hp load_target2 heap_alloc_size;
move load_target2_heap hp;

move ssp_saved ssp;

sub cur_stack_size sp ssp;
cfs cur_stack_size;

ldc load_target1 zero length1 i0;
ldc load_target2_heap zero length2 i0;

addi heap_alloc_size zero i64;
aloc heap_alloc_size;
sw hp ssp_saved i0;
}
__jmp_mem()
}
32 changes: 6 additions & 26 deletions test/src/sdk-harness/test_projects/run_external_proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ abigen!(Contract(
async fn run_external_can_proxy_call() {
let wallet = launch_provider_and_get_wallet().await.unwrap();

let target_id1 = Contract::load_from(
"test_projects/run_external_target/out/release/part-1.bin",
let target_id = Contract::load_from(
"test_projects/run_external_target/out/release/run_external_target.bin",
LoadConfiguration::default()
.with_storage_configuration(StorageConfiguration::default().with_autoload(false)),
)
Expand All @@ -19,22 +19,8 @@ async fn run_external_can_proxy_call() {
.await
.unwrap();

let target_id2 = Contract::load_from(
"test_projects/run_external_target/out/release/part-2.bin",
LoadConfiguration::default()
.with_storage_configuration(StorageConfiguration::default().with_autoload(false)),
)
.unwrap()
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();

dbg!(&target_id1, &target_id2);

let configurables = RunExternalProxyContractConfigurables::default()
.with_TARGET_1(target_id1.clone().into())
.unwrap()
.with_TARGET_2(target_id2.clone().into())
.with_TARGET(target_id.clone().into())
.unwrap();
let id = Contract::load_from(
"test_projects/run_external_proxy/out/release/run_external_proxy.bin",
Expand All @@ -44,17 +30,15 @@ async fn run_external_can_proxy_call() {
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();

let instance = RunExternalProxyContract::new(id.clone(), wallet);

// Call "large_value"
// Will call run_external_proxy::large_value
// that will call run_external_target::large_value
// and return the value doubled.
let result = instance
.methods()
.large_value()
.with_contract_ids(&[target_id1.clone().into(), target_id2.clone().into()])
.with_contract_ids(&[target_id.clone().into()])
.call()
.await
.unwrap();
Expand All @@ -67,7 +51,6 @@ async fn run_external_can_proxy_call() {
print!("{:?} ", s);
}
}

println!("{:?}", data);
}
}
Expand All @@ -78,15 +61,14 @@ async fn run_external_can_proxy_call() {
Bits256::from_hex_str("0x00000000000000000000000059F2f1fCfE2474fD5F0b9BA1E73ca90b143Eb8d0")
.unwrap();
assert_eq!(result.value, expected_large);

// Call "double_value"
// Will call run_external_proxy::double_value
// that will call run_external_target::double_value
// and return the value doubled.
let result = instance
.methods()
.double_value(42)
.with_contract_ids(&[target_id1.clone().into(), target_id2.clone().into()])
.with_contract_ids(&[target_id.clone().into()])
.call()
.await
.unwrap();
Expand All @@ -99,23 +81,21 @@ async fn run_external_can_proxy_call() {
print!("{:?} ", s);
}
}

println!("{:?}", data);
}
}
_ => {}
}
}
assert_eq!(result.value, 84);

// Call "does_not_exist_in_the_target"
// Will call run_external_proxy::does_not_exist_in_the_target
// it will proxy the call to run_external_target,
// and endup in the fallback, fn that will triple the input value
let result = instance
.methods()
.does_not_exist_in_the_target(42)
.with_contract_ids(&[target_id1.into(), target_id2.into()])
.with_contract_ids(&[target_id.into()])
.call()
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
contract;

use std::execution::run_external2;
use std::execution::run_external;

configurable {
TARGET_1: ContractId = ContractId::zero(),
TARGET_2: ContractId = ContractId::zero(),
TARGET: ContractId = ContractId::zero(),
}

abi RunExternalTest {
fn double_value(foo: u64) -> u64;
fn large_value() -> b256;
fn does_not_exist_in_the_target(foo: u64) -> u64;
}

impl RunExternalTest for Contract {
fn double_value(_foo: u64) -> u64 {
__log(1);
run_external2(TARGET_1, TARGET_2)
run_external(TARGET)
}

fn large_value() -> b256 {
run_external2(TARGET_1, TARGET_2)
run_external(TARGET)
}

// ANCHOR: does_not_exist_in_the_target
fn does_not_exist_in_the_target(_foo: u64) -> u64 {
run_external2(TARGET_1, TARGET_2)
run_external(TARGET)
}
// ANCHOR_END: does_not_exist_in_the_target
}
}

0 comments on commit 1d55638

Please sign in to comment.