Skip to content

Commit

Permalink
fix push size calc
Browse files Browse the repository at this point in the history
  • Loading branch information
WilfredTA committed Mar 9, 2023
1 parent b013764 commit 3bc884a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub mod state;
pub mod traits;
pub mod storage;
pub mod parser;


use instruction::*;
use smt::*;
use stack::*;
Expand Down
35 changes: 32 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,26 @@ fn is_push(b: u8) -> bool {
}

fn push_size(b: u8) -> u8 {
b - 0x60
if b > 0x60 {
b - 0x60 + 1
} else {
0
}

}


impl Instruction {
pub fn from_byte(value: u8) -> Self {
value.into()

}

// Has to handle when it's a push or dup, otherwise easy 1-1 conversion
pub fn from_slice(bytes: &[u8]) -> Vec<Instruction> {
todo!()
}
}
impl From<u8> for Instruction {
fn from(value: u8) -> Self {

Expand Down Expand Up @@ -191,8 +206,22 @@ impl From<u8> for Instruction {
0xfe => Instruction::Invalid,
0xff => Instruction::SelfDestruct,
_ => Instruction::Invalid,
};
}

todo!()
}
}

#[test]
fn is_push_works() {
for b in (0x60_u8..0x7f) {
assert!(is_push(b));
}

for b in (0x00_u8 .. 0x5f) {
assert!(!is_push(b));
}

for b in (0x80..0xff_u8) {
assert!(!is_push(b));
}
}

0 comments on commit 3bc884a

Please sign in to comment.