kkrt-labs / kakarot Goto Github PK
View Code? Open in Web Editor NEWKakarot is a zkEVM written in Cairo, leveraging the STARK proof system.
Home Page: https://kakarot.org
License: MIT License
Kakarot is a zkEVM written in Cairo, leveraging the STARK proof system.
Home Page: https://kakarot.org
License: MIT License
SINCE | GROUP |
---|---|
Frontier | Stack Memory Storage and Flow Operations |
Stack input
offset: offset in the memory in bytes.
value: 1-byte value to write in the memory (the least significant byte of the 32-byte stack value).
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Gas
static_gas = 3
dynamic_gas = memory_expansion_cost
The memory expansion cost explanation can be found here.
Describe the Feature Request
Implement the serie of SWAPX Swap Operations.
SINCE | GROUP |
---|---|
Frontier | Stop and Arithmetic Operations |
The state changes done by the current context are reverted in those cases:
All values are treated as two’s complement signed 256-bit integers. Note the overflow semantic when −2255 is negated.
a: integer numerator.
b: integer denominator.
a % b: integer result of the signed integer modulo. If the denominator is 0, the result will be 0.
Input Output
1 10 1
2 3
Input Output
1 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
2 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD
Reproduce in playground.
The state changes done by the current context are reverted in those cases:
SINCE GROUP
Frontier Stop and Arithmetic Operations
Reproduce in playground.
The state changes done by the current context are reverted in those cases:
SINCE GROUP Frontier Stop and Arithmetic Operations Index 1 is top of the stack. See PUSH.
All values are treated as two’s complement signed 256-bit integers. Note the overflow semantic when −2255 is negated.
a: integer. b: integer. c: integer.
a + b % c: integer result of the addition integer modulo.
The state changes done by the current context are reverted in those cases:
Frontier
Environmental Information
0x3a - GASPRICE: Get price of gas in current environment
Index 1 is top of the stack. See PUSH.
price
: gas price in wei per gas.Input | Output | |
---|---|---|
1 | 10 |
The state changes done by the current context are reverted in those cases:
Rename the intrinsic_gas_cost
field of the ExecutionContext
to gas_price
. This value is constant and should not have any helper to update it.
Update compute_intrinsic_gas_cost
to compute the true intrinsic gas cost using the call_context.calldata
.
The intrinsic gas cost is 21,000 per transaction plus the cost of input data (16 gas per non-zero byte and 4 gas per zero byte)
Return a felt
and not an updated context:
(self: model.ExecutionContext*) -> felt {
let base_cost = Constants.TRANSACTION_INTRINSIC_GAS_COST;
let calldata_cost = self.call_context.calldata_len * 16 // this is not accurate, but for this snippet, because some bytes are 0s
return base_cost + calldata_cost
In places where compute_intrinsic_gas_cost
was used, use compute_intrinsic_gas_cost
then increment_gas_used
.
SINCE GROUP
Frontier Stop and Arithmetic Operations
Reproduce in playground.
The state changes done by the current context are reverted in those cases:
SINCE GROUP Frontier Stop and Arithmetic Operations Index 1 is top of the stack. See PUSH.
All values are treated as two’s complement signed 256-bit integers. Note the overflow semantic when −2255 is negated.
a: integer. b: integer. c: integer.
a * b % c: integer result of the addition integer modulo.
The state changes done by the current context are reverted in those cases:
SINCE | GROUP |
---|---|
Frontier | Comparison & Bitwise Logic Operations |
The state changes done by the current context are reverted in those cases:
Stack input
a: integer.
Stack output
a == 0: 1 if a is 0, 0 otherwise.
Examples
Input Output Input Output
1 10 0 1 0 1
Reproduce in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
SINCE GROUP
Frontier - Comparison & Bitwise Logic Operations
Reproduce in playground.
a
: left side integer.b
: right side integer.a < b
: 1 if the left side is smaller, 0 otherwise.The state changes done by the current context are reverted in those cases:
Frontier
Stack, Memory, Storage and Flow Operations
0x54 - SLOAD
Index 1 is top of the stack. See PUSH.
key
: 32-byte key in storage.value
: 32-byte value corresponding to that key. 0 if that key was never written before.Storage key | Storage value |
---|---|
0 | 46 |
The state changes done by the current context are reverted in those cases:
The static cost is 0. If the accessed address is warm, the dynamic cost is 100. Otherwise the dynamic cost is 2100. See section access sets.
Frontier
Block Information
0x44 - DIFFICULTY: Get the block's difficulty
Index 1 is top of the stack. See PUSH.
difficulty
: current block difficulty.Input | Output | |
---|---|---|
1 | 10995000000000000 |
The state changes done by the current context are reverted in those cases:
@all-contributors please add @abdelhamidbakhta projectManagement
Frontier
Block Information
0x45 - GASLIMIT: Get the block's gas limit
Index 1 is top of the stack. See PUSH.
gasLimit
: gas limit.Input | Output | |
---|---|---|
1 | 0xffffffffffff |
The state changes done by the current context are reverted in those cases:
Describe the Feature Request
Implement the serie of DUPX Duplication Operations.
@all-contributors please add @abdelhamidbakhta for infrastructure, tests, doc and code
Byzantium
Environmental Information
0x3e - RETURNDATACOPY: Copy output data from the previous call to memory
Index 1 is top of the stack. See PUSH.
A sub context can be created with CALL, CALLCODE, DELEGATECALL or STATICCALL.
destOffset
: byte offset in the memory where the result will be copied.offset
: byte offset in the return data from the last executed sub context to copy.size
: byte size to copy.0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
The state changes done by the current context are reverted in those cases:
minimum_word_size = (size + 31) / 32
static_gas = 3
dynamic_gas = 3 * minimum_word_size + memory_expansion_cost
The memory expansion cost explanation can be found here.
Implement EQ (0x14) opcode
Frontier
Block Information
0x43 - NUMBER: Get the block's number
Index 1 is top of the stack. See PUSH.
blockNumber
: current block number.Input | Output | |
---|---|---|
1 | 1636704767 |
The state changes done by the current context are reverted in those cases:
SINCE | GROUP |
---|---|
Frontier | Stack Memory Storage and Flow Operations |
Index 1 is top of the stack. See PUSH.
offset
: offset in the memory in bytes.value
: the 32 bytes in memory starting at that offset. If it goes beyond its current size (see MSIZE), writes 0s.Stack input
offset: offset in the memory in bytes.
Stack output
value: the 32 bytes in memory starting at that offset. If it goes beyond its current size (see MSIZE), writes 0s.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Gas
static_gas = 3
dynamic_gas = memory_expansion_cost
The memory expansion cost explanation can be found here.
SINCE | GROUP |
---|---|
Frontier | Environmental Information |
Notes
Each instruction occupies one byte. In the case of a PUSH instruction, the bytes that need to be pushed are encoded after that, it thus increases the codesize accordingly.
Stack output
size: byte size of the code.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
Frontier
Stack, Memory, Storage and Flow Operations
0x5a - GAS
Index 1 is top of the stack. See PUSH.
Stack output
gas: remaining gas (after this instruction).
Example
See in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
Frontier
Environmental Information
0x37 - CALLDATACOPY
Index 1 is top of the stack. See PUSH.
For out of bound bytes, 0s will be copied.
destOffset
: byte offset in the memory where the result will be copied.offset
: byte offset in the calldata to copy.size
: byte size to copy.0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
The state changes done by the current context are reverted in those cases:
minimum_word_size = (size + 31) / 32
static_gas = 3
dynamic_gas = 3 * minimum_word_size + memory_expansion_cost
The memory expansion cost explanation can be found here.
Frontier
System Operations
Equivalent to any other opcode not present in this reference, but guaranteed to remain an invalid instruction. Equivalent to REVERT (since Byzantium fork) with 0,0 as stack parameters, except that all the gas given to the current context is consumed.
Gas
All the remaining gas in this context is consumed.
SINCE | GROUP |
---|---|
Istanbul | Block Information |
chainId
: chain id of the network.Notes
Here are some chain ids (source):
Id Chain
1 Mainnet
3 Ropsten
4 Rinkeby
5 Goerli
6 Kotti
61 Classic
63 Mordor
212 Astor
2018 Dev
Stack output
chainId: chain id of the network.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
Frontier
Environmental Information
0x3f - EXTCODEHASH
Index 1 is top of the stack. See PUSH.
address
: 20-byte address of the account.hash
: hash of the chosen account's code, the empty hash (0xc5d24601...) if the account has no code, or 0 if the account does not exist or has been destroyed.Input | Output | |
---|---|---|
1 | 0x43a61f3f4c73ea0d444c5c1c1a8544067a86219b | 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 |
The state changes done by the current context are reverted in those cases:
The static cost is 0. If the accessed address is warm, the dynamic cost is 100. Otherwise the dynamic cost is 2600. See section access sets.
contract_account.bytecode()
to retrieve the code of the given contractbytecode_len, bytecode
array.Byzantium
Environmental Information
0x3d - RETURNDATASIZE
Index 1 is top of the stack. See PUSH.
A sub context can be created with CALL, CALLCODE, DELEGATECALL or STATICCALL.
size
: byte size of the return data from the last executed sub context.Input | Output | |
---|---|---|
1 | 32 |
The state changes done by the current context are reverted in those cases:
SINCE | GROUP |
---|---|
Frontier | Stop and Arithmetic Operations |
The state changes done by the current context are reverted in those cases:
Stack input
a: integer numerator.
b: integer denominator.
Stack output
a % b: integer result of the integer modulo. If the denominator is 0, the result will be 0.
Examples
Input Output Input Output
1 10 1 1 17 2
2 3 2 5
Reproduce in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Istanbul
Block Information
0x47 - SELFBALANCE
Index 1 is top of the stack. See PUSH.
Semantically equivalent of calling BALANCE with ADDRESS as parameter, but with a reduced gas cost.
balance
: balance of the current account in wei.Input | Output | |
---|---|---|
1 | 9 |
The state changes done by the current context are reverted in those cases:
Frontier
Stack, Memory, Storage and Flow Operations
0x55 - SSTORE
Index 1 is top of the stack. See PUSH.
key
: 32-byte key in storage.value
: 32-byte value to store.Input 1 | Input 2 | |||
---|---|---|---|---|
1 | 0 | 1 | 8965 | |
2 | 0xFFFF | 2 | 0xFF |
The state changes done by the current context are reverted in those cases:
static_gas = 0
if value == current_value
if key is warm
base_dynamic_gas = 100
else
base_dynamic_gas = 100
else if current_value == original_value
if original_value == 0
base_dynamic_gas = 20000
else
base_dynamic_gas = 2900
else
base_dynamic_gas = 100
On top of the cost above, 2100 is added to base_dynamic_gas
if the slot is cold. See section access sets.
if value != current_value
if current_value == original_value
if original_value != 0 and value == 0
gas_refunds += 4800
else
if original_value != 0
if current_value == 0
gas_refunds -= 4800
else if value == 0
gas_refunds += 4800
if value == original_value
if original_value == 0
if key is warm
gas_refunds += 20000 - 100
else
gas_refunds += 19900
else
if key is warm
gas_refunds += 5000 - 2100 - 100
else
gas_refunds += 4900
SINCE | GROUP |
---|---|
Frontier | Comparison & Bitwise Logic Operations |
Index 1 is top of the stack. See PUSH.
i
: byte offset starting from the most significant byte.x
: 32-byte value.y
: the indicated byte at the least significant position. If the byte offset is out of range, the result is 0.Stack input
i: byte offset starting from the most significant byte.
x: 32-byte value.
Stack output
y: the indicated byte at the least significant position. If the byte offset is out of range, the result is 0.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Frontier
Block Information
0x40 - BLOCKHASH: Get the hash of one of the 256 most recent complete blocks
Index 1 is top of the stack. See PUSH.
blockNumber
: block number to get the hash from. Valid range is the last 256 blocks (not including the current one). Current block number can be queried with NUMBER.hash
: hash of the chosen block, or 0 if the block number is not in the valid range.Input | Output | |
---|---|---|
1 | 599423545 | 0x29045A592007D0C246EF02C2223570DA9522D0CF0F73282C79A1BC8F0BB2C238 |
The state changes done by the current context are reverted in those cases:
Frontier
Stack, Memory, Storage and Flow Operations
0x59 - MSIZE
Get the size of active memory in bytes
The memory is always fully accessible. What this instruction tracks is the highest offset that was accessed in the current execution. A first write or read to a bigger offset will trigger a memory expansion, which will cost gas. The size is always a multiple of a word (32 bytes).
Stack output
size: current memory size in bytes (higher offset accessed until now + 1).
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
@all-contributors please add @0xMentorNotAPseudo for tests, doc, code
Implement 0x11 - GT opcode
Frontier
Stack, Memory, Storage and Flow Operations
0x56 - JUMP
Index 1 is top of the stack. See PUSH.
Notes
The program counter (PC) is a byte offset in the deployed code. It indicates which instruction will be executed next. When an ADD is executed, for example, the PC is incremented by 1, since the instruction is 1 byte. The PUSH instructions are bigger than one byte, and so will increment the counter accordingly.
The JUMP instruction alters the program counter, thus breaking the linear path of the execution to another point in the deployed code. It is used to implement functionalities like functions.
Stack input
counter: byte offset in the deployed code where execution will continue from. Must be a JUMPDEST instruction.
Example
See in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Counter offset is not a JUMPDEST. The error is generated even if the JUMP would not have been done.
SINCE | GROUP |
---|---|
Constantinople | Comparison & Bitwise Logic Operations |
Index 1 is top of the stack. See PUSH.
Shift the bits towards the most significant one. The bits moved after the 256th one are discarded, the new bits are set to 0.
shift
: number of bits to shift to the left.value
: 32 bytes to shift.value << shift
: the shifted value. If shift
is bigger than 255, returns 0.Notes
Shift the bits towards the most significant one. The bits moved after the 256th one are discarded, the new bits are set to 0.
Stack input
shift: number of bits to shift to the left.
value: 32 bytes to shift.
Stack output
value << shift: the shifted value. If shift is bigger than 255, returns 0.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Describe the Feature Request
Currently MSTORE
operation only account for static gas cost (3). It should also take into consideration dynamic gas cost related to memory expansion.
Memory expansion works as explained in this section: https://www.evm.codes/about#memoryexpansion
Describe Preferred Solution
Implement gas accounting that compute the dynamic gas cost of MSTORE.
Related Code
memory_operations
Frontier
Stack Memory Storage and Flow Operations
0x50 - POP
Index 1 is top of the stack. See PUSH.
y
: a stack item.Input | Output | |
---|---|---|
1 | 125985 |
The state changes done by the current context are reverted in those cases:
WIP: story to refine but generally speaking - design & refactor tests.
tests/cases
should be reviewed.For example, we have test_arithmetic_operations
which is IMO an integration test by chaining every arithmetic operation into one big operation. Same for test_duplication_operations
. We can't do the same for test_comparison_operations
.
Suggestion: the unit test scope of an opcode should be the opcode itself.
We should avoid using 00x.json
as the fixture's name. To allow the factorization of tests, payload of fixture should also accept an array of scenarios instead of just one scenario.
Frontier
Environmental Information
0x3b - EXTCODESIZE
Index 1 is top of the stack. See PUSH.
address
: 20-byte address of the contract to query.size
: byte size of the code.Input | Output | |
---|---|---|
1 | 0x43a61f3f4c73ea0d444c5c1c1a8544067a86219b | 32 |
The state changes done by the current context are reverted in those cases:
The static cost is 0. If the accessed address is warm, the dynamic cost is 100. Otherwise the dynamic cost is 2600. See section access sets.
SINCE | GROUP |
---|---|
Constantinople | Comparison & Bitwise Logic Operations |
Index 1 is top of the stack. See PUSH.
Shift the bits towards the least significant one. The bits moved before the first one are discarded, the new bits are set to 0 if the previous most significant bit was 0, otherwise the new bits are set to 1.
shift
: number of bits to shift to the right.value
: integer to shift.value >> shift
: the shifted value.Notes
Shift the bits towards the least significant one. The bits moved before the first one are discarded, the new bits are set to 0 if the previous most significant bit was 0, otherwise the new bits are set to 1.
Stack input
shift: number of bits to shift to the right.
value: integer to shift.
Stack output
value >> shift: the shifted value.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
SINCE | GROUP |
---|---|
Constantinople | Comparison & Bitwise Logic Operations |
Index 1 is top of the stack. See PUSH.
Shift the bits towards the least significant one. The bits moved before the first one are discarded, the new bits are set to 0.
shift
: number of bits to shift to the right.value
: 32 bytes to shift.value >> shift
: the shifted value. If shift
is bigger than 255, returns 0.Notes
Shift the bits towards the least significant one. The bits moved before the first one are discarded, the new bits are set to 0.
Stack input
shift: number of bits to shift to the right.
value: 32 bytes to shift.
Stack output
value >> shift: the shifted value. If shift is bigger than 255, returns 0.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Frontier
Environmental Information
0x39 - CODECOPY: Copy code running in current environment to memory
Index 1 is top of the stack. See PUSH.
For out of bound bytes, 0s will be copied.
destOffset
: byte offset in the memory where the result will be copied.offset
: byte offset in the code to copy.size
: byte size to copy.0x7DFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F
The state changes done by the current context are reverted in those cases:
minimum_word_size = (size + 31) / 32
static_gas = 3
dynamic_gas = 3 * minimum_word_size + memory_expansion_cost
The memory expansion cost explanation can be found here.
Frontier
Stack, Memory, Storage and Flow Operations
0x58 - PC
Notes
The program counter (PC) is a byte offset in the deployed code. It indicates which instruction will be executed next. When an ADD is executed, for example, the PC is incremented by 1, since the instruction is 1 byte. The PUSH instructions are bigger than one byte, and so will increment the counter accordingly.
Stack output
counter: PC of this instruction in the current program.
Example
See in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
Frontier
Stack, Memory, Storage and Flow Operations
0x57 - JUMPI
Index 1 is top of the stack. See PUSH.
Notes
The program counter (PC) is a byte offset in the deployed code. It indicates which instruction will be executed next. When an ADD is executed, for example, the PC is incremented by 1, since the instruction is 1 byte. The PUSH instructions are bigger than one byte, and so will increment the counter accordingly.
The JUMPI instruction may alter the program counter, thus breaking the linear path of the execution to another point in the deployed code. It is used to implement functionalities like loops and conditions.
Stack input
counter: byte offset in the deployed code where execution will continue from. Must be a JUMPDEST instruction.
b: the program counter will be altered with the new value only if this value is different from 0. Otherwise, the program counter is simply incremented and the next instruction will be executed.
Example
See in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Not enough values on the stack.
Counter offset is not a JUMPDEST. The error is generated only if the JUMP would have been done.
SINCE | GROUP |
---|---|
Frontier | Block Information |
The state changes done by the current context are reverted in those cases:
Stack output
address: miner's 20-byte address.
Example
Input Output
1 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
Error cases
The state changes done by the current context are reverted in those cases:
Not enough gas.
Stack overflow.
Frontier
Environmental Information
0x3c - EXTCODECOPY: Copy an account's code to memory
Index 1 is top of the stack. See PUSH.
For out of bound bytes, 0s will be copied.
address
: 20-byte address of the contract to query.destOffset
: byte offset in the memory where the result will be copied.offset
: byte offset in the code to copy.size
: byte size to copy.0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
The state changes done by the current context are reverted in those cases:
minimum_word_size = (size + 31) / 32
static_gas = 0
dynamic_gas = 3 * minimum_word_size + memory_expansion_cost + address_access_cost
The memory expansion cost explanation can be found here. If the accessed address is warm, address_access_cost
is 100, otherwise it is 2600. See section access sets.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.