Skip to content
This repository has been archived by the owner on Jun 21, 2020. It is now read-only.

A redeployment of an existing contract fails with Missing State Key #114

Closed
lacabra opened this issue Apr 5, 2019 · 5 comments
Closed

Comments

@lacabra
Copy link
Contributor

lacabra commented Apr 5, 2019

Describe the bug
A second attempt to redeploy a contract, regardless of whether the first one succeeded or failed (as in #113), errors out with Cryptography Error: MissingKeyError { key_type: "State Key" }. This seems to have nothing to do with core 's ability to request the right state keys from the Key Management node, as this behavior can be observed when the 1st and 2nd deployment happen in the same epoch, when the state keys should be arguably the same.

To Reproduce

  1. Deploy one valid secret contract, that succeeds.
  2. Attempt to redeploy the very same contract.

Expected behavior
If a contract exists at a given address, it should error out with a relevant message.

This opens the question on whether two different people cannot deploy the same contract with the same address that is derived from the same preCode

Backtrace

core_1        | Error in deployment of smart contract function: Cryptography Error: MissingKeyError { key_type: "State Key" }
core_1        | 06:42:57 [INFO] LOG DERIVE: Err(EnclaveFailError { err: KeysError, status: SGX_SUCCESS }
core_1        | 
core_1        | stack backtrace:
core_1        |    0: failure::backtrace::internal::InternalBacktrace::new::h0c85aeebdcdd7156 (0x56077d40376e)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/backtrace/internal.rs:44
core_1        |    1: failure::backtrace::Backtrace::new::hb2072042fb7e0676 (0x56077d40323d)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/backtrace/mod.rs:111
core_1        |    2: <failure::error::error_impl::ErrorImpl as core::convert::From<F>>::from::h884f71c8d4fc0d7b (0x56077ccc4cb2)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/error/error_impl.rs:19
core_1        |    3: <failure::error::Error as core::convert::From<F>>::from::h2322150188ad4903 (0x56077cc0eac8)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/error/mod.rs:36
core_1        |    4: <T as core::convert::Into<U>>::into::hae9d1a181fbb5063 (0x56077cc94c38)
core_1        |              at libcore/convert.rs:456
core_1        |    5: <enigma_core_app::wasm_u::WasmResult as core::convert::TryFrom<(enigma_types::types::ExecuteResult, enigma_types::hash::Hash256, enigma_types::types::EnclaveReturn, sgx_types::error::sgx_status_t)>>::try_from::hd1482c277b1f2b9a (0x56077ccceffb)
core_1        |              at src/wasm_u/mod.rs:100
core_1        |    6: <T as core::convert::TryInto<U>>::try_into::h6619c98f67a049f3 (0x56077cccdace)
core_1        |              at libcore/convert.rs:474
core_1        |    7: enigma_core_app::wasm_u::wasm::deploy::{{closure}}::hc2f875e7975caada (0x56077ccd552c)
core_1        |              at src/wasm_u/wasm.rs:49
core_1        |    8: enigma_core_app::wasm_u::wasm::deploy::h051d82273f6610b3 (0x56077cca4530)
core_1        |              at src/wasm_u/wasm.rs:27
core_1        |    9: enigma_core_app::networking::ipc_listener::handling::deploy_contract::{{closure}}::he9bae77b29db796c (0x56077cc1e4f1)
core_1        |              at src/networking/ipc_listener.rs:307
core_1        |   10: enigma_core_app::networking::ipc_listener::handling::deploy_contract::h2667e8963674a2af (0x56077cccad0d)
core_1        |              at src/networking/ipc_listener.rs:307
core_1        |   11: enigma_core_app::networking::ipc_listener::handle_message::h1750df4bf26872f3 (0x56077cc0fb10)
core_1        |              at src/networking/ipc_listener.rs:48
core_1        |   12: enigma_core_app::main::{{closure}}::hf35b7eb5da2211fb (0x56077cba7814)
core_1        |              at src/main.rs:35
core_1        |   13: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once::h0a1b12463a3b99c4 (0x56077cba76da)
core_1        |              at libcore/ops/function.rs:286
core_1        |   14: <core::option::Option<T>>::map::h32de77ba92ca6014 (0x56077cba5fbc)
core_1        |              at libcore/option.rs:424
core_1        |   15: <futures::stream::map::Map<S, F> as futures::stream::Stream>::poll::h020ec7812c81f167 (0x56077cbc7d8a)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/stream/map.rs:79
core_1        |   16: <futures::stream::forward::Forward<T, U> as futures::future::Future>::poll::h9f24ac433f8d0533 (0x56077cbb5433)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/stream/forward.rs:94
core_1        |   17: <futures::future::map::Map<A, F> as futures::future::Future>::poll::hedf6c26bce1e517a (0x56077cbbf4cd)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/map.rs:30
core_1        |   18: <futures::future::chain::Chain<A, B, C>>::poll::h9a56683a803d98e6 (0x56077cbcbca5)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/chain.rs:32
core_1        |   19: <futures::future::and_then::AndThen<A, B, F> as futures::future::Future>::poll::h476e6dd9a7af70c0 (0x56077cbb27f9)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/and_then.rs:32
core_1        |   20: <futures::task_impl::Spawn<T>>::poll_future_notify::{{closure}}::h8aac65f6c2b28787 (0x56077cba3769)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:329
core_1        |   21: <futures::task_impl::Spawn<T>>::enter::{{closure}}::h0dcbd4cb7cf055a1 (0x56077cba38e6)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:399
core_1        |   22: futures::task_impl::std::set::h42825b196f346936 (0x56077cbc6fec)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:78
core_1        |   23: <futures::task_impl::Spawn<T>>::enter::h73545ec010aa3483 (0x56077cba3872)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:399
core_1        |   24: <futures::task_impl::Spawn<T>>::poll_fn_notify::hbab32881f8f24cdd (0x56077cba3694)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:291
core_1        |   25: <futures::task_impl::Spawn<T>>::poll_future_notify::h7d6ea848a1928f74 (0x56077cba373d)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:329
core_1        |   26: futures::task_impl::std::<impl futures::task_impl::Spawn<F>>::wait_future::{{closure}}::h007f83165af89296 (0x56077cbc70c8)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:231
core_1        |   27: futures::task_impl::std::ThreadNotify::with_current::{{closure}}::h2a26e648c9ac6231 (0x56077cbc6efe)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:478
core_1        |   28: <std::thread::local::LocalKey<T>>::try_with::h2a5cc9a7429097dd (0x56077cba58f3)
core_1        |              at libstd/thread/local.rs:294
core_1        |   29: <std::thread::local::LocalKey<T>>::with::hc1a5d9c54e7a9872 (0x56077cba56f0)
core_1        |              at libstd/thread/local.rs:248
core_1        |   30: futures::task_impl::std::ThreadNotify::with_current::hd3630610c1e4cdc4 (0x56077cbc6ebd)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:478
core_1        |   31: futures::task_impl::std::<impl futures::task_impl::Spawn<F>>::wait_future::h9b449006e78c92e2 (0x56077cba3913)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:228
core_1        |   32: futures::future::Future::wait::h65ec1379a489e9f4 (0x56077cbb29f1)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/mod.rs:299
core_1        |   33: enigma_core_app::main::h51e5e13b67620211 (0x56077cbb0034)
core_1        |              at src/main.rs:34
core_1        |   34: std::rt::lang_start::{{closure}}::hf50adf6ebd355f61 (0x56077cbb93bf)
core_1        |              at libstd/rt.rs:74
core_1        |   35: std::rt::lang_start_internal::{{closure}}::hdc2a896aeffb5179 (0x56077d5447d2)
core_1        |              at libstd/rt.rs:59
core_1        |       std::panicking::try::do_call::h5a4eb2ce70a501f5
core_1        |              at libstd/panicking.rs:310
core_1        |   36: __rust_maybe_catch_panic (0x56077d565729)
core_1        |              at libpanic_unwind/lib.rs:102
core_1        |   37: std::panicking::try::h97436c380f30f437 (0x56077d546c95)
core_1        |              at libstd/panicking.rs:289
core_1        |       std::panic::catch_unwind::h9c28ef6e0c478c5d
core_1        |              at libstd/panic.rs:392
core_1        |       std::rt::lang_start_internal::h6abd6befa9748e41
core_1        |              at libstd/rt.rs:58
core_1        |   38: std::rt::lang_start::h28de98d2c46239d3 (0x56077cbb9397)
core_1        |              at libstd/rt.rs:74
core_1        |   39: main (0x56077cbb01c9)
core_1        |   40: __libc_start_main (0x7f68da613b96)
core_1        |   41: _start (0x56077cba29d9)
core_1        |   42: <unknown> (0x0))
core_1        | 06:42:57 [ERROR] Unwrapped p2p Message failed: EnclaveFailError { err: KeysError, status: SGX_SUCCESS }
core_1        | 
core_1        | stack backtrace:
core_1        |    0: failure::backtrace::internal::InternalBacktrace::new::h0c85aeebdcdd7156 (0x56077d40376e)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/backtrace/internal.rs:44
core_1        |    1: failure::backtrace::Backtrace::new::hb2072042fb7e0676 (0x56077d40323d)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/backtrace/mod.rs:111
core_1        |    2: <failure::error::error_impl::ErrorImpl as core::convert::From<F>>::from::h884f71c8d4fc0d7b (0x56077ccc4cb2)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/error/error_impl.rs:19
core_1        |    3: <failure::error::Error as core::convert::From<F>>::from::h2322150188ad4903 (0x56077cc0eac8)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.5/src/error/mod.rs:36
core_1        |    4: <T as core::convert::Into<U>>::into::hae9d1a181fbb5063 (0x56077cc94c38)
core_1        |              at libcore/convert.rs:456
core_1        |    5: <enigma_core_app::wasm_u::WasmResult as core::convert::TryFrom<(enigma_types::types::ExecuteResult, enigma_types::hash::Hash256, enigma_types::types::EnclaveReturn, sgx_types::error::sgx_status_t)>>::try_from::hd1482c277b1f2b9a (0x56077ccceffb)
core_1        |              at src/wasm_u/mod.rs:100
core_1        |    6: <T as core::convert::TryInto<U>>::try_into::h6619c98f67a049f3 (0x56077cccdace)
core_1        |              at libcore/convert.rs:474
core_1        |    7: enigma_core_app::wasm_u::wasm::deploy::{{closure}}::hc2f875e7975caada (0x56077ccd552c)
core_1        |              at src/wasm_u/wasm.rs:49
core_1        |    8: enigma_core_app::wasm_u::wasm::deploy::h051d82273f6610b3 (0x56077cca4530)
core_1        |              at src/wasm_u/wasm.rs:27
core_1        |    9: enigma_core_app::networking::ipc_listener::handling::deploy_contract::{{closure}}::he9bae77b29db796c (0x56077cc1e4f1)
core_1        |              at src/networking/ipc_listener.rs:307
core_1        |   10: enigma_core_app::networking::ipc_listener::handling::deploy_contract::h2667e8963674a2af (0x56077cccad0d)
core_1        |              at src/networking/ipc_listener.rs:307
core_1        |   11: enigma_core_app::networking::ipc_listener::handle_message::h1750df4bf26872f3 (0x56077cc0fb10)
core_1        |              at src/networking/ipc_listener.rs:48
core_1        |   12: enigma_core_app::main::{{closure}}::hf35b7eb5da2211fb (0x56077cba7814)
core_1        |              at src/main.rs:35
core_1        |   13: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once::h0a1b12463a3b99c4 (0x56077cba76da)
core_1        |              at libcore/ops/function.rs:286
core_1        |   14: <core::option::Option<T>>::map::h32de77ba92ca6014 (0x56077cba5fbc)
core_1        |              at libcore/option.rs:424
core_1        |   15: <futures::stream::map::Map<S, F> as futures::stream::Stream>::poll::h020ec7812c81f167 (0x56077cbc7d8a)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/stream/map.rs:79
core_1        |   16: <futures::stream::forward::Forward<T, U> as futures::future::Future>::poll::h9f24ac433f8d0533 (0x56077cbb5433)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/stream/forward.rs:94
core_1        |   17: <futures::future::map::Map<A, F> as futures::future::Future>::poll::hedf6c26bce1e517a (0x56077cbbf4cd)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/map.rs:30
core_1        |   18: <futures::future::chain::Chain<A, B, C>>::poll::h9a56683a803d98e6 (0x56077cbcbca5)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/chain.rs:32
core_1        |   19: <futures::future::and_then::AndThen<A, B, F> as futures::future::Future>::poll::h476e6dd9a7af70c0 (0x56077cbb27f9)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/and_then.rs:32
core_1        |   20: <futures::task_impl::Spawn<T>>::poll_future_notify::{{closure}}::h8aac65f6c2b28787 (0x56077cba3769)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:329
core_1        |   21: <futures::task_impl::Spawn<T>>::enter::{{closure}}::h0dcbd4cb7cf055a1 (0x56077cba38e6)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:399
core_1        |   22: futures::task_impl::std::set::h42825b196f346936 (0x56077cbc6fec)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:78
core_1        |   23: <futures::task_impl::Spawn<T>>::enter::h73545ec010aa3483 (0x56077cba3872)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:399
core_1        |   24: <futures::task_impl::Spawn<T>>::poll_fn_notify::hbab32881f8f24cdd (0x56077cba3694)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:291
core_1        |   25: <futures::task_impl::Spawn<T>>::poll_future_notify::h7d6ea848a1928f74 (0x56077cba373d)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/mod.rs:329
core_1        |   26: futures::task_impl::std::<impl futures::task_impl::Spawn<F>>::wait_future::{{closure}}::h007f83165af89296 (0x56077cbc70c8)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:231
core_1        |   27: futures::task_impl::std::ThreadNotify::with_current::{{closure}}::h2a26e648c9ac6231 (0x56077cbc6efe)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:478
core_1        |   28: <std::thread::local::LocalKey<T>>::try_with::h2a5cc9a7429097dd (0x56077cba58f3)
core_1        |              at libstd/thread/local.rs:294
core_1        |   29: <std::thread::local::LocalKey<T>>::with::hc1a5d9c54e7a9872 (0x56077cba56f0)
core_1        |              at libstd/thread/local.rs:248
core_1        |   30: futures::task_impl::std::ThreadNotify::with_current::hd3630610c1e4cdc4 (0x56077cbc6ebd)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:478
core_1        |   31: futures::task_impl::std::<impl futures::task_impl::Spawn<F>>::wait_future::h9b449006e78c92e2 (0x56077cba3913)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/task_impl/std/mod.rs:228
core_1        |   32: futures::future::Future::wait::h65ec1379a489e9f4 (0x56077cbb29f1)
core_1        |              at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.26/src/future/mod.rs:299
core_1        |   33: enigma_core_app::main::h51e5e13b67620211 (0x56077cbb0034)
core_1        |              at src/main.rs:34
core_1        |   34: std::rt::lang_start::{{closure}}::hf50adf6ebd355f61 (0x56077cbb93bf)
core_1        |              at libstd/rt.rs:74
core_1        |   35: std::rt::lang_start_internal::{{closure}}::hdc2a896aeffb5179 (0x56077d5447d2)
core_1        |              at libstd/rt.rs:59
core_1        |       std::panicking::try::do_call::h5a4eb2ce70a501f5
core_1        |              at libstd/panicking.rs:310
core_1        |   36: __rust_maybe_catch_panic (0x56077d565729)
core_1        |              at libpanic_unwind/lib.rs:102
core_1        |   37: std::panicking::try::h97436c380f30f437 (0x56077d546c95)
core_1        |              at libstd/panicking.rs:289
core_1        |       std::panic::catch_unwind::h9c28ef6e0c478c5d
core_1        |              at libstd/panic.rs:392
core_1        |       std::rt::lang_start_internal::h6abd6befa9748e41
core_1        |              at libstd/rt.rs:58
core_1        |   38: std::rt::lang_start::h28de98d2c46239d3 (0x56077cbb9397)
core_1        |              at libstd/rt.rs:74
core_1        |   39: main (0x56077cbb01c9)
core_1        |   40: __libc_start_main (0x7f68da613b96)
core_1        |   41: _start (0x56077cba29d9)
core_1        |   42: <unknown> (0x0)
@elichai
Copy link
Contributor

elichai commented Apr 6, 2019

Did you redo the PTT with the new address?
Core needs to get the key for the contract.

@lacabra
Copy link
Contributor Author

lacabra commented Apr 7, 2019

  • Did you redo the PTT with the new address?
    I don't control the PTT from the client side. In the integration tests I'm only dealing with the functionality that the Enigma.JS provides, and it's not part of the library to trigger or manage the PTT. The network should handle it automatically.

As far as I understand, the P2P subscribes to epoch changes, and that's the only time when it triggers PTT requests to/from core. @lenak25 and @fredfortier can confirm.

Shouldn't it be core 's responsibility to request keys if it realizes it's missing them for a deploy/compute request it receives? Because these requests come already validated by P2P that are indeed directed to that instance of core, so if at that point core is missing some state keys, shouldn't it do something about it?

cc:@moria

@elichai
Copy link
Contributor

elichai commented Apr 7, 2019

No. If there's a new contract in the middle of the epoch it should be the p2p responsibility to initiate a new PTT.
core has no sense of epochs etc.

@lacabra
Copy link
Contributor Author

lacabra commented Apr 7, 2019

Well, then I would like @lenak25 and @Isan-Rivkin to comment on this.

@lacabra
Copy link
Contributor Author

lacabra commented Apr 10, 2019

Similar to #113, I had misidentified this issue as well, and the underlying issue is in the P2P repo as reported here: GetStateKeys before deploying a contract

So closing this issue in favor of the issue reported in P2P.

@lacabra lacabra closed this as completed Apr 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants