Skip to content

Commit

Permalink
dev: remove kakarot precompiles (#224)
Browse files Browse the repository at this point in the history
Closes #164
  • Loading branch information
enitrat authored Dec 9, 2024
1 parent f8ffa6e commit 335d77e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 343 deletions.
2 changes: 0 additions & 2 deletions cairo/src/evm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ namespace EVM {
is_create=evm.message.is_create,
depth=evm.message.depth,
env=evm.message.env,
cairo_precompile_called=evm.message.cairo_precompile_called,
);

tempvar evm = new model.EVM(
Expand Down Expand Up @@ -285,7 +284,6 @@ namespace EVM {
is_create=self.message.is_create,
depth=self.message.depth,
env=self.message.env,
cairo_precompile_called=self.message.cairo_precompile_called,
);

if (is_valid_jumpdest == FALSE) {
Expand Down
26 changes: 0 additions & 26 deletions cairo/src/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ namespace SystemOperations {
is_create=TRUE,
depth=evm.message.depth + 1,
env=evm.message.env,
cairo_precompile_called=evm.message.cairo_precompile_called,
);
let child_evm = EVM.init(message, gas_limit);
let stack = Stack.init();
Expand Down Expand Up @@ -915,7 +914,6 @@ namespace CallHelper {
is_create=FALSE,
depth=evm.message.depth + 1,
env=evm.message.env,
cairo_precompile_called=evm.message.cairo_precompile_called,
);

let child_evm = EVM.init(message, gas);
Expand Down Expand Up @@ -954,9 +952,6 @@ namespace CallHelper {
}
let state = cast([ap - 1], model.State*);

let cairo_precompile_called = evm.message.cairo_precompile_called +
evm.message.parent.evm.message.cairo_precompile_called;

tempvar message = new model.Message(
bytecode=evm.message.parent.evm.message.bytecode,
bytecode_len=evm.message.parent.evm.message.bytecode_len,
Expand All @@ -973,17 +968,8 @@ namespace CallHelper {
is_create=evm.message.parent.evm.message.is_create,
depth=evm.message.parent.evm.message.depth,
env=evm.message.parent.evm.message.env,
cairo_precompile_called=cairo_precompile_called,
);

if (evm.reverted != FALSE) {
// If a call to a cairo precompile has been made, the tx should be reverted
with_attr error_message(
"EVM tx reverted, reverting SN tx because of previous calls to cairo precompiles") {
assert cairo_precompile_called = FALSE;
}
}

if (evm.reverted == Errors.EXCEPTIONAL_HALT) {
// If the call has halted exceptionnaly, the return_data is empty
// and nothing is copied to memory, and the gas is not returned;
Expand Down Expand Up @@ -1155,9 +1141,6 @@ namespace CreateHelper {
}(evm: model.EVM*) -> model.EVM* {
alloc_locals;

let cairo_precompile_called = evm.message.cairo_precompile_called +
evm.message.parent.evm.message.cairo_precompile_called;

tempvar message = new model.Message(
bytecode=evm.message.parent.evm.message.bytecode,
bytecode_len=evm.message.parent.evm.message.bytecode_len,
Expand All @@ -1174,14 +1157,9 @@ namespace CreateHelper {
is_create=evm.message.parent.evm.message.is_create,
depth=evm.message.parent.evm.message.depth,
env=evm.message.parent.evm.message.env,
cairo_precompile_called=cairo_precompile_called,
);
// Reverted during execution - either REVERT or exceptional
if (evm.reverted != FALSE) {
with_attr error_message(
"EVM tx reverted, reverting SN tx because of previous calls to cairo precompiles") {
assert cairo_precompile_called = FALSE;
}
let is_exceptional_revert = is_not_zero(Errors.REVERT - evm.reverted);
let return_data_len = (1 - is_exceptional_revert) * evm.return_data_len;
let gas_left = evm.message.parent.evm.gas_left + (1 - is_exceptional_revert) *
Expand Down Expand Up @@ -1228,10 +1206,6 @@ namespace CreateHelper {

if (success == FALSE) {
tempvar state = evm.message.parent.state;
with_attr error_message(
"EVM tx reverted, reverting SN tx because of previous calls to cairo precompiles") {
assert cairo_precompile_called = FALSE;
}
tempvar evm = new model.EVM(
message=message,
Expand Down
24 changes: 2 additions & 22 deletions cairo/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ from src.instructions.system_operations import CallHelper, CreateHelper, SystemO
from src.memory import Memory
from src.model import model
from src.precompiles.precompiles import Precompiles
from src.precompiles.precompiles_helpers import PrecompilesHelpers
from src.stack import Stack
from src.state import State
from src.gas import Gas, GAS_INIT_CODE_WORD_COST
Expand Down Expand Up @@ -58,34 +57,17 @@ namespace Interpreter {
let pc = evm.program_counter;
let is_pc_ge_code_len = is_nn(pc - evm.message.bytecode_len);
if (is_pc_ge_code_len != FALSE) {
let is_precompile = PrecompilesHelpers.is_precompile(evm.message.code_address);
let is_precompile = Precompiles.is_precompile(evm.message.code_address);
if (is_precompile != FALSE) {
let parent_context = evm.message.parent;
let is_parent_zero = Helpers.is_zero(cast(parent_context, felt));
if (is_parent_zero != FALSE) {
// Case A: The precompile is called straight from an EOA
tempvar caller_code_address = evm.message.caller;
} else {
// Case B: The precompile is called from a contract
tempvar caller_code_address = parent_context.evm.message.code_address;
}
tempvar caller_address = evm.message.caller;
let (
output_len, output, gas_used, precompile_reverted
) = Precompiles.exec_precompile(
evm.message.code_address,
evm.message.calldata_len,
evm.message.calldata,
caller_code_address,
caller_address,
evm.message.code_address, evm.message.calldata_len, evm.message.calldata
);
let evm = EVM.charge_gas(evm, gas_used);
let evm_reverted = is_not_zero(evm.reverted);
let success = (1 - precompile_reverted) * (1 - evm_reverted);
let evm = EVM.stop(evm, output_len, output, 1 - success);
let is_cairo_precompile_called = PrecompilesHelpers.is_kakarot_precompile(
evm.message.code_address
);
tempvar message = new model.Message(
bytecode=evm.message.bytecode,
bytecode_len=evm.message.bytecode_len,
Expand All @@ -102,7 +84,6 @@ namespace Interpreter {
is_create=evm.message.is_create,
depth=evm.message.depth,
env=evm.message.env,
cairo_precompile_called=is_cairo_precompile_called,
);
tempvar evm = new model.EVM(
message=message,
Expand Down Expand Up @@ -900,7 +881,6 @@ namespace Interpreter {
is_create=is_deploy_tx,
depth=0,
env=env,
cairo_precompile_called=FALSE,
);

let stack = Stack.init();
Expand Down
1 change: 0 additions & 1 deletion cairo/src/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ namespace model {
is_create: felt,
depth: felt,
env: Environment*,
cairo_precompile_called: felt,
}

// @dev Stores all data relevant to the current execution context.
Expand Down
67 changes: 0 additions & 67 deletions cairo/src/precompiles/kakarot_precompiles.cairo

This file was deleted.

Loading

0 comments on commit 335d77e

Please sign in to comment.