Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
implement 0x17 - OR opcode #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Noeljarillo committed Sep 6, 2023
1 parent 266086c commit 9544962
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/evm/src/instructions/comparison_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl ComparisonAndBitwiseOperations of ComparisonAndBitwiseOperationsTrait {
/// 0x17 - OR
/// # Specification: https://www.evm.codes/#17?fork=shanghai
fn exec_or(ref self: ExecutionContext) -> Result<(), EVMError> {
Result::Ok(())
let popped = self.stack.pop_n(2)?;
let a = *popped[0];
let b = *popped[1];
let result = a | b;
self.stack.push(result)
}

/// 0x18 - XOR operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,39 @@ fn assert_sar(a: u256, b: u256, expected: u256) {
assert(ctx.stack.peek().unwrap() == expected, 'sar failed');
}

#[test]
#[available_gas(20000000)]
fn test_or_true() {
// Given
let mut ctx = setup_execution_context();
ctx.stack.push(0x01).unwrap();
ctx.stack.push(0x00).unwrap();

// When
ctx.exec_or();

// Then
assert(ctx.stack.len() == 1, 'stack should have one element');
assert(ctx.stack.peek().unwrap() == 0x01, 'stack top should be true');
}

#[test]
#[available_gas(20000000)]
fn test_or_false() {
// Given
let mut ctx = setup_execution_context();
ctx.stack.push(0x00).unwrap();
ctx.stack.push(0x00).unwrap();

// When
ctx.exec_or();

// Then
assert(ctx.stack.len() == 1, 'stack should have one element');
assert(ctx.stack.peek().unwrap() == 0x00, 'stack top should be false');
}


#[test]
#[available_gas(20000000)]
fn test_exec_lt_true() {
Expand Down

0 comments on commit 9544962

Please sign in to comment.