enigma-core icon indicating copy to clipboard operation
enigma-core copied to clipboard

System error if wrong contract address is passed to the secret contract computation

Open moriaab opened this issue 6 years ago • 0 comments

Description Currently, when core gets a computation for a non-existent secret contract address, it throws an error saying that's missing the "State Keys" but does not return a proper "Failed Compute" result, so that it never reaches p2p. This should be corrected.

To Reproduce

  1. Create the following test in /enigma-core/app/src/wasm_u/wasm.rs:
   #[test]
    fn non_existent_contract_address() {
        let (mut db, _dir) = create_test_db();
        let contract_address = generate_contract_address();
        let non_existent_contract_address = generate_contract_address();

        let enclave = init_enclave_wrapper().unwrap();
        instantiate_encryption_key(vec![contract_address], enclave.geteid());

        let (keys, shared_key, _, _) = exchange_keys(enclave.geteid());
        let encrypted_construct = symmetric::encrypt("construct()".as_bytes(), &shared_key).unwrap();
        let encrypted_args = symmetric::encrypt(&ethabi::encode(&[]), &shared_key).unwrap();

        let deploy_res = compile_and_deploy_wasm_contract(
                &mut db,
                enclave.geteid(),
                "../../examples/eng_wasm_contracts/flip_coin",
                contract_address,
                &encrypted_construct,
                &encrypted_args,
                &keys.get_pubkey()
            ).unwrap_result();

        let exe_code = deploy_res.output;
        let (keys, shared_key, _, _) = exchange_keys(enclave.geteid());
        let encrypted_callable = symmetric::encrypt("flip()".as_bytes(), &shared_key).unwrap();
        let encrypted_args = symmetric::encrypt(&ethabi::encode(&[]), &shared_key).unwrap();

        // Execute the contract with wrong address
        let result = wasm::execute(
                &mut db,
                enclave.geteid(),
                &exe_code,
                &encrypted_callable,
                &encrypted_args,
                &keys.get_pubkey(),
                &non_existent_contract_address,
                GAS_LIMIT
            ).expect("Execution failed").unwrap_result();

    }
  1. Run the test
  2. See the system error: Execution failed: EnclaveFailError { err: KeysError, status: SGX_SUCCESS }'

Expected behavior Return to the user the error message about wrong contract address.

moriaab avatar Apr 28 '19 09:04 moriaab