Hi,
I’m trying to read contract’s bytecode from another contract and I’m getting a “MemoryOverflow” revert on the my TX.
This is my contract:
contract;
abi Counter {
fn get_first_8_bytes(contract_id: ContractId) -> [u8; 8];
}
impl Counter for Contract {
fn get_first_8_bytes(contract_id: ContractId) -> [u8; 8] {
let mut bytecode_array: [u8; 8] = [0; 8];
let mut counter = 0;
while counter < 2 {
bytecode_array[counter] = _get_bytecode_byte_at(contract_id, counter);
counter += 1;
}
bytecode_array
}
}
fn _get_bytecode_byte_at(contract_id: ContractId, pos: u64) -> u8 {
let mut bytecode: u8 = 0;
let amount = 1;
asm(target: contract_id, bt: &bytecode, pos: pos, amount: amount) {
ccp bt target pos amount;
}
bytecode
}
It only doesn’t work on my local node and I’m getting the following error:
Transaction(Reverted { reason: "MemoryOverflow", revert_id: 0, receipts: [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 39f7d6002550e17e713ea3e329fbcd967848f3d7e6b959786f929aefb5b4f165, amount: 0, asset_id: f8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07, gas: 377745, param1: 10480, param2: 10505, pc: 11960, is: 11960 }, Panic { id: 39f7d6002550e17e713ea3e329fbcd967848f3d7e6b959786f929aefb5b4f165, reason: PanicInstruction { reason: MemoryOverflow, instruction: CCP { dst_addr: 0x13, contract_id_addr: 0x10, offset: 0x11, len: 0x14 } (bytes: 2e 4d 04 54) }, pc: 18632, is: 11960, contract_id: None }, ScriptResult { result: Panic, gas_used: 24382 }] })
We can see that it points to the CCP instruction above.
When I run the harness test on the testnet the TX succeeds and I’m getting the value out:
running 1 test
Bytecode: [26, 240, 0, 0, 0, 0, 0, 0]
Gas used: 21243
This is my harness function:
#[tokio::test]
async fn test_bytecode() {
let (_instance1, id1) = get_contract_instance().await;
let (instance2, _id2) = get_contract_instance().await;
let bech32_id1 = Bech32ContractId::from(id1);
let result = instance2
.methods()
.get_first_8_bytes(id1)
.with_tx_policies(
TxPolicies::default()
.with_script_gas_limit(400000)
)
.with_contract_ids(&[bech32_id1])
.call()
.await
.unwrap();
println!("Bytecode: {:?}", result.value);
println!("Gas used: {}", result.gas_used);
}
Could this be something wrong with my local node configuration?