Skip to content

Commit

Permalink
evm: add PC, SAR, EXTCODECOPY, MULMOD, ADDMOD opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Sep 26, 2024
1 parent 14ec575 commit d448b11
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/evm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,33 @@ where
(3, if s0 >= VAL_256 { U256::ZERO } else { s1 >> s0 })
}),

op::SAR => self.bop(op, |_, s0, _, s1| {
(
3,
if s0 < VAL_256 {
s1 >> s0
} else if s1.bit(255) {
U256::MAX
} else {
U256::ZERO
},
)
}),

op::MULMOD | op::ADDMOD => {
let s0 = self.stack.pop_uint()?;
let s1 = self.stack.pop_uint()?;
let s2 = self.stack.pop_uint()?;

self.stack.push_uint(if op == op::MULMOD {
s0.mul_mod(s1, s2)
} else {
s0.add_mod(s1, s2)
});

Ok(StepResult::new(op, 8))
}

op::KECCAK256 => {
let mut ret = StepResult::new(op, 30);
ret.fa = Some(self.stack.pop()?); // offset
Expand Down Expand Up @@ -389,6 +416,14 @@ where
Ok(StepResult::new(op, 100))
}

op::EXTCODECOPY => {
self.stack.pop()?;
self.stack.pop()?;
self.stack.pop()?;
self.stack.pop()?;
Ok(StepResult::new(op, 100))
}

op::RETURNDATASIZE => {
self.stack.push_data(VAL_1024_B);
Ok(StepResult::new(op, 2))
Expand Down Expand Up @@ -473,6 +508,11 @@ where
Ok(StepResult::new(op, 2))
}

op::PC => {
self.stack.push_uint(U256::from(self.pc));
Ok(StepResult::new(op, 2))
}

op::LOG0..=op::LOG4 => {
let n = (op - op::LOG0) as u32;
for _ in 0..n + 2 {
Expand Down

0 comments on commit d448b11

Please sign in to comment.