-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: showing low-level VM errors (#311)
* feat: showing low-level VM errors * silenced clippy warning * Update to latest version and check-in e2e test that displays console errors * fix lint --------- Co-authored-by: Nicolas Villanueva <[email protected]> Co-authored-by: MexicanAce <[email protected]>
- Loading branch information
1 parent
3a6451d
commit d35eb77
Showing
7 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "era_test_node" | ||
version = "0.1.0-alpha.27" | ||
version = "0.1.0-alpha.28" | ||
edition = "2018" | ||
authors = ["The Matter Labs Team <[email protected]>"] | ||
homepage = "https://zksync.io/" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
contract Fib { | ||
function fib(uint256 n) public pure returns (uint256) { | ||
return n <= 1 ? 1 : fib(n - 1) + fib(n - 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Wallet } from "zksync-web3"; | ||
import * as hre from "hardhat"; | ||
import { Deployer } from "@matterlabs/hardhat-zksync-deploy"; | ||
import { RichAccounts } from "../helpers/constants"; | ||
import { deployContract, expectThrowsAsync, getTestProvider } from "../helpers/utils"; | ||
|
||
const provider = getTestProvider(); | ||
|
||
describe("Test Fib error flags", function () { | ||
it("Should print to the console NOT ENOUGH ERGS", async function () { | ||
const action = async () => { | ||
const wallet = new Wallet(RichAccounts[0].PrivateKey, provider); | ||
|
||
const deployer = new Deployer(hre, wallet); | ||
const fib = await deployContract(deployer, "Fib"); | ||
await fib.fib(100); | ||
}; | ||
|
||
// This is expected to throw and the console is expected to show: | ||
// XX:YY:ZZ ERROR !! Got error flags: | ||
// XX:YY:ZZ ERROR NOT ENOUGH ERGS | ||
await expectThrowsAsync(action, "call revert exception"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use zksync_multivm::{ | ||
tracers::dynamic::vm_1_5_0::DynTracer, | ||
vm_latest::{HistoryMode, SimpleMemory, VmTracer}, | ||
zk_evm_latest::{ | ||
tracing::{AfterDecodingData, VmLocalStateData}, | ||
vm_state::ErrorFlags, | ||
}, | ||
}; | ||
use zksync_state::interface::WriteStorage; | ||
|
||
pub struct CallErrorTracer {} | ||
|
||
impl CallErrorTracer { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl<S, H: HistoryMode> DynTracer<S, SimpleMemory<H>> for CallErrorTracer { | ||
fn after_decoding( | ||
&mut self, | ||
_state: VmLocalStateData<'_>, | ||
data: AfterDecodingData, | ||
_memory: &SimpleMemory<H>, | ||
) { | ||
if !data.error_flags_accumulated.is_empty() { | ||
tracing::error!("!! Got error flags: "); | ||
if data | ||
.error_flags_accumulated | ||
.contains(ErrorFlags::INVALID_OPCODE) | ||
{ | ||
tracing::error!("INVALID OPCODE"); | ||
} | ||
if data | ||
.error_flags_accumulated | ||
.contains(ErrorFlags::NOT_ENOUGH_ERGS) | ||
{ | ||
tracing::error!("NOT ENOUGH ERGS"); | ||
} | ||
if data | ||
.error_flags_accumulated | ||
.contains(ErrorFlags::PRIVILAGED_ACCESS_NOT_FROM_KERNEL) | ||
{ | ||
tracing::error!("PRIVILEGED ACCESS"); | ||
} | ||
if data | ||
.error_flags_accumulated | ||
.contains(ErrorFlags::WRITE_IN_STATIC_CONTEXT) | ||
{ | ||
tracing::error!("WRITE IN STATIC"); | ||
} | ||
if data | ||
.error_flags_accumulated | ||
.contains(ErrorFlags::CALLSTACK_IS_FULL) | ||
{ | ||
tracing::error!("CALLSTACK IS FULL"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for CallErrorTracer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters