Skip to content

Commit

Permalink
external opcodes added
Browse files Browse the repository at this point in the history
  • Loading branch information
advock committed Feb 24, 2023
1 parent 2319f16 commit e14fa4a
Showing 1 changed file with 94 additions and 4 deletions.
98 changes: 94 additions & 4 deletions src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,104 @@ impl Opcode {
pub const SWAP15: Opcode = Opcode(0x9e);
pub const SWAP16: Opcode = Opcode(0x9f);

/// `RETURN`
pub const RETURN: Opcode = Opcode(0xf3);
/// `REVERT`

pub const REVERT: Opcode = Opcode(0xfd);

/// `INVALID`
pub const INVALID: Opcode = Opcode(0xfe);

/// See [EIP-3541](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3541.md)
pub const EOFMAGIC: Opcode = Opcode(0xef);
}
// External opcodes
impl Opcode {
/// `SHA3`
pub const SHA3: Opcode = Opcode(0x20);
/// `ADDRESS`
pub const ADDRESS: Opcode = Opcode(0x30);
/// `BALANCE`
pub const BALANCE: Opcode = Opcode(0x31);
/// `SELFBALANCE`
pub const SELFBALANCE: Opcode = Opcode(0x47);
/// `BASEFEE`
pub const BASEFEE: Opcode = Opcode(0x48);
/// `ORIGIN`
pub const ORIGIN: Opcode = Opcode(0x32);
/// `CALLER`
pub const CALLER: Opcode = Opcode(0x33);
/// `CALLVALUE`
pub const CALLVALUE: Opcode = Opcode(0x34);
/// `GASPRICE`
pub const GASPRICE: Opcode = Opcode(0x3a);
/// `EXTCODESIZE`
pub const EXTCODESIZE: Opcode = Opcode(0x3b);
/// `EXTCODECOPY`
pub const EXTCODECOPY: Opcode = Opcode(0x3c);
/// `EXTCODEHASH`
pub const EXTCODEHASH: Opcode = Opcode(0x3f);
/// `RETURNDATASIZE`
pub const RETURNDATASIZE: Opcode = Opcode(0x3d);
/// `RETURNDATACOPY`
pub const RETURNDATACOPY: Opcode = Opcode(0x3e);
/// `BLOCKHASH`
pub const BLOCKHASH: Opcode = Opcode(0x40);
/// `COINBASE`
pub const COINBASE: Opcode = Opcode(0x41);
/// `TIMESTAMP`
pub const TIMESTAMP: Opcode = Opcode(0x42);
/// `NUMBER`
pub const NUMBER: Opcode = Opcode(0x43);
/// `DIFFICULTY`
pub const DIFFICULTY: Opcode = Opcode(0x44);
/// `GASLIMIT`
pub const GASLIMIT: Opcode = Opcode(0x45);
/// `SLOAD`
pub const SLOAD: Opcode = Opcode(0x54);
/// `SSTORE`
pub const SSTORE: Opcode = Opcode(0x55);
/// `GAS`
pub const GAS: Opcode = Opcode(0x5a);
/// `LOGn`
pub const LOG0: Opcode = Opcode(0xa0);
pub const LOG1: Opcode = Opcode(0xa1);
pub const LOG2: Opcode = Opcode(0xa2);
pub const LOG3: Opcode = Opcode(0xa3);
pub const LOG4: Opcode = Opcode(0xa4);
/// `CREATE`
pub const CREATE: Opcode = Opcode(0xf0);
/// `CREATE2`
pub const CREATE2: Opcode = Opcode(0xf5);
/// `CALL`
pub const CALL: Opcode = Opcode(0xf1);
/// `CALLCODE`
pub const CALLCODE: Opcode = Opcode(0xf2);
/// `DELEGATECALL`
pub const DELEGATECALL: Opcode = Opcode(0xf4);
/// `STATICCALL`
pub const STATICCALL: Opcode = Opcode(0xfa);
/// `SUICIDE`
pub const SUICIDE: Opcode = Opcode(0xff);
/// `CHAINID`
pub const CHAINID: Opcode = Opcode(0x46);
}

impl Opcode {
/// Whether the opcode is a push opcode.
pub fn is_push(&self) -> Option<u8> {
let value = self.0;
if (0x60..=0x7f).contains(&value) {
Some(value - 0x60 + 1)
} else {
None
}
}

#[inline]
pub const fn as_u8(&self) -> u8 {
self.0
}

#[inline]
pub const fn as_usize(&self) -> usize {
self.0 as usize
}
}

0 comments on commit e14fa4a

Please sign in to comment.