Open pbeza opened 1 year ago
It turned out that I was missing gcc-multilib
Ubuntu package (all credits goes to @dyxushuai for suggesting that – thanks a lot!). Once I installed it, I progressed to yet different compilation error message:
ubuntu@VM-0-6-ubuntu:~/sgx-revm$ cargo run --release --target x86_64-fortanix-unknown-sgx [328/1981]
Compiling autocfg v1.1.0
Compiling libc v0.2.147
Compiling version_check v0.9.4
Compiling proc-macro2 v1.0.66
Compiling unicode-ident v1.0.11
Compiling typenum v1.16.0
Compiling zeroize v1.6.0
Compiling cfg-if v1.0.0
Compiling subtle v2.5.0
Compiling syn v1.0.109
Compiling const-oid v0.9.5
Compiling serde v1.0.188
Compiling generic-array v0.14.7
Compiling num-traits v0.2.16
Compiling crunchy v0.2.2
Compiling glob v0.3.1
Compiling num-integer v0.1.45
Compiling prettyplease v0.2.12
Compiling rand_core v0.6.4
Compiling quote v1.0.33
Compiling minimal-lexical v0.2.1
Compiling memchr v2.6.2
Compiling clang-sys v1.6.1
Compiling syn v2.0.29
Compiling cc v1.0.83
Compiling byteorder v1.4.3
Compiling regex-syntax v0.7.5
Compiling rustc-hex v2.1.0
Compiling nom v7.1.3
Compiling libloading v0.7.4
Compiling block-buffer v0.10.4
Compiling crypto-common v0.1.6
Compiling digest v0.10.7
Compiling bindgen v0.65.1
Compiling either v1.9.0
Compiling static_assertions v1.1.0
Compiling which v4.4.0
Compiling proc-macro-error-attr v1.0.4
Compiling hex v0.4.3
Compiling lazycell v1.3.0
Compiling crossbeam-utils v0.8.16
Compiling lazy_static v1.4.0
Compiling bitflags v1.3.2
Compiling rustc-hash v1.1.0
Compiling log v0.4.20
Compiling peeking_take_while v0.1.2
Compiling shlex v1.1.0
Compiling uint v0.9.5
Compiling fixed-hash v0.8.0
Compiling cmake v0.1.50
Compiling memoffset v0.9.0
Compiling proc-macro-error v1.0.4
Compiling ahash v0.8.3
Compiling once_cell v1.18.0
Compiling regex-automata v0.3.7
Compiling cexpr v0.6.0
Compiling radium v0.7.0
Compiling primitive-types v0.12.1
Compiling ff v0.13.0
Compiling crossbeam-epoch v0.9.15
Compiling num-bigint v0.4.4
Compiling der v0.7.8
Compiling regex v1.9.4
Compiling convert_case v0.4.0
Compiling base16ct v0.2.0
Compiling ruint-macro v1.1.0
Compiling cpufeatures v0.2.9
Compiling tap v1.0.1
Compiling wyz v0.5.1
Compiling sec1 v0.7.3
Compiling group v0.13.0
Compiling serde_derive v1.0.188
Compiling secp256k1-sys v0.8.1
Compiling hmac v0.12.1
Compiling crypto-bigint v0.5.2
Compiling derive_more v0.99.17
Compiling num-rational v0.4.1
Compiling num-iter v0.1.43
Compiling hex-literal v0.4.1
Compiling funty v2.0.0
Compiling keccak v0.1.4
Compiling scopeguard v1.2.0
Compiling allocator-api2 v0.2.16
Compiling elliptic-curve v0.13.5
Compiling hashbrown v0.14.0
Compiling bitvec v1.0.1
Compiling sha3 v0.10.8
Compiling auto_impl v1.1.0
Compiling rfc6979 v0.4.0
Compiling enumn v0.1.11
Compiling mbedtls-platform-support v0.1.0
Compiling signature v2.1.0
Compiling num-bigint v0.2.6
Compiling rayon-core v1.11.0
Compiling spin v0.5.2
Compiling bitflags v2.4.0
Compiling ecdsa v0.16.8
Compiling crossbeam-deque v0.8.3
Compiling sha2 v0.10.7
Compiling crossbeam-channel v0.5.8
Compiling num_cpus v1.16.0
Compiling time v0.1.45
Compiling mbedtls-sys-auto v2.28.3
Compiling rs-libc v0.1.0
Compiling num-complex v0.4.4
Compiling rand v0.8.5
Compiling tiny-keccak v2.0.2
Compiling num v0.4.1
Compiling chrono v0.4.28
Compiling substrate-bn v0.6.0
Compiling bytes v1.4.0
Compiling k256 v0.13.1
Compiling rlp v0.5.2
Compiling ruint v1.10.1
Compiling secp256k1 v0.27.0
Compiling revm-primitives v1.1.2 (https://github.com/bluealloy/revm#6bd05c90)
Compiling mbedtls v0.7.4
Compiling ripemd v0.1.3
Compiling eyre v0.6.8
Compiling bit-vec v0.5.1
Compiling itoa v1.0.9
Compiling serde_json v1.0.105
Compiling yasna v0.2.2
Compiling revm-interpreter v1.1.2 (https://github.com/bluealloy/revm#6bd05c90)
Compiling rayon v1.7.0
Compiling revm-precompile v2.0.3 (https://github.com/bluealloy/revm#6bd05c90)
Compiling const-hex v1.8.0
Compiling ryu v1.0.15
Compiling indenter v0.3.3
Compiling alloy-primitives v0.3.3
Compiling revm v3.3.0 (https://github.com/bluealloy/revm#6bd05c90)
Compiling sgx-revm v0.1.0 (/home/ubuntu/sgx-revm)
warning: unused import: `TcpListener`
--> src/server.rs:17:11
|
17 | net::{TcpListener, TcpStream},
| ^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unnecessary parentheses around assigned value
--> src/server.rs:24:28
|
24 | const CERT_VAL_SECS: u64 = (365 * DAYS_TO_SES);
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
24 - const CERT_VAL_SECS: u64 = (365 * DAYS_TO_SES);
24 + const CERT_VAL_SECS: u64 = 365 * DAYS_TO_SES;
|
warning: unused import: `serve`
--> src/main.rs:10:32
|
10 | use server::{get_key_and_cert, serve};
| ^^^^^
warning: use of deprecated method `chrono::TimeZone::timestamp`: use `timestamp_opt()` instead
--> src/server.rs:107:26
|
107 | let not_before = Utc.timestamp(start as _, 0);
| ^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: use of deprecated method `chrono::TimeZone::timestamp`: use `timestamp_opt()` instead
--> src/server.rs:108:25
|
108 | let not_after = Utc.timestamp(end as _, 0);
| ^^^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:67:57
|
67 | transact_to: revm::primitives::TransactTo::Call(receiver),
| ---------------------------------- ^^^^^^^^ expected `B160`, found `Address`
| |
| arguments to this enum variant are incorrect
|
note: tuple variant defined here
--> /home/ubuntu/.cargo/git/checkouts/revm-bf744d8ffabcbad9/6bd05c9/crates/primitives/src/env.rs:53:5
|
53 | Call(B160),
| ^^^^
For more information about this error, try `rustc --explain E0308`.
warning: `sgx-revm` (bin "sgx-revm") generated 5 warnings
error: could not compile `sgx-revm` (bin "sgx-revm") due to previous error; 5 warnings emitted
I believe that is because revm
dependency is not pinned to the fixed version and thus cargo
is fetching the latest version, whereas sgx-revm
is using revm
's outdated API for revm::primitives::TransactTo::Call(receiver)
. Notice that this commit: https://github.com/bluealloy/revm/commit/eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2#diff-0ade7f08f6db390934f025d9f530c64cc6d399de28856684a8b98185d43b46dcL52 reverted this commit https://github.com/bluealloy/revm/commit/f95b7a42a60c857dfe25040b98086fae01e94a71 that introduced the API that we are using here: https://github.com/gakonst/sgx-revm/blob/212d285d67d9434513272e9a8e0db84e08f60c70/src/main.rs#L67
(after the revert receiver
's type is now B160
yet again instead of Address
)
So I just replaced this line: https://github.com/gakonst/sgx-revm/blob/212d285d67d9434513272e9a8e0db84e08f60c70/Cargo.toml#L10 with this one:
revm = { git = "https://github.com/bluealloy/revm", rev = "e5227c4" }
(https://github.com/bluealloy/revm/commit/e5227c4399ea8b4a8b518075b553e25cddee4134 is one commit before the API revert mentioned above)
but it now errors out with:
$ RUST_BACKTRACE=1 cargo run --target x86_64-fortanix-unknown-sgx
(...)
Error: Init(Io(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }))
0: failure::backtrace::Backtrace::new
1: <failure::error::error_impl::ErrorImpl as core::convert::From<F>>::from
2: sgxs_loaders::generic::Device<D>::load
3: enclave_runner::loader::EnclaveBuilder::build
4: ftxsgx_runner::main
5: std::sys_common::backtrace::__rust_begin_short_backtrace
6: std::rt::lang_start::{{closure}}
7: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:284:13
std::panicking::try::do_call
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
std::panicking::try
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
std::panic::catch_unwind
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
std::rt::lang_start_internal::{{closure}}
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:48
std::panicking::try::do_call
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
std::panicking::try
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
std::panic::catch_unwind
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
std::rt::lang_start_internal
at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:20
8: main
9: <unknown>
10: __libc_start_main
11: _start
While loading SGX enclave
ERROR: while running "ftxsgx-runner" "target/x86_64-fortanix-unknown-sgx/debug/sgx-revm.sgxs" got exit status: 1
It seems to be something wrong with my Fortanix setup (see relevant: https://github.com/fortanix/rust-sgx/issues/526). Investigating...
It seems to be something wrong with my Fortanix setup (see relevant: fortanix/rust-sgx#526). Investigating...
It was indeed caused by the issue with Fortanix misconfiguration (see the details here; TL;DR I just needed to upgrade Linux kernel to the latest one which is ver. 6.5
).
Now running cargo run --release --target x86_64-fortanix-unknown-sgx
succeeds, meaning it waits for the request I send from the other terminal (as described here). The problem is that when I run:
nc localhost 7878
{ "sender": "0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5", "amount": 40 }
and press Ctrl+C, I'm getting this in the first terminal:
Attaching debugger
Error while executing SGX enclave.
Enclave panicked: Exited with status code 101
ERROR: while running "ftxsgx-runner" "target/x86_64-fortanix-unknown-sgx/release/sgx-revm.sgxs" got exit status: 255
Why? 🤔
Why? 🤔
Because supposedly there is a bug in the code. Instead of: https://github.com/gakonst/sgx-revm/blob/212d285d67d9434513272e9a8e0db84e08f60c70/src/main.rs#L76 should be:
U256::from(71)
Once I fixed it, it works as expected! Output from the first terminal (i.e. server's output):
[src/main.rs:79] &result = ResultAndState {
result: Success {
reason: Stop,
gas_used: 21000,
gas_refunded: 0,
logs: [],
output: Call(
Bytes(0x),
),
},
state: {
0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97: Account {
info: AccountInfo {
balance: 0x0000000000000000000000000000000000000000000000000000000000000047_U256,
nonce: 1,
code_hash: 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470,
code: Some(
Bytecode {
bytecode: Bytes(0x00),
state: Analysed {
len: 0,
jump_map: JumpMap {
map: BinaryString(
"00000000",
),
},
},
},
),
},
storage: {},
status: AccountStatus(
Touched,
),
},
0x0000000000000000000000000000000000000000: Account {
info: AccountInfo {
balance: 0x0_U256,
nonce: 0,
code_hash: 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470,
code: Some(
Bytecode {
bytecode: Bytes(0x00),
state: Analysed {
len: 0,
jump_map: JumpMap {
map: BinaryString(
"00000000",
),
},
},
},
),
},
storage: {},
status: AccountStatus(
Touched | LoadedAsNotExisting,
),
},
0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5: Account {
info: AccountInfo {
balance: 0x0000000000000000000000000000000000000000000000000000000000000028_U256,
nonce: 0,
code_hash: 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470,
code: Some(
Bytecode {
bytecode: Bytes(0x00),
state: Analysed {
len: 0,
jump_map: JumpMap {
map: BinaryString(
"00000000",
),
},
},
},
),
},
storage: {},
status: AccountStatus(
Touched | LoadedAsNotExisting,
),
},
},
}
I think I can close this issue, but before doing that – @gakonst please feel free to comment if I missed something in the above investigation. I had to workaround/solve a lot of intermediate problems before it started working as advertised in the README
, but maybe I missed something.
I followed the build process described in the
README
but the build fails with the following error:Any help would be greatly appreciated!