Skip to content

Commit

Permalink
fix: internal audit issues (#335)
Browse files Browse the repository at this point in the history
* fix: audit issues

* fix: fix mockdapp test
  • Loading branch information
ibrizsabin authored Jun 25, 2024
1 parent c71f4f7 commit 7a180af
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 116 deletions.
3 changes: 2 additions & 1 deletion contracts/sui/mock_dapp/tests/mock_dapp_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module mock_dapp::mock_dapp_tests {
fun setup_connection(admin:address,mut scenario:Scenario):Scenario {
let mut xcall_state= scenario.take_shared<XCallState>();
let adminCap=scenario.take_from_sender<AdminCap>();
xcall::register_connection(&mut xcall_state,&adminCap,string::utf8(b"netid"),string::utf8(b"centralized-1"),admin,scenario.ctx());
xcall::register_connection_admin(&mut xcall_state,&adminCap,string::utf8(b"centralized-1"),admin,scenario.ctx());
xcall::set_default_connection(&mut xcall_state,&adminCap,string::utf8(b"netid"),string::utf8(b"centralized-1"),scenario.ctx());
test_scenario::return_shared<XCallState>(xcall_state);
scenario.return_to_sender(adminCap);
scenario.next_tx(admin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ module xcall::centralized_state {
sn
}

public fun get_fee(self: &State, netId: &String, response: bool): u64 {
let fee: u64 = if (response == true) {
public fun get_fee(self: &State, netId: &String, need_response: bool): u64 {
let fee: u64 = if (need_response == true) {
utils::get_or_default(&self.message_fee, netId, 0)
+ utils::get_or_default(&self.response_fee, netId, 0)
} else {
Expand Down
55 changes: 25 additions & 30 deletions contracts/sui/xcall/sources/connections.move
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
#[allow(unused_field,unused_use,unused_const,unused_mut_parameter,unused_variable,unused_assignment)]
module xcall::connections{
use std::string::{Self, String};
use sui::bag::{Bag, Self};
use xcall::centralized_connection::{Self};
use xcall::centralized_state::{Self,State};
use xcall::xcall_state::{ConnCap};

use sui::coin::{Self,Coin};
use std::string::{Self, String};
use sui::bag::{Bag, Self};
use xcall::centralized_connection::{Self};
use xcall::centralized_state::{Self,State};
use xcall::xcall_state::{ConnCap};
use sui::coin::{Self,Coin};
use sui::balance::{Self, Balance};
use sui::sui::SUI;


const EConnectionNotFound:u64=0;

const ConnCentralized:vector<u8> =b"centralized";


const EConnectionNotFound:u64=0;
const ConnCentralized:vector<u8> =b"centralized";


public(package) fun register(states:&mut Bag,connection_id:String,ctx:&mut TxContext){

if (get_connection_type(&connection_id).bytes()==ConnCentralized){
let state= centralized_connection::connect();
bag::add(states, connection_id, state);
let state= centralized_connection::connect();
bag::add(states, connection_id, state);
}else{
abort EConnectionNotFound
abort EConnectionNotFound
}


}

public(package) fun get_fee(states:&Bag,connection_id:String,netId:String,response:bool):u64{
public(package) fun get_fee(states:&Bag,connection_id:String,netId:String,response:bool):u64{

if (get_connection_type(&connection_id).bytes()==ConnCentralized){
let fee= centralized_connection::get_fee(states,connection_id,netId,response);
fee
}else{
abort EConnectionNotFound
abort EConnectionNotFound
}
}

public(package) fun send_message(states:&mut Bag,
connection_id:String,
coin:Coin<SUI>,
netId:String,
sn:u128,
msg:vector<u8>,
is_response:bool,
ctx:&mut TxContext){
if (get_connection_type(&connection_id).bytes()==ConnCentralized){
public(package) fun send_message(states:&mut Bag,
connection_id:String,
coin:Coin<SUI>,
netId:String,
sn:u128,
msg:vector<u8>,
is_response:bool,
ctx:&mut TxContext){

if (get_connection_type(&connection_id).bytes()==ConnCentralized){
centralized_connection::send_message(states,connection_id,coin,netId,sn,msg,is_response,ctx);
}else{
abort EConnectionNotFound
abort EConnectionNotFound
}
}

Expand Down
Loading

0 comments on commit 7a180af

Please sign in to comment.