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

Commit

Permalink
Use opcode from context and OOG in Arithmetic Operations (#782)
Browse files Browse the repository at this point in the history
Time spent on this PR: 0.3

## Pull request type

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [x] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

All the Arithmetic opcodes use the same internal
`exec_arithmetic_operation` function with an extra `opcode`
parameter.

## What is the new behavior?

The opcode number is taken directly from the `ctx` and
`StopAndArithmeticOperations.exec_arithmetic_operation`
is consequently directly used in `evm.cairo`.

OOG during these opcodes is now raised.
  • Loading branch information
ClementWalter authored Nov 2, 2023
1 parent 93a622c commit e5d4cc3
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 638 deletions.
2 changes: 1 addition & 1 deletion scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ async def get_eoa(private_key=None, amount=10) -> Account:

async def eth_send_transaction(
to: Union[int, str],
gas: int,
data: Union[str, bytes],
gas: int = 21_000,
value: Union[int, str] = 0,
caller_eoa: Optional[Account] = None,
max_fee: Optional[int] = None,
Expand Down
24 changes: 24 additions & 0 deletions src/kakarot/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,28 @@ namespace Errors {
dw 'o';
dw 'n';
}

func outOfGas() -> (error_len: felt, error: felt*) {
let (error) = get_label_location(oog_error_message);
return (17, error);
oog_error_message:
dw 'K';
dw 'a';
dw 'k';
dw 'a';
dw 'r';
dw 'o';
dw 't';
dw ':';
dw ' ';
dw 'o';
dw 'u';
dw 't';
dw 'O';
dw 'f';
dw 'G';
dw 'a';
dw 's';
}
}
22 changes: 11 additions & 11 deletions src/kakarot/evm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ namespace EVM {
jmp rel offset;
call StopAndArithmeticOperations.exec_stop; // 0x0
ret;
call StopAndArithmeticOperations.exec_add; // 0x1
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x1
ret;
call StopAndArithmeticOperations.exec_mul; // 0x2
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x2
ret;
call StopAndArithmeticOperations.exec_sub; // 0x3
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x3
ret;
call StopAndArithmeticOperations.exec_div; // 0x4
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x4
ret;
call StopAndArithmeticOperations.exec_sdiv; // 0x5
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x5
ret;
call StopAndArithmeticOperations.exec_mod; // 0x6
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x6
ret;
call StopAndArithmeticOperations.exec_smod; // 0x7
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x7
ret;
call StopAndArithmeticOperations.exec_addmod; // 0x8
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x8
ret;
call StopAndArithmeticOperations.exec_mulmod; // 0x9
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0x9
ret;
call StopAndArithmeticOperations.exec_exp; // 0xa
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0xa
ret;
call StopAndArithmeticOperations.exec_signextend; // 0xb
call StopAndArithmeticOperations.exec_arithmetic_operation; // 0xb
ret;
call unknown_opcode; // 0xc
ret;
Expand Down
Loading

0 comments on commit e5d4cc3

Please sign in to comment.