Repository: huff-language/huff-rs
Pull request #179 (2022-07-28 23:55:29)

fix(huff_utils): `basefee` opcode
## Overview

Adds the missing `basefee` opcode



Patch:
diff --git a/huff_parser/src/lib.rs b/huff_parser/src/lib.rs
index a8c65d9..f559334 100644
--- a/huff_parser/src/lib.rs
+++ b/huff_parser/src/lib.rs
@@ -103,12 +103,12 @@ impl Parser {
                     _ => {
                         tracing::error!(
                             target: "parser",
-                            "Invalid definition. Must be a function, event, constant, or macro. Got: {}",
+                            "Invalid definition. Must be a function, event, constant, error, or macro. Got: {}",
                             self.current_token.kind
                         );
                         return Err(ParserError {
                             kind: ParserErrorKind::InvalidDefinition(self.current_token.kind.clone()),
-                            hint: Some("Definition must be one of: `function`, `event`, `constant`, `macro`, or `fn`.".to_string()),
+                            hint: Some("Definition must be one of: `function`, `event`, `constant`, `error`, `macro`, or `fn`.".to_string()),
                             spans: AstSpan(vec![self.current_token.span.clone()]),
                         })
                     }
diff --git a/huff_utils/src/evm.rs b/huff_utils/src/evm.rs
index 80ed568..6cc7f2f 100644
--- a/huff_utils/src/evm.rs
+++ b/huff_utils/src/evm.rs
@@ -6,7 +6,7 @@ use strum_macros::EnumString;
 /// They are arranged in a particular order such that all the opcodes that have common
 /// prefixes are ordered by decreasing length to avoid mismatch when lexing.
 /// Example : [origin, or] or [push32, ..., push3]
-pub const OPCODES: [&str; 142] = [
+pub const OPCODES: [&str; 143] = [
     "lt",
     "gt",
     "slt",
@@ -28,6 +28,7 @@ pub const OPCODES: [&str; 142] = [
     "calldatacopy",
     "codesize",
     "codecopy",
+    "basefee",
     "blockhash",
     "coinbase",
     "timestamp",
@@ -174,6 +175,7 @@ pub static OPCODES_MAP: phf::Map<&'static str, Opcode> = phf_map! {
     "calldatacopy" => Opcode::Calldatacopy,
     "codesize" => Opcode::Codesize,
     "codecopy" => Opcode::Codecopy,
+    "basefee" => Opcode::Basefee,
     "blockhash" => Opcode::Blockhash,
     "coinbase" => Opcode::Coinbase,
     "timestamp" => Opcode::Timestamp,
@@ -624,7 +626,6 @@ impl Opcode {
             Opcode::Shr => "1c",
             Opcode::Sar => "1d",
             Opcode::Sha3 => "20",
-            // Opcode::Keccak => "20",
             Opcode::Address => "30",
             Opcode::Balance => "31",
             Opcode::Origin => "32",


Test patch:
diff --git a/huff_core/tests/parser_errors.rs b/huff_core/tests/parser_errors.rs
index 18831bd..a70776b 100644
--- a/huff_core/tests/parser_errors.rs
+++ b/huff_core/tests/parser_errors.rs
@@ -95,7 +95,7 @@ fn test_invalid_definition() {
                 ParserError {
                     kind: ParserErrorKind::InvalidDefinition(TokenKind::Ident("test".to_string())),
                     hint: Some(
-                        "Definition must be one of: `function`, `event`, `constant`, `macro`, or `fn`."
+                        "Definition must be one of: `function`, `event`, `constant`, `error`, `macro`, or `fn`."
                             .to_string()
                     ),
                     spans: AstSpan(vec![Span {