diff --git a/evm/src/cpu/kernel/asm/curve/bn254/curve_add.asm b/evm/src/cpu/kernel/asm/curve/bn254/curve_add.asm index 15f9df05..dda82109 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/curve_add.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/curve_add.asm @@ -9,7 +9,6 @@ global ec_add: // PUSH 1 // PUSH 0x1bf9384aa3f0b3ad763aee81940cacdde1af71617c06f46e11510f14f3d5d121 // PUSH 0xe7313274bb29566ff0c8220eb9841de1d96c2923c6a4028f7dd3c6a14cee770 - JUMPDEST // stack: x0, y0, x1, y1, retdest // Check if points are valid BN254 points. @@ -38,7 +37,6 @@ global ec_add: // BN254 elliptic curve addition. // Assumption: (x0,y0) and (x1,y1) are valid points. global ec_add_valid_points: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Check if the first point is the identity. @@ -92,7 +90,6 @@ global ec_add_valid_points: // BN254 elliptic curve addition. // Assumption: (x0,y0) == (0,0) ec_add_first_zero: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Just return (x1,y1) %stack (x0, y0, x1, y1, retdest) -> (retdest, x1, y1) @@ -101,7 +98,6 @@ ec_add_first_zero: // BN254 elliptic curve addition. // Assumption: (x1,y1) == (0,0) ec_add_snd_zero: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Just return (x0,y0) @@ -111,7 +107,6 @@ ec_add_snd_zero: // BN254 elliptic curve addition. // Assumption: lambda = (y0 - y1)/(x0 - x1) ec_add_valid_points_with_lambda: - JUMPDEST // stack: lambda, x0, y0, x1, y1, retdest // Compute x2 = lambda^2 - x1 - x0 @@ -159,7 +154,6 @@ ec_add_valid_points_with_lambda: // BN254 elliptic curve addition. // Assumption: (x0,y0) and (x1,y1) are valid points and x0 == x1 ec_add_equal_first_coord: - JUMPDEST // stack: x0, y0, x1, y1, retdest with x0 == x1 // Check if the points are equal @@ -188,7 +182,6 @@ ec_add_equal_first_coord: // Assumption: x0 == x1 and y0 == y1 // Standard doubling formula. ec_add_equal_points: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Compute lambda = 3/2 * x0^2 / y0 @@ -216,7 +209,6 @@ ec_add_equal_points: // Assumption: (x0,y0) is a valid point. // Standard doubling formula. global ec_double: - JUMPDEST // stack: x0, y0, retdest DUP2 // stack: y0, x0, y0, retdest diff --git a/evm/src/cpu/kernel/asm/curve/bn254/curve_mul.asm b/evm/src/cpu/kernel/asm/curve/bn254/curve_mul.asm index 62cf2235..b1472812 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/curve_mul.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/curve_mul.asm @@ -6,7 +6,6 @@ global ec_mul: // PUSH 0xd // PUSH 2 // PUSH 1 - JUMPDEST // stack: x, y, s, retdest DUP2 // stack: y, x, y, s, retdest @@ -29,7 +28,6 @@ global ec_mul: // Same algorithm as in `exp.asm` ec_mul_valid_point: - JUMPDEST // stack: x, y, s, retdest DUP3 // stack: s, x, y, s, retdest @@ -38,7 +36,6 @@ ec_mul_valid_point: %jump(ret_zero_ec_mul) step_case: - JUMPDEST // stack: x, y, s, retdest PUSH recursion_return // stack: recursion_return, x, y, s, retdest @@ -58,12 +55,10 @@ step_case: // Assumption: 2(x,y) = (x',y') step_case_contd: - JUMPDEST // stack: x', y', s / 2, recursion_return, x, y, s, retdest %jump(ec_mul_valid_point) recursion_return: - JUMPDEST // stack: x', y', x, y, s, retdest SWAP4 // stack: s, y', x, y, x', retdest @@ -96,6 +91,5 @@ recursion_return: JUMP odd_scalar: - JUMPDEST // stack: x', y', x, y, retdest %jump(ec_add_valid_points) diff --git a/evm/src/cpu/kernel/asm/curve/common.asm b/evm/src/cpu/kernel/asm/curve/common.asm index 107dc63c..9e273c15 100644 --- a/evm/src/cpu/kernel/asm/curve/common.asm +++ b/evm/src/cpu/kernel/asm/curve/common.asm @@ -1,5 +1,4 @@ global ret_zero_ec_mul: - JUMPDEST // stack: x, y, s, retdest %pop3 // stack: retdest diff --git a/evm/src/cpu/kernel/asm/curve/secp256k1/curve_add.asm b/evm/src/cpu/kernel/asm/curve/secp256k1/curve_add.asm index 7f9c1fff..790fb116 100644 --- a/evm/src/cpu/kernel/asm/curve/secp256k1/curve_add.asm +++ b/evm/src/cpu/kernel/asm/curve/secp256k1/curve_add.asm @@ -3,7 +3,6 @@ // Secp256k1 elliptic curve addition. // Assumption: (x0,y0) and (x1,y1) are valid points. global ec_add_valid_points_secp: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Check if the first point is the identity. @@ -57,7 +56,6 @@ global ec_add_valid_points_secp: // Secp256k1 elliptic curve addition. // Assumption: (x0,y0) == (0,0) ec_add_first_zero: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Just return (x1,y1) @@ -72,7 +70,6 @@ ec_add_first_zero: // Secp256k1 elliptic curve addition. // Assumption: (x1,y1) == (0,0) ec_add_snd_zero: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Just return (x1,y1) @@ -93,7 +90,6 @@ ec_add_snd_zero: // Secp256k1 elliptic curve addition. // Assumption: lambda = (y0 - y1)/(x0 - x1) ec_add_valid_points_with_lambda: - JUMPDEST // stack: lambda, x0, y0, x1, y1, retdest // Compute x2 = lambda^2 - x1 - x0 @@ -150,7 +146,6 @@ ec_add_valid_points_with_lambda: // Secp256k1 elliptic curve addition. // Assumption: (x0,y0) and (x1,y1) are valid points and x0 == x1 ec_add_equal_first_coord: - JUMPDEST // stack: x0, y0, x1, y1, retdest with x0 == x1 // Check if the points are equal @@ -179,7 +174,6 @@ ec_add_equal_first_coord: // Assumption: x0 == x1 and y0 == y1 // Standard doubling formula. ec_add_equal_points: - JUMPDEST // stack: x0, y0, x1, y1, retdest // Compute lambda = 3/2 * x0^2 / y0 @@ -207,7 +201,6 @@ ec_add_equal_points: // Assumption: (x0,y0) is a valid point. // Standard doubling formula. global ec_double_secp: - JUMPDEST // stack: x0, y0, retdest DUP2 // stack: y0, x0, y0, retdest diff --git a/evm/src/cpu/kernel/asm/curve/secp256k1/curve_mul.asm b/evm/src/cpu/kernel/asm/curve/secp256k1/curve_mul.asm index f0825e88..892d57c0 100644 --- a/evm/src/cpu/kernel/asm/curve/secp256k1/curve_mul.asm +++ b/evm/src/cpu/kernel/asm/curve/secp256k1/curve_mul.asm @@ -1,6 +1,5 @@ // Same algorithm as in `exp.asm` global ec_mul_valid_point_secp: - JUMPDEST // stack: x, y, s, retdest %stack (x,y) -> (x,y,x,y) %ec_isidentity @@ -13,7 +12,6 @@ global ec_mul_valid_point_secp: %jump(ret_zero_ec_mul) step_case: - JUMPDEST // stack: x, y, s, retdest PUSH recursion_return // stack: recursion_return, x, y, s, retdest @@ -33,12 +31,10 @@ step_case: // Assumption: 2(x,y) = (x',y') step_case_contd: - JUMPDEST // stack: x', y', s / 2, recursion_return, x, y, s, retdest %jump(ec_mul_valid_point_secp) recursion_return: - JUMPDEST // stack: x', y', x, y, s, retdest SWAP4 // stack: s, y', x, y, x', retdest @@ -71,6 +67,5 @@ recursion_return: JUMP odd_scalar: - JUMPDEST // stack: x', y', x, y, retdest %jump(ec_add_valid_points_secp) diff --git a/evm/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm b/evm/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm index 538a86dc..96e177ff 100644 --- a/evm/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm +++ b/evm/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm @@ -1,6 +1,5 @@ // ecrecover precompile. global ecrecover: - JUMPDEST // stack: hash, v, r, s, retdest // Check if inputs are valid. @@ -47,7 +46,6 @@ global ecrecover: // let u2 = -hash * r_inv; // return u1*P + u2*GENERATOR; ecrecover_valid_input: - JUMPDEST // stack: hash, y, r, s, retdest // Compute u1 = s * r^(-1) @@ -83,7 +81,6 @@ ecrecover_valid_input: // ecrecover precompile. // Assumption: (X,Y) = u1 * P. Result is (X,Y) + u2*GENERATOR ecrecover_with_first_point: - JUMPDEST // stack: X, Y, hash, r^(-1), retdest %secp_scalar // stack: p, X, Y, hash, r^(-1), retdest @@ -132,7 +129,6 @@ ecrecover_with_first_point: // Take a public key (PKx, PKy) and return the associated address KECCAK256(PKx || PKy)[-20:]. pubkey_to_addr: - JUMPDEST // stack: PKx, PKy, retdest PUSH 0 // stack: 0, PKx, PKy, retdest diff --git a/evm/src/cpu/kernel/asm/exp.asm b/evm/src/cpu/kernel/asm/exp.asm index 3640b2f6..f025e312 100644 --- a/evm/src/cpu/kernel/asm/exp.asm +++ b/evm/src/cpu/kernel/asm/exp.asm @@ -10,7 +10,6 @@ /// Note that this correctly handles exp(0, 0) == 1. global exp: - jumpdest // stack: x, e, retdest dup2 // stack: e, x, e, retdest @@ -27,7 +26,6 @@ global exp: jump step_case: - jumpdest // stack: x, e, retdest push recursion_return // stack: recursion_return, x, e, retdest @@ -43,7 +41,6 @@ step_case: // stack: x * x, e / 2, recursion_return, x, e, retdest %jump(exp) recursion_return: - jumpdest // stack: exp(x * x, e / 2), x, e, retdest push 2 // stack: 2, exp(x * x, e / 2), x, e, retdest diff --git a/evm/src/cpu/kernel/asm/memory/memcpy.asm b/evm/src/cpu/kernel/asm/memory/memcpy.asm index 0a390736..3feca35d 100644 --- a/evm/src/cpu/kernel/asm/memory/memcpy.asm +++ b/evm/src/cpu/kernel/asm/memory/memcpy.asm @@ -4,7 +4,6 @@ // DST = (dst_ctx, dst_segment, dst_addr). // These tuple definitions are used for brevity in the stack comments below. global memcpy: - JUMPDEST // stack: DST, SRC, count, retdest DUP7 // stack: count, DST, SRC, count, retdest @@ -44,7 +43,6 @@ global memcpy: %jump(memcpy) memcpy_finish: - JUMPDEST // stack: DST, SRC, count, retdest %pop7 // stack: retdest diff --git a/evm/src/cpu/kernel/asm/rlp/decode.asm b/evm/src/cpu/kernel/asm/rlp/decode.asm index 0388276a..5749aee7 100644 --- a/evm/src/cpu/kernel/asm/rlp/decode.asm +++ b/evm/src/cpu/kernel/asm/rlp/decode.asm @@ -12,7 +12,6 @@ // Pre stack: pos, retdest // Post stack: pos', len global decode_rlp_string_len: - JUMPDEST // stack: pos, retdest DUP1 %mload_current(@SEGMENT_RLP_RAW) @@ -32,7 +31,6 @@ global decode_rlp_string_len: JUMP decode_rlp_string_len_medium: - JUMPDEST // String is 0-55 bytes long. First byte contains the len. // stack: first_byte, pos, retdest %sub_const(0x80) @@ -44,7 +42,6 @@ decode_rlp_string_len_medium: JUMP decode_rlp_string_len_large: - JUMPDEST // String is >55 bytes long. First byte contains the len of the len. // stack: first_byte, pos, retdest %sub_const(0xb7) @@ -69,7 +66,6 @@ decode_rlp_string_len_large: // bytes, so that the result can be returned as a single word on the stack. // As per the spec, scalars must not have leading zeros. global decode_rlp_scalar: - JUMPDEST // stack: pos, retdest PUSH decode_int_given_len // stack: decode_int_given_len, pos, retdest @@ -91,7 +87,6 @@ global decode_rlp_scalar: // Pre stack: pos, retdest // Post stack: pos', len global decode_rlp_list_len: - JUMPDEST // stack: pos, retdest DUP1 %mload_current(@SEGMENT_RLP_RAW) @@ -116,7 +111,6 @@ global decode_rlp_list_len: JUMP decode_rlp_list_len_big: - JUMPDEST // The length of the length is first_byte - 0xf7. // stack: first_byte, pos', retdest %sub_const(0xf7) @@ -137,7 +131,6 @@ decode_rlp_list_len_big: // Pre stack: pos, len, retdest // Post stack: pos', int decode_int_given_len: - JUMPDEST %stack (pos, len, retdest) -> (pos, len, pos, retdest) ADD // stack: end_pos, pos, retdest @@ -147,7 +140,6 @@ decode_int_given_len: // stack: acc, pos, end_pos, retdest decode_int_given_len_loop: - JUMPDEST // stack: acc, pos, end_pos, retdest DUP3 DUP3 @@ -171,6 +163,5 @@ decode_int_given_len_loop: %jump(decode_int_given_len_loop) decode_int_given_len_finish: - JUMPDEST %stack (acc, pos, end_pos, retdest) -> (retdest, pos, acc) JUMP diff --git a/evm/src/cpu/kernel/asm/rlp/read_to_memory.asm b/evm/src/cpu/kernel/asm/rlp/read_to_memory.asm index ae75e3d7..db474b9b 100644 --- a/evm/src/cpu/kernel/asm/rlp/read_to_memory.asm +++ b/evm/src/cpu/kernel/asm/rlp/read_to_memory.asm @@ -5,7 +5,6 @@ // Post stack: (empty) global read_rlp_to_memory: - JUMPDEST // stack: retdest PROVER_INPUT // Read the RLP blob length from the prover tape. // stack: len, retdest @@ -13,7 +12,6 @@ global read_rlp_to_memory: // stack: pos, len, retdest read_rlp_to_memory_loop: - JUMPDEST // stack: pos, len, retdest DUP2 DUP2 @@ -32,7 +30,6 @@ read_rlp_to_memory_loop: %jump(read_rlp_to_memory_loop) read_rlp_to_memory_finish: - JUMPDEST // stack: pos, len, retdest %pop2 // stack: retdest diff --git a/evm/src/cpu/kernel/asm/transactions/router.asm b/evm/src/cpu/kernel/asm/transactions/router.asm index 01a65fec..47a899c9 100644 --- a/evm/src/cpu/kernel/asm/transactions/router.asm +++ b/evm/src/cpu/kernel/asm/transactions/router.asm @@ -3,7 +3,6 @@ // jump to the appropriate transaction parsing method. global route_txn: - JUMPDEST // stack: (empty) // First load transaction data into memory, where it will be parsed. PUSH read_txn_from_memory @@ -11,7 +10,6 @@ global route_txn: // At this point, the raw txn data is in memory. read_txn_from_memory: - JUMPDEST // stack: (empty) // We will peak at the first byte to determine what type of transaction this is. diff --git a/evm/src/cpu/kernel/asm/transactions/type_0.asm b/evm/src/cpu/kernel/asm/transactions/type_0.asm index 7c8488f7..3f258624 100644 --- a/evm/src/cpu/kernel/asm/transactions/type_0.asm +++ b/evm/src/cpu/kernel/asm/transactions/type_0.asm @@ -12,7 +12,6 @@ // keccak256(rlp([nonce, gas_price, gas_limit, to, value, data])) global process_type_0_txn: - JUMPDEST // stack: (empty) PUSH 0 // initial pos // stack: pos diff --git a/evm/src/cpu/kernel/asm/transactions/type_1.asm b/evm/src/cpu/kernel/asm/transactions/type_1.asm index 5b9d2cdf..9d45c1e4 100644 --- a/evm/src/cpu/kernel/asm/transactions/type_1.asm +++ b/evm/src/cpu/kernel/asm/transactions/type_1.asm @@ -7,6 +7,5 @@ // data, access_list])) global process_type_1_txn: - JUMPDEST // stack: (empty) PANIC // TODO: Unfinished diff --git a/evm/src/cpu/kernel/asm/transactions/type_2.asm b/evm/src/cpu/kernel/asm/transactions/type_2.asm index 9807f88f..b2a862c1 100644 --- a/evm/src/cpu/kernel/asm/transactions/type_2.asm +++ b/evm/src/cpu/kernel/asm/transactions/type_2.asm @@ -8,6 +8,5 @@ // access_list])) global process_type_2_txn: - JUMPDEST // stack: (empty) PANIC // TODO: Unfinished diff --git a/evm/src/cpu/kernel/asm/util/assertions.asm b/evm/src/cpu/kernel/asm/util/assertions.asm index 69193e5f..0051219c 100644 --- a/evm/src/cpu/kernel/asm/util/assertions.asm +++ b/evm/src/cpu/kernel/asm/util/assertions.asm @@ -1,7 +1,6 @@ // It is convenient to have a single panic routine, which we can jump to from // anywhere. global panic: - JUMPDEST PANIC // Consumes the top element and asserts that it is zero. diff --git a/evm/src/cpu/kernel/interpreter.rs b/evm/src/cpu/kernel/interpreter.rs index 17be0523..64d70529 100644 --- a/evm/src/cpu/kernel/interpreter.rs +++ b/evm/src/cpu/kernel/interpreter.rs @@ -250,7 +250,7 @@ impl<'a> Interpreter<'a> { 0x58 => todo!(), // "GETPC", 0x59 => todo!(), // "MSIZE", 0x5a => todo!(), // "GAS", - 0x5b => (), // "JUMPDEST", + 0x5b => self.run_jumpdest(), // "JUMPDEST", 0x5c => todo!(), // "GET_STATE_ROOT", 0x5d => todo!(), // "SET_STATE_ROOT", 0x5e => todo!(), // "GET_RECEIPT_ROOT", @@ -490,6 +490,10 @@ impl<'a> Interpreter<'a> { } } + fn run_jumpdest(&mut self) { + assert!(!self.kernel_mode, "JUMPDEST is not needed in kernel code"); + } + fn jump_to(&mut self, offset: usize) { // The JUMPDEST rule is not enforced in kernel mode. if !self.kernel_mode && self.jumpdests.binary_search(&offset).is_err() {