Skip to content

Commit

Permalink
fix: Fix debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfschoen committed Dec 21, 2024
1 parent e4f287b commit 1446e7a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
8 changes: 4 additions & 4 deletions _QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
# UPDATE IF DIFFERS deploy.ts

```bash
docker exec -it secretdev secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt
y
docker exec -it secretdev secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt -y

docker exec -it secretdev secretcli query bank balances secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg | jq
```

Expand Down Expand Up @@ -162,8 +162,8 @@ scp -r $SOURCE root@$REMOTE_IP:$DESTINATION
```

```bash
docker exec -it secretdev secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt
y
docker exec -it secretdev secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt -y

docker exec -it secretdev secretcli query bank balances secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg | jq
```

Expand Down
4 changes: 2 additions & 2 deletions _SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ cd SecretPath/TNLS-Relayers
* Note: We need the 300000uscrt to process the broadcast the `requestValue` transaction from the relayer, so give them more than that.
* Note: If you forget to do this before running the relayer, then you might get error `[SCRT Interface: ERROR] Failed to fetch account info: HTTP 404`
```
secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt
y
secretcli tx bank send secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03 secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg 100000000000000000uscrt -y

secretcli query bank balances secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg | jq
```
Expand Down
2 changes: 1 addition & 1 deletion packages/secret-contracts-scripts/src/config/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const config = {
endpoint: process.env.ENDPOINT_LOCAL,
secretNunya: {
nunyaContractCodeId: "2", // only know after upload
nunyaContractCodeHash: "9cbd5742b70a5f6f94f93bc2a31f9c8e8b27c011d4782f18131e11e72ffe1655", // only know after upload
nunyaContractCodeHash: "37bf978b95a5fb3aa60799ab8be8be410d9da9cb291c40c3dc3e0d110a5fca66", // only know after upload
nunyaContractAddress: "secret1gyruqan6yxf0q423t8z5zce3x7np35uw8s8wqc", // only know after instantiate
nunyaContractWasmPath: "contract.wasm.gz",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub fn instantiate(
owner: info.sender.clone(),
};

deps.api
.debug(format!("Contract was initialized by {}", info.sender).as_str());
deps.api.debug(format!("Contract was initialized by {}", info.sender).as_str());
config(deps.storage).save(&state)?;

Ok(Response::default())
Expand Down
24 changes: 12 additions & 12 deletions packages/secret-contracts/nunya-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ pub fn instantiate(
owner: info.sender.clone(),
};

eprintln!("instantiate");
eprintln!("msg: {:#?}", msg.clone());
eprintln!("info: {:#?}", info.clone());
eprintln!("state: {:#?}", state.clone());
deps.api.debug(format!("instantiate").as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());
deps.api.debug(format!("info: {:#?}", info.clone()).as_str());
deps.api.debug(format!("state: {:#?}", state.clone()).as_str());

deps.api
.debug(format!("Contract was initialized by {}", info.sender).as_str());
deps.api.debug(format!("Contract was initialized by {}", info.sender).as_str());

CONFIG.save(deps.storage, &state)?;

Expand Down Expand Up @@ -96,9 +95,9 @@ fn try_handle(
// verify signature with stored gateway public key
let config = CONFIG.load(deps.storage)?;

eprintln!("try_handle");
eprintln!("msg: {:#?}", msg.clone());
eprintln!("info: {:#?}", info.clone());
deps.api.debug(format!("try_handle").as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());
deps.api.debug(format!("info: {:#?}", info.clone()).as_str());

// Security
//
Expand All @@ -119,6 +118,7 @@ fn try_handle(
// ));
// }

// FIXME: Generic error: Invalid public key format
deps.api
.secp256k1_verify(
msg.input_hash.as_slice(),
Expand All @@ -130,8 +130,8 @@ fn try_handle(
// determine which function to call based on the included handle
let handle = msg.handle.as_str();

eprintln!("try_handle");
eprintln!("handle: {:#?}", handle);
deps.api.debug(format!("try_handle").as_str());
deps.api.debug(format!("handle: {:#?}", handle).as_str());

match handle {
// TODO: change all below to snake_case if required for Gateway contract to be able to call.
Expand Down Expand Up @@ -165,7 +165,7 @@ fn request_value(
.map_err(|err| StdError::generic_err(err.to_string()))?;

let my_arg = input.myArg;
eprintln!("request_value: input.myArg {:#?}", input.myArg);
deps.api.debug(format!("request_value: input.myArg {:#?}", input.myArg).as_str());

let response_status_code: ResponseStatusCode = 0u16;

Expand Down
88 changes: 44 additions & 44 deletions packages/secret-contracts/secret-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ pub fn instantiate(
signing_keys: KeyPair::default(),
};

eprintln!("instantiate");
eprintln!("msg: {:#?}", msg.clone());
eprintln!("info: {:#?}", info.clone());
deps.api.debug(format!("instantiate").as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());
deps.api.debug(format!("info: {:#?}", info.clone()).as_str());

CONFIG.save(deps.storage, &state)?;

Expand All @@ -90,9 +90,9 @@ pub fn instantiate(
///
#[entry_point]
pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
eprintln!("execute");
eprintln!("msg: {:#?}", msg.clone());
eprintln!("info: {:#?}", info.clone());
deps.api.debug(format!("execute").as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());
deps.api.debug(format!("info: {:#?}", info.clone()).as_str());

let response = match msg {
ExecuteMsg::Input { inputs } => pre_execution(deps, env, inputs),
Expand All @@ -115,10 +115,10 @@ fn rotate_gateway_keys(deps: DepsMut, env: Env, info: MessageInfo) -> StdResult<

let caller_raw = deps.api.addr_canonicalize(info.sender.as_str())?;

eprintln!("rotate_gateway_keys");
eprintln!("caller: {:#?}", caller_raw.clone());
eprintln!("state: {:#?}", state.clone());
eprintln!("info: {:#?}", info.clone());
deps.api.debug(format!("rotate_gateway_keys").as_str());
deps.api.debug(format!("caller: {:#?}", caller_raw.clone()).as_str());
deps.api.debug(format!("state: {:#?}", state.clone()).as_str());
deps.api.debug(format!("info: {:#?}", info.clone()).as_str());

// check if the keys have already been created
if state.keyed {
Expand Down Expand Up @@ -164,8 +164,8 @@ fn create_gateway_keys(deps: DepsMut, env: Env) -> StdResult<Response> {
// load config
let state = CONFIG.load(deps.storage)?;

eprintln!("create_gateway_keys");
eprintln!("state: {:#?}", state.clone());
deps.api.debug(format!("create_gateway_keys").as_str());
deps.api.debug(format!("state: {:#?}", state.clone()).as_str());

// check if the keys have already been created
if state.keyed {
Expand Down Expand Up @@ -207,9 +207,9 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
// load config
let config = CONFIG.load(deps.storage)?;

eprintln!("pre_execution");
eprintln!("config: {:#?}", config.clone());
eprintln!("msg: {:#?}", msg.clone());
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("config: {:#?}", config.clone()).as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());

// Check if the payload matches the payload hash for Solana
let mut hasher = Keccak256::new();
Expand All @@ -231,7 +231,7 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
if msg.payload_hash.as_slice() != payload_hash_tmp_eth.as_slice()
&& msg.payload_hash.as_slice() != payload_hash_tmp_solana.as_slice()
{
eprintln!("Hashed Payload does not match payload hash");
deps.api.debug(format!("Hashed Payload does not match payload hash").as_str());
return Err(StdError::generic_err(
"Hashed Payload does not match payload hash",
));
Expand All @@ -250,15 +250,15 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
unsafe_payload = false;
// Both decryption and verification succeeded

eprintln!("pre_execution");
eprintln!("Both decryption and verification succeeded");
eprintln!("decrypted_payload: {:#?}", decrypted_payload.clone());
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("Both decryption and verification succeeded").as_str());
deps.api.debug(format!("decrypted_payload: {:#?}", decrypted_payload.clone()).as_str());

decrypted_payload
}
Err(err) => {
eprintln!("pre_execution");
eprintln!("Verification failed: {:#?}", err);
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("Verification failed: {:#?}", err).as_str());

//return Err(StdError::generic_err(format!("Verification failed: {}", err)));
// Continue with the decrypted payload if only verification fails
Expand All @@ -267,33 +267,33 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
}
}
Err(err) => {
eprintln!("pre_execution");
eprintln!("Decryption failed: {:#?}", err);
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("Decryption failed: {:#?}", err).as_str());
//return Err(StdError::generic_err(format!("Decryption failed: {}", err)));
// If decryption fails, continue with the original, encrypted payload
// We are not verifying the payload in this case as it's already deemed unsafe
from_binary(&Binary::from(msg.payload.as_slice()))?
}
};

eprintln!("verify the internal verification key matches the user address");
eprintln!("msg.user_key: {:#?}", msg.user_key);
eprintln!("payload.user_key: {:#?}", payload.user_key);
deps.api.debug(format!("verify the internal verification key matches the user address").as_str());
deps.api.debug(format!("msg.user_key: {:#?}", msg.user_key).as_str());
deps.api.debug(format!("payload.user_key: {:#?}", payload.user_key).as_str());

// verify the internal verification key matches the user address
if payload.user_key != msg.user_key {
return Err(StdError::generic_err("verification key mismatch"));
}
eprintln!("verify the routing info matches the internally stored routing info");
eprintln!("msg.routing_info: {:#?}", msg.routing_info);
eprintln!("payload.routing_info: {:#?}", payload.routing_info);
deps.api.debug(format!("verify the routing info matches the internally stored routing info").as_str());
deps.api.debug(format!("msg.routing_info: {:#?}", msg.routing_info).as_str());
deps.api.debug(format!("payload.routing_info: {:#?}", payload.routing_info).as_str());
// verify the routing info matches the internally stored routing info
if msg.routing_info != payload.routing_info {
return Err(StdError::generic_err("routing info mismatch"));
}
eprintln!("verify the callback_gas_limit defined in the payload matches the msg callback_gas_limit");
eprintln!("msg.callback_gas_limit: {:#?}", msg.callback_gas_limit);
eprintln!("payload.callback_gas_limit: {:#?}", payload.callback_gas_limit);
deps.api.debug(format!("verify the callback_gas_limit defined in the payload matches the msg callback_gas_limit").as_str());
deps.api.debug(format!("msg.callback_gas_limit: {:#?}", msg.callback_gas_limit).as_str());
deps.api.debug(format!("payload.callback_gas_limit: {:#?}", payload.callback_gas_limit).as_str());
// verify the callback_gas_limit defined in the payload matches the msg callback_gas_limit
if msg.callback_gas_limit != payload.callback_gas_limit {
return Err(StdError::generic_err("callback gas limit mismatch"));
Expand All @@ -304,8 +304,8 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
task_id: msg.task_id,
};

eprintln!("pre_execution");
eprintln!("new_task: {:#?}", new_task.clone());
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("new_task: {:#?}", new_task.clone()).as_str());

// check if the task wasn't executed before already
let map_contains_task = TASK_MAP.contains(deps.storage, &new_task);
Expand Down Expand Up @@ -350,8 +350,8 @@ fn pre_execution(deps: DepsMut, _env: Env, msg: PreExecutionMsg) -> StdResult<Re
callback_gas_limit: payload.callback_gas_limit,
};

eprintln!("pre_execution");
eprintln!("task_info: {:#?}", task_info.clone());
deps.api.debug(format!("pre_execution").as_str());
deps.api.debug(format!("task_info: {:#?}", task_info.clone()).as_str());

// map task to task info
TASK_MAP.insert(deps.storage, &new_task, &task_info)?;
Expand Down Expand Up @@ -393,13 +393,13 @@ fn post_execution(deps: DepsMut, env: Env, msg: PostExecutionMsg) -> StdResult<R
.get(deps.storage, &msg.task)
.ok_or_else(|| StdError::generic_err("task not found"))?;

eprintln!("post_execution");
eprintln!("msg: {:#?}", msg.clone());
eprintln!("task_info: {:#?}", task_info.clone());
deps.api.debug(format!("post_execution").as_str());
deps.api.debug(format!("msg: {:#?}", msg.clone()).as_str());
deps.api.debug(format!("task_info: {:#?}", task_info.clone()).as_str());

eprintln!("verify that input hash is correct one for Task");
eprintln!("msg.input_hash.as_slice(): {:#?}", msg.input_hash.as_slice());
eprintln!("task_info.input_hash.to_vec(): {:#?}", task_info.input_hash.to_vec());
deps.api.debug(format!("verify that input hash is correct one for Task").as_str());
deps.api.debug(format!("msg.input_hash.as_slice(): {:#?}", msg.input_hash.as_slice()).as_str());
deps.api.debug(format!("task_info.input_hash.to_vec(): {:#?}", task_info.input_hash.to_vec()).as_str());

// verify that input hash is correct one for Task
if msg.input_hash.as_slice() != task_info.input_hash.to_vec() {
Expand Down Expand Up @@ -586,8 +586,8 @@ fn post_execution(deps: DepsMut, env: Env, msg: PostExecutionMsg) -> StdResult<R
callback_gas_limit: callback_gas_limit,
};

eprintln!("post_execution");
eprintln!("result_info: {:#?}", result_info.clone());
deps.api.debug(format!("post_execution").as_str());
deps.api.debug(format!("result_info: {:#?}", result_info.clone()).as_str());

// Store the result info in the result map
RESULT_MAP.insert(deps.storage, &msg.task, &result_info)?;
Expand Down

0 comments on commit 1446e7a

Please sign in to comment.