Function evmil::util::from_be_bytes

source ·
pub fn from_be_bytes(bytes: &[u8]) -> u128
Expand description

Convert a sequence of bytes in big endian form into a 128bit value.

Examples found in repository?
src/cfa.rs (line 145)
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
    fn transfer(self, insn: &Instruction) -> CfaState {
        match insn {
            STOP => CfaState::bottom(),
            // 0s: Stop and Arithmetic Operations
            ADD|MUL|SUB|DIV|SDIV|MOD|SMOD|EXP|SIGNEXTEND => {
                self.pop().pop().push(UNKNOWN)
            }
            ADDMOD|MULMOD => {
                self.pop().pop().pop().push(UNKNOWN)
            }
            // 0s: Stop and Arithmetic Operations
            ISZERO|NOT => {
                self.pop().push(UNKNOWN)
            }
            // Binary Comparators
            LT|GT|SLT|SGT|EQ => {
                self.pop().pop().push(UNKNOWN)
            }
            // Binary bitwise operators
            AND|OR|XOR|BYTE|SHL|SHR|SAR => {
                self.pop().pop().push(UNKNOWN)
            }
            // 20s: Keccak256
            // 30s: Environmental Information
            CALLVALUE => self.push(UNKNOWN),
            CALLDATALOAD => self.pop().push(UNKNOWN),
            CALLDATASIZE => self.push(UNKNOWN),
            // 40s: Block Information
            // 50s: Stack, Memory, Storage and Flow Operations
            POP => self.pop(),
            MLOAD => self.pop().push(UNKNOWN),
            MSTORE => self.pop().pop(),
            SLOAD => self.pop().push(UNKNOWN),
            SSTORE => self.pop().pop(),
            JUMPI => self.pop().pop(),
            JUMPDEST(_) => self, // nop
            // 60 & 70s: Push Operations
            PUSH(bytes) => {
                let n = util::from_be_bytes(&bytes);
                if n <= MAX_CODE_SIZE {
                    self.push(AbstractValue::Known(n as usize))
                } else {
                    self.push(UNKNOWN)
                }
            }
            // 80s: Duplicate Operations
            DUP(n) => {
                let m = (*n - 1) as usize;
                let nth = self.peek(m);
                self.push(nth)
            }
            // 90s: Swap Operations
            SWAP(n) => {
                let m = (*n - 1) as usize;
                let x = self.peek(m);
                let y = self.peek(0);
                self.set(0,x).set(m,y)
            }
            // 90s: Exchange Operations
            // a0s: Logging Operations
            // f0s: System Operations
            INVALID|JUMP|RETURN|REVERT => {
                CfaState::bottom()
            }
            _ => {
                // This is a catch all to ensure no instructions are
                // missed above.
                panic!("unknown instruction ({:?})",insn);
            }
        }
    }