risc0 / risc0-foundry-template

Template for integrating RISC Zero and Ethereum using Foundry
https://risczero.com
108 stars 60 forks source link

Suggestions from the Hackathon #11

Closed nategraf closed 1 year ago

nategraf commented 1 year ago

A collection of small edits that I made along the way while working through the template. Notable changes are to run forge fmt, remove the need to have an explicit expected input length, and change assertTrue to require in the BonsaiTest.sol contract to make it more clear when the callback fails[^1]


[^1]: For some reason when assertTrue fails, the program continues, and then crashes when it gets to the next call out to the application contract, where a require fails within that contract because the cache is not set, leading to a confusing error message.

mothran commented 1 year ago

Could you integrate forge fmt into the CI?

nategraf commented 1 year ago

Could you integrate forge fmt into the CI?

Done in 2e5b0f588a0cb4457e74cbc8235f068dd214b02c

nategraf commented 1 year ago

@mothran, in 3d9a12bbd62d016873dd18992da64b34cb4aa987 I adjusted CI definitions to trigger on all pull requests instead of just pull requests to main (e.g. to run on PR like this one). If you agree, feel free to hit merge on this PR. If not, feel free to revert that commit and merge, or ask me to do so.

nategraf commented 1 year ago

If you merge your PR before this one, I will retarget it to main. (That was my original plan)

nategraf commented 1 year ago

Currently working on debugging the following error:

RUSTFLAGS="--cfg tokio_unstable" RUST_BACKTRACE=full PROVE_MODE=bonsai cargo run 0x818633a631981372e1b55154f8da545d72b4eb5f798c0a5262981bfbe4e59dcd 0x0000000000000000000000000000000000000000000000000000000000000080
   Compiling bonsai-starter-methods v0.1.0 (/Users/victorgraf/risc0/bonsai-hackathon/bonsai-foundry-template/methods)
bonsai-starter-methods-guest: Starting build for riscv32im-risc0-zkvm-elfbuild)
bonsai-starter-methods-guest:     Updating crates.io index
bonsai-starter-methods-guest:     Finished release [optimized] target(s) in 0.68s
    Finished dev [optimized + debuginfo] target(s) in 1.98s
     Running `target/debug/bonsai-starter-methods 0x818633a631981372e1b55154f8da545d72b4eb5f798c0a5262981bfbe4e59dcd 0x0000000000000000000000000000000000000000000000000000000000000080`
thread 'main' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.', /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/blockin
g/shutdown.rs:51:21
stack backtrace:
   0:        0x10306697c - std::backtrace_rs::backtrace::libunwind::trace::he794f483562ace83
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x10306697c - std::backtrace_rs::backtrace::trace_unsynchronized::hf05b01a102701590
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10306697c - std::sys_common::backtrace::_print_fmt::hff089dec9f32383d
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x10306697c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8daea1343397be85
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x103081450 - core::fmt::write::hcf237ee36f044428
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/fmt/mod.rs:1232:17
   5:        0x1030639c0 - std::io::Write::write_fmt::h5feddf4a99888398
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/io/mod.rs:1684:15
   6:        0x103066790 - std::sys_common::backtrace::_print::h9c9c2f44ccf83f9a
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x103066790 - std::sys_common::backtrace::print::h3dca64bdc42524d8
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x103067e6c - std::panicking::default_hook::{{closure}}::h10c2e8a9c396100e
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:271:22
   9:        0x103067bc4 - std::panicking::default_hook::hfb1fd4c1ac98b340
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:290:9
  10:        0x10306837c - std::panicking::rust_panic_with_hook::h50157183e0a2fab2
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:692:13
  11:        0x103068270 - std::panicking::begin_panic_handler::{{closure}}::h59ecc30c7e64e646
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:581:13
  12:        0x103066d9c - std::sys_common::backtrace::__rust_end_short_backtrace::he85ba1f2517ce8c9
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:150:18
  13:        0x10306800c - rust_begin_unwind
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:579:5
  14:        0x1031277c4 - core::panicking::panic_fmt::h767e3a46d9029811
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/panicking.rs:64:14
  15:        0x103019b00 - tokio::runtime::blocking::shutdown::Receiver::wait::h2f3442e150f541a2
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/blocking/shutdown.rs:51:21
  16:        0x103019b00 - tokio::runtime::blocking::pool::BlockingPool::shutdown::h41e749c5d3013ccd
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/blocking/pool.rs:261:12
  17:        0x102f13668 - core::ptr::drop_in_place<tokio::runtime::blocking::pool::BlockingPool>::h3fb54aaff3adc4ec
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/ptr/mod.rs:490:1
  18:        0x102f195e8 - reqwest::blocking::wait::enter::h1fb6c3140e17f86e
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/blocking/wait.rs:76:21
  19:        0x102f19108 - reqwest::blocking::wait::timeout::hb0d63cb38d4b1415
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/blocking/wait.rs:13:5
  20:        0x102f2792c - reqwest::blocking::client::ClientHandle::new::h0e30b56cb162b918
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/blocking/client.rs:1042:15
  21:        0x102f2792c - reqwest::blocking::client::ClientBuilder::build::h94e111a839bb8405
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.11.18/src/blocking/client.rs:103:9
  22:        0x102ebf81c - bonsai_sdk::alpha::construct_req_client::h783b697ad781792c
                               at /Users/victorgraf/.cargo/git/checkouts/risc0-7d6ab9951628e5b1/109ff3e/bonsai/sdk/src/alpha.rs:108:5
  23:        0x102ebf930 - bonsai_sdk::alpha::Client::from_env::h728f9701eb5165fd
                               at /Users/victorgraf/.cargo/git/checkouts/risc0-7d6ab9951628e5b1/109ff3e/bonsai/sdk/src/alpha.rs:124:22
  24:        0x1029eb7fc - bonsai_starter_methods::prove_alpha::hd03b69faef41c33e
                               at /Users/victorgraf/risc0/bonsai-hackathon/bonsai-foundry-template/methods/src/main.rs:57:18
  25:        0x1029e9920 - bonsai_starter_methods::main::{{closure}}::h595f18f0021d6871
                               at /Users/victorgraf/risc0/bonsai-hackathon/bonsai-foundry-template/methods/src/main.rs:128:29
  26:        0x1029e9920 - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h68c1eb83dbc7af46
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/park.rs:283:63
  27:        0x1029e9920 - tokio::runtime::coop::with_budget::h008c8a942c936ad1
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/coop.rs:107:5
  28:        0x1029e9920 - tokio::runtime::coop::budget::h5fcfe87ede2ce3fe
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/coop.rs:73:5
  29:        0x1029e9920 - tokio::runtime::park::CachedParkThread::block_on::hcb224b77671a60c0
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/park.rs:283:31
  30:        0x1029e5e2c - tokio::runtime::context::BlockingRegionGuard::block_on::h3122766fac48366c
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/context.rs:315:13
  31:        0x1029e5e2c - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::hc969232c9cd096a1
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/scheduler/multi_thread/mod.rs:66:9
  32:        0x1029e6340 - tokio::runtime::runtime::Runtime::block_on::h0e0809236d46eca3
                               at /Users/victorgraf/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.28.2/src/runtime/runtime.rs:304:45
  33:        0x1029ecb40 - bonsai_starter_methods::main::hd5b037567f83632b
                               at /Users/victorgraf/risc0/bonsai-hackathon/bonsai-foundry-template/methods/src/main.rs:143:5
  34:        0x1029e8228 - core::ops::function::FnOnce::call_once::h29cc0f06f7a59739
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/ops/function.rs:250:5
  35:        0x1029e8228 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9893994c2b6d80c7
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/sys_common/backtrace.rs:134:18
  36:        0x1029e19b4 - std::rt::lang_start::{{closure}}::he5c165ee91bf699e
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/rt.rs:166:18
  37:        0x10305cc2c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h995ec148ae09fd28
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/core/src/ops/function.rs:287:13
  38:        0x10305cc2c - std::panicking::try::do_call::h8a6c1d7cc17ad284
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:487:40
  39:        0x10305cc2c - std::panicking::try::h15aa758ca7a49a11
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:451:19
  40:        0x10305cc2c - std::panic::catch_unwind::haeb3c70f1c8ec625
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panic.rs:140:14
  41:        0x10305cc2c - std::rt::lang_start_internal::{{closure}}::h2a4353abfb9d72ae
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/rt.rs:148:48
  42:        0x10305cc2c - std::panicking::try::do_call::h4a84fce08414c204
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:487:40
  43:        0x10305cc2c - std::panicking::try::hb58ef99d06163d7d
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panicking.rs:451:19
  44:        0x10305cc2c - std::panic::catch_unwind::hf0eb7dab38f8bf4d
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/panic.rs:140:14
  45:        0x10305cc2c - std::rt::lang_start_internal::hf0a6c79d020fc6b1
                               at /rustc/7820b62d20bc548096d4632a3487987308cb4b5d/library/std/src/rt.rs:148:20
  46:        0x1029ecc08 - _main
mothran commented 1 year ago

bonsai-starter-methods-guest: Starting build for riscv32im-risc0-zkvm-elfbuild) bonsai-starter-methods-guest: Updating crates.io index bonsai-starter-methods-guest: Finished release [optimized] target(s) in 0.68s Finished dev [optimized + debuginfo] target(s) in 1.98s Running target/debug/bonsai-starter-methods 0x818633a631981372e1b55154f8da545d72b4eb5f798c0a5262981bfbe4e59dcd 0x0000000000000000000000000000000000000000000000000000000000000080 thread 'main' panicked at 'Canno

Yeah I hit the same, now that we just have the alpha SDK we can drop tokio / async all together. I just pushed: c5997e645807344059167b5d40a2f31e984cca6c to the source branch to hopefully resolve it.

mothran commented 1 year ago

Heads up: Just got the final merge conflicts resolved so we can push this forward. Thanks!