Skip to content

Commit

Permalink
fix: don't panic when a precompile errors (#728)
Browse files Browse the repository at this point in the history
* fix: don't panic when a precompile errors

* Create polite-plums-ring.md
  • Loading branch information
fvictorio authored Nov 15, 2024
1 parent e0c927d commit 9c062ad
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-plums-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

fix: don't panic when a precompile errors
4 changes: 3 additions & 1 deletion crates/edr_napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ export const enum ExitCode {
/** Create init code size exceeds limit (runtime). */
CODESIZE_EXCEEDS_MAXIMUM = 6,
/** Create collision. */
CREATE_COLLISION = 7
CREATE_COLLISION = 7,
/** Unknown halt reason. */
UNKNOWN_HALT_REASON = 8
}
export interface EvmStep {
pc: number
Expand Down
5 changes: 4 additions & 1 deletion crates/edr_napi/src/trace/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum ExitCode {
CODESIZE_EXCEEDS_MAXIMUM,
/// Create collision.
CREATE_COLLISION,
/// Unknown halt reason.
UNKNOWN_HALT_REASON,
}

impl fmt::Display for ExitCode {
Expand All @@ -43,6 +45,7 @@ impl fmt::Display for ExitCode {
ExitCode::STACK_UNDERFLOW => write!(f, "Stack underflow"),
ExitCode::CODESIZE_EXCEEDS_MAXIMUM => write!(f, "Codesize exceeds maximum"),
ExitCode::CREATE_COLLISION => write!(f, "Create collision"),
ExitCode::UNKNOWN_HALT_REASON => write!(f, "Unknown halt reason"),
}
}
}
Expand All @@ -62,7 +65,7 @@ impl From<edr_solidity::message_trace::ExitCode> for ExitCode {
ExitCode::Halt(HaltReason::StackUnderflow) => Self::STACK_UNDERFLOW,
ExitCode::Halt(HaltReason::CreateContractSizeLimit) => Self::CODESIZE_EXCEEDS_MAXIMUM,
ExitCode::Halt(HaltReason::CreateCollision) => Self::CREATE_COLLISION,
halt @ ExitCode::Halt(_) => panic!("Unmatched EDR exceptional halt: {halt:?}"),
ExitCode::Halt(_) => Self::UNKNOWN_HALT_REASON,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.8.1;

contract C {
address internal constant POINT_EVALUATION_PRECOMPILE_ADDRESS = address(0x0a);

function test() public {
bytes memory forcingFailureBytes = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

_verifyPointEvaluation(0x0, 0x0, 0x0, forcingFailureBytes, forcingFailureBytes);
}

function _verifyPointEvaluation(
bytes32 _currentDataHash,
uint256 _dataEvaluationPoint,
uint256 _dataEvaluationClaim,
bytes memory _kzgCommitment,
bytes memory _kzgProof
) internal view {
POINT_EVALUATION_PRECOMPILE_ADDRESS.staticcall(
abi.encodePacked(_currentDataHash, _dataEvaluationPoint, _dataEvaluationClaim, _kzgCommitment, _kzgProof)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "This test checks that EDR doesn't crash when a precompile call results in an error. See https://github.com/NomicFoundation/edr/issues/727",
"transactions": [
{
"file": "c.sol",
"contract": "C"
},
{
"to": 0,
"function": "test"
}
]
}

0 comments on commit 9c062ad

Please sign in to comment.