mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 00:03:10 +00:00
Merge branch 'fp318' of github.com:mir-protocol/plonky2 into fp381-opcodes
This commit is contained in:
commit
874805cc65
@ -55,12 +55,6 @@ global extcodesize:
|
|||||||
// stack: extcodesize(address), retdest
|
// stack: extcodesize(address), retdest
|
||||||
SWAP1 JUMP
|
SWAP1 JUMP
|
||||||
|
|
||||||
%macro codecopy
|
|
||||||
// stack: dest_offset, offset, size
|
|
||||||
%address
|
|
||||||
%extcodecopy
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
%macro extcodecopy
|
%macro extcodecopy
|
||||||
// stack: address, dest_offset, offset, size
|
// stack: address, dest_offset, offset, size
|
||||||
%stack (address, dest_offset, offset, size) -> (address, dest_offset, offset, size, %%after)
|
%stack (address, dest_offset, offset, size) -> (address, dest_offset, offset, size, %%after)
|
||||||
|
|||||||
@ -13,32 +13,11 @@ global sys_sgt:
|
|||||||
PANIC
|
PANIC
|
||||||
global sys_sar:
|
global sys_sar:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_origin:
|
|
||||||
PANIC
|
|
||||||
global sys_calldatasize:
|
|
||||||
PANIC
|
|
||||||
global sys_calldatacopy:
|
|
||||||
PANIC
|
|
||||||
global sys_codecopy:
|
|
||||||
PANIC
|
|
||||||
global sys_returndatasize:
|
|
||||||
PANIC
|
|
||||||
global sys_returndatacopy:
|
|
||||||
PANIC
|
|
||||||
global sys_blockhash:
|
global sys_blockhash:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_coinbase:
|
|
||||||
PANIC
|
|
||||||
global sys_timestamp:
|
|
||||||
PANIC
|
|
||||||
global sys_number:
|
|
||||||
PANIC
|
|
||||||
global sys_prevrandao:
|
global sys_prevrandao:
|
||||||
// TODO: What semantics will this have for Edge?
|
// TODO: What semantics will this have for Edge?
|
||||||
PANIC
|
PANIC
|
||||||
global sys_gaslimit:
|
|
||||||
// TODO: Return the block's gas limit.
|
|
||||||
PANIC
|
|
||||||
global sys_chainid:
|
global sys_chainid:
|
||||||
// TODO: Return the block's chain ID instead of the txn's, even though they should match.
|
// TODO: Return the block's chain ID instead of the txn's, even though they should match.
|
||||||
// stack: kexit_info
|
// stack: kexit_info
|
||||||
@ -48,8 +27,6 @@ global sys_chainid:
|
|||||||
// stack: chain_id, kexit_info
|
// stack: chain_id, kexit_info
|
||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
global sys_basefee:
|
|
||||||
PANIC
|
|
||||||
global sys_log0:
|
global sys_log0:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_log1:
|
global sys_log1:
|
||||||
|
|||||||
@ -104,6 +104,97 @@ global sys_msize:
|
|||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro calldatasize
|
||||||
|
%mload_context_metadata(@CTX_METADATA_CALLDATA_SIZE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_calldatasize:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%calldatasize
|
||||||
|
// stack: calldatasize, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro returndatasize
|
||||||
|
%mload_context_metadata(@CTX_METADATA_RETURNDATA_SIZE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_returndatasize:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%returndatasize
|
||||||
|
// stack: returndatasize, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro coinbase
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BENEFICIARY)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_coinbase:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%coinbase
|
||||||
|
// stack: coinbase, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro timestamp
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_TIMESTAMP)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_timestamp:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%timestamp
|
||||||
|
// stack: timestamp, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro blocknumber
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_NUMBER)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_number:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%blocknumber
|
||||||
|
// stack: blocknumber, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro blockgaslimit
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_LIMIT)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_gaslimit:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%blockgaslimit
|
||||||
|
// stack: blockgaslimit, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro basefee
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BASE_FEE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_basefee:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%basefee
|
||||||
|
// stack: basefee, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
%macro update_mem_words
|
%macro update_mem_words
|
||||||
// stack: num_words, kexit_info
|
// stack: num_words, kexit_info
|
||||||
%mem_words
|
%mem_words
|
||||||
|
|||||||
@ -118,3 +118,32 @@ sys_calldataload_after_mload_packing:
|
|||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
PANIC
|
PANIC
|
||||||
|
|
||||||
|
// Macro for {CALLDATA,CODE,RETURNDATA}COPY (W_copy in Yellow Paper).
|
||||||
|
%macro wcopy(segment)
|
||||||
|
// stack: kexit_info, dest_offset, offset, size
|
||||||
|
DUP4 %num_bytes_to_num_words %mul_const(@GAS_COPY) %add_const(@GAS_VERYLOW) %charge_gas
|
||||||
|
|
||||||
|
%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, dest_offset, offset, size, kexit_info)
|
||||||
|
ADD // TODO: check for overflow, see discussion here https://github.com/mir-protocol/plonky2/pull/930/files/a4ea0965d79561c345e2f77836c07949c7e0bc69#r1143630253
|
||||||
|
// stack: expanded_num_bytes, dest_offset, offset, size, kexit_info
|
||||||
|
DUP1 %ensure_reasonable_offset
|
||||||
|
%update_mem_bytes
|
||||||
|
|
||||||
|
GET_CONTEXT
|
||||||
|
%stack (context, dest_offset, offset, size, kexit_info) ->
|
||||||
|
(context, @SEGMENT_MAIN_MEMORY, dest_offset, context, $segment, offset, size, %%after, kexit_info)
|
||||||
|
%jump(memcpy)
|
||||||
|
%%after:
|
||||||
|
// stack: kexit_info
|
||||||
|
EXIT_KERNEL
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_calldatacopy:
|
||||||
|
%wcopy(@SEGMENT_CALLDATA)
|
||||||
|
|
||||||
|
global sys_codecopy:
|
||||||
|
%wcopy(@SEGMENT_CODE)
|
||||||
|
|
||||||
|
global sys_returndatacopy:
|
||||||
|
%wcopy(@SEGMENT_RETURNDATA)
|
||||||
|
|||||||
@ -15,3 +15,16 @@
|
|||||||
%mstore_kernel(@SEGMENT_NORMALIZED_TXN)
|
%mstore_kernel(@SEGMENT_NORMALIZED_TXN)
|
||||||
// stack: (empty)
|
// stack: (empty)
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
|
%macro origin
|
||||||
|
%mload_txn_field(@TXN_FIELD_ORIGIN)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_origin:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%origin
|
||||||
|
// stack: origin, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|||||||
@ -378,8 +378,13 @@ impl<T: FieldExt> Div for Fp2<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function which multiplies by the Fp2 element
|
/// This trait defines the method which multiplies
|
||||||
/// whose cube root we will adjoin in the next extension
|
/// by the Fp2 element t^3 whose cube root we will
|
||||||
|
/// adjoin in the subsequent cubic extension.
|
||||||
|
/// For BN254 this is 9+i, and for BLS381 it is 1+i.
|
||||||
|
/// It also defines the relevant FROB constants,
|
||||||
|
/// given by t^(p^n) and t^(p^2n) for various n,
|
||||||
|
/// used to compute the frobenius operations.
|
||||||
pub trait Adj: Sized {
|
pub trait Adj: Sized {
|
||||||
fn mul_adj(self) -> Self;
|
fn mul_adj(self) -> Self;
|
||||||
const FROB_T: [[Self; 6]; 2];
|
const FROB_T: [[Self; 6]; 2];
|
||||||
|
|||||||
@ -11,7 +11,9 @@ use crate::cpu::membus::NUM_GP_CHANNELS;
|
|||||||
use crate::cpu::simple_logic::eq_iszero::generate_pinv_diff;
|
use crate::cpu::simple_logic::eq_iszero::generate_pinv_diff;
|
||||||
use crate::generation::state::GenerationState;
|
use crate::generation::state::GenerationState;
|
||||||
use crate::memory::segments::Segment;
|
use crate::memory::segments::Segment;
|
||||||
|
use crate::witness::errors::MemoryError::{ContextTooLarge, SegmentTooLarge, VirtTooLarge};
|
||||||
use crate::witness::errors::ProgramError;
|
use crate::witness::errors::ProgramError;
|
||||||
|
use crate::witness::errors::ProgramError::MemoryError;
|
||||||
use crate::witness::memory::{MemoryAddress, MemoryOp};
|
use crate::witness::memory::{MemoryAddress, MemoryOp};
|
||||||
use crate::witness::util::{
|
use crate::witness::util::{
|
||||||
keccak_sponge_log, mem_read_gp_with_log_and_fill, mem_write_gp_log_and_fill,
|
keccak_sponge_log, mem_read_gp_with_log_and_fill, mem_write_gp_log_and_fill,
|
||||||
@ -632,9 +634,15 @@ pub(crate) fn generate_mstore_general<F: Field>(
|
|||||||
stack_pop_with_log_and_fill::<4, _>(state, &mut row)?;
|
stack_pop_with_log_and_fill::<4, _>(state, &mut row)?;
|
||||||
|
|
||||||
let address = MemoryAddress {
|
let address = MemoryAddress {
|
||||||
context: context.as_usize(),
|
context: context
|
||||||
segment: segment.as_usize(),
|
.try_into()
|
||||||
virt: virt.as_usize(),
|
.map_err(|_| MemoryError(ContextTooLarge { context }))?,
|
||||||
|
segment: segment
|
||||||
|
.try_into()
|
||||||
|
.map_err(|_| MemoryError(SegmentTooLarge { segment }))?,
|
||||||
|
virt: virt
|
||||||
|
.try_into()
|
||||||
|
.map_err(|_| MemoryError(VirtTooLarge { virt }))?,
|
||||||
};
|
};
|
||||||
let log_write = mem_write_gp_log_and_fill(4, address, state, &mut row, val);
|
let log_write = mem_write_gp_log_and_fill(4, address, state, &mut row, val);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user