From 08c68beef374e7a984dc329c89d69a7f8d64fcdb Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Wed, 11 Sep 2024 23:11:40 +0200 Subject: [PATCH 1/4] return error on empty accounts --- steel/src/host/db/proof.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/steel/src/host/db/proof.rs b/steel/src/host/db/proof.rs index 241c7f18..54748b26 100644 --- a/steel/src/host/db/proof.rs +++ b/steel/src/host/db/proof.rs @@ -140,8 +140,9 @@ impl> ProofDb Result<(MerkleTrie, Vec)> { - let proofs = &mut self.proofs; + ensure!(!self.accounts.is_empty(), "no accounts accessed: use Contract::preflight"); + let proofs = &mut self.proofs; for (address, storage_keys) in &self.accounts { let account_proof = proofs.get(address); let storage_keys: Vec<_> = storage_keys From df3d33f27a6835f1a34cfe1fd000841a43ce0c63 Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Wed, 11 Sep 2024 23:14:31 +0200 Subject: [PATCH 2/4] update CHANGELOG --- steel/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/steel/CHANGELOG.md b/steel/CHANGELOG.md index 5d49cf74..828c567c 100644 --- a/steel/CHANGELOG.md +++ b/steel/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project will be documented in this file. ### ⚡️ Features +### 🛠 Fixes + +- Return specific error, when no `Contract::preflight` was called. + ### 🚨 Breaking Changes ## [0.13.0](https://github.com/risc0/risc0-ethereum/releases/tag/steel-v0.13.0) - 2024-09-10 From 9c736e334e872c3bbd5b7b8ea3ab6f50a5eeb569 Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Wed, 11 Sep 2024 23:28:29 +0200 Subject: [PATCH 3/4] add test --- steel/src/host/db/proof.rs | 5 ++++- steel/tests/steel.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/steel/src/host/db/proof.rs b/steel/src/host/db/proof.rs index 54748b26..4a343a51 100644 --- a/steel/src/host/db/proof.rs +++ b/steel/src/host/db/proof.rs @@ -140,7 +140,10 @@ impl> ProofDb Result<(MerkleTrie, Vec)> { - ensure!(!self.accounts.is_empty(), "no accounts accessed: use Contract::preflight"); + ensure!( + !self.accounts.is_empty(), + "no accounts accessed: use Contract::preflight" + ); let proofs = &mut self.proofs; for (address, storage_keys) in &self.accounts { diff --git a/steel/tests/steel.rs b/steel/tests/steel.rs index 35835c13..d829a02a 100644 --- a/steel/tests/steel.rs +++ b/steel/tests/steel.rs @@ -324,6 +324,20 @@ async fn call_eoa() { .expect_err("calling an EOA should fail"); } +#[test(tokio::test)] +async fn no_preflight() { + let env = EthEvmEnv::builder() + .provider(test_provider().await) + .build() + .await + .unwrap() + .with_chain_spec(&ANVIL_CHAIN_SPEC); + match env.into_input().await { + Ok(_) => panic!("calling into_input without a preflight should fail"), + Err(err) => assert_eq!(err.to_string(), "no accounts accessed: use Contract::preflight"), + } +} + alloy::sol!( // docker run -i ethereum/solc:0.8.26 - --optimize --bin #[sol(rpc, bytecode="60a0604052348015600e575f80fd5b5060405161012a38038061012a833981016040819052602b91604b565b60808190525f5b6080518110156045576001808255016032565b50506061565b5f60208284031215605a575f80fd5b5051919050565b60805160b46100765f395f6047015260b45ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c8063380eb4e014602a575b5f80fd5b60306042565b60405190815260200160405180910390f35b5f805b7f0000000000000000000000000000000000000000000000000000000000000000811015607a57805491909101906001016045565b509056fea26469706673582212203687b75eefdd9cc7ceedb243aa360bd9e1b4cab1930149a371efef74ce18bdf164736f6c634300081a0033")] From 53f5a77e6eacc5abded2fa1268123fabac23457c Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Wed, 11 Sep 2024 23:33:28 +0200 Subject: [PATCH 4/4] fix fmt --- steel/tests/steel.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/steel/tests/steel.rs b/steel/tests/steel.rs index d829a02a..220c7fee 100644 --- a/steel/tests/steel.rs +++ b/steel/tests/steel.rs @@ -334,7 +334,10 @@ async fn no_preflight() { .with_chain_spec(&ANVIL_CHAIN_SPEC); match env.into_input().await { Ok(_) => panic!("calling into_input without a preflight should fail"), - Err(err) => assert_eq!(err.to_string(), "no accounts accessed: use Contract::preflight"), + Err(err) => assert_eq!( + err.to_string(), + "no accounts accessed: use Contract::preflight" + ), } }