mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 14:53:08 +00:00
Self-destruct list (#948)
This commit is contained in:
parent
a926dcad22
commit
8e04cbfe8d
@ -37,7 +37,7 @@ pub(crate) fn combined_kernel() -> Kernel {
|
||||
include_str!("asm/core/transfer.asm"),
|
||||
include_str!("asm/core/util.asm"),
|
||||
include_str!("asm/core/access_lists.asm"),
|
||||
include_str!("asm/core/selfdestruct_set.asm"),
|
||||
include_str!("asm/core/selfdestruct_list.asm"),
|
||||
include_str!("asm/curve/bls381/util.asm"),
|
||||
include_str!("asm/curve/bn254/curve_arithmetic/constants.asm"),
|
||||
include_str!("asm/curve/bn254/curve_arithmetic/curve_add.asm"),
|
||||
|
||||
@ -146,6 +146,7 @@ global process_contract_creation_txn_after_constructor:
|
||||
POP // TODO: Success will go into the receipt when we support that.
|
||||
// stack: leftover_gas, new_ctx, address, retdest
|
||||
%pay_coinbase_and_refund_sender
|
||||
// TODO: Delete accounts in self-destruct list and empty touched addresses.
|
||||
// stack: new_ctx, address, retdest
|
||||
POP
|
||||
POP
|
||||
@ -229,6 +230,7 @@ global process_message_txn_after_call:
|
||||
POP // TODO: Success will go into the receipt when we support that.
|
||||
// stack: leftover_gas, new_ctx, retdest
|
||||
%pay_coinbase_and_refund_sender
|
||||
// TODO: Delete accounts in self-destruct list and empty touched addresses.
|
||||
// stack: new_ctx, retdest
|
||||
POP
|
||||
JUMP
|
||||
|
||||
12
evm/src/cpu/kernel/asm/core/selfdestruct_list.asm
Normal file
12
evm/src/cpu/kernel/asm/core/selfdestruct_list.asm
Normal file
@ -0,0 +1,12 @@
|
||||
/// Self-destruct list.
|
||||
/// Implemented as an append-only array, with the length stored in the global metadata.
|
||||
|
||||
%macro insert_selfdestruct_list
|
||||
// stack: addr
|
||||
%mload_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN)
|
||||
%stack (len, addr) -> (len, addr, len)
|
||||
%mstore_kernel(@SEGMENT_SELFDESTRUCT_LIST) // Store new address at the end of the array.
|
||||
// stack: len
|
||||
%increment
|
||||
%mstore_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN) // Store new length.
|
||||
%endmacro
|
||||
@ -1,43 +0,0 @@
|
||||
/// Self-destruct set.
|
||||
/// Essentially the same code as in `access_lists.asm`, with the exception that the insert function doesn't return anything.
|
||||
/// TODO: Would it make sense to merge this with `access_lists.asm`?
|
||||
/// TODO: Look into using a more efficient data structure.
|
||||
|
||||
%macro insert_selfdestruct_set
|
||||
%stack (addr) -> (addr, %%after)
|
||||
%jump(insert_selfdestruct_set)
|
||||
%%after:
|
||||
// stack: (empty)
|
||||
%endmacro
|
||||
|
||||
/// Inserts the address into the self-destruct set if it is not already present.
|
||||
global insert_selfdestruct_set:
|
||||
// stack: addr, retdest
|
||||
%mload_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_SET_LEN)
|
||||
// stack: len, addr, retdest
|
||||
PUSH 0
|
||||
insert_selfdestruct_set_loop:
|
||||
%stack (i, len, addr, retdest) -> (i, len, i, len, addr, retdest)
|
||||
EQ %jumpi(insert_address)
|
||||
// stack: i, len, addr, retdest
|
||||
DUP1 %mload_kernel(@SEGMENT_SELFDESTRUCT_SET)
|
||||
// stack: loaded_addr, i, len, addr, retdest
|
||||
DUP4
|
||||
// stack: addr, loaded_addr, i, len, addr, retdest
|
||||
EQ %jumpi(insert_address_found)
|
||||
// stack: i, len, addr, retdest
|
||||
%increment
|
||||
%jump(insert_selfdestruct_set_loop)
|
||||
|
||||
insert_address:
|
||||
%stack (i, len, addr, retdest) -> (i, addr, len, retdest)
|
||||
%mstore_kernel(@SEGMENT_SELFDESTRUCT_SET) // Store new address at the end of the array.
|
||||
// stack: len, retdest
|
||||
%increment
|
||||
%mstore_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_SET_LEN) // Store new length.
|
||||
JUMP
|
||||
|
||||
insert_address_found:
|
||||
// stack: i, len, addr, retdest
|
||||
%pop3
|
||||
JUMP
|
||||
@ -46,7 +46,7 @@ global sys_selfdestruct:
|
||||
|
||||
// Insert address into the selfdestruct set.
|
||||
// stack: balance, address, recipient, kexit_info
|
||||
DUP2 %insert_selfdestruct_set
|
||||
DUP2 %insert_selfdestruct_list
|
||||
|
||||
// Set the balance of the address to 0.
|
||||
// stack: balance, address, recipient, kexit_info
|
||||
|
||||
@ -49,8 +49,8 @@ pub(crate) enum GlobalMetadata {
|
||||
AccessedAddressesLen = 23,
|
||||
/// Length of the storage keys access list.
|
||||
AccessedStorageKeysLen = 24,
|
||||
/// Length of the self-destruct set.
|
||||
SelfDestructSetLen = 25,
|
||||
/// Length of the self-destruct list.
|
||||
SelfDestructListLen = 25,
|
||||
}
|
||||
|
||||
impl GlobalMetadata {
|
||||
@ -82,7 +82,7 @@ impl GlobalMetadata {
|
||||
Self::RefundCounter,
|
||||
Self::AccessedAddressesLen,
|
||||
Self::AccessedStorageKeysLen,
|
||||
Self::SelfDestructSetLen,
|
||||
Self::SelfDestructListLen,
|
||||
]
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ impl GlobalMetadata {
|
||||
Self::RefundCounter => "GLOBAL_METADATA_REFUND_COUNTER",
|
||||
Self::AccessedAddressesLen => "GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN",
|
||||
Self::AccessedStorageKeysLen => "GLOBAL_METADATA_ACCESSED_STORAGE_KEYS_LEN",
|
||||
Self::SelfDestructSetLen => "GLOBAL_METADATA_SELFDESTRUCT_SET_LEN",
|
||||
Self::SelfDestructListLen => "GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ pub enum Segment {
|
||||
/// List of storage keys that have been accessed in the current transaction.
|
||||
AccessedStorageKeys = 24,
|
||||
/// List of addresses that have called SELFDESTRUCT in the current transaction.
|
||||
SelfDestructSet = 25,
|
||||
SelfDestructList = 25,
|
||||
}
|
||||
|
||||
impl Segment {
|
||||
@ -82,7 +82,7 @@ impl Segment {
|
||||
Self::BnPairing,
|
||||
Self::AccessedAddresses,
|
||||
Self::AccessedStorageKeys,
|
||||
Self::SelfDestructSet,
|
||||
Self::SelfDestructList,
|
||||
]
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ impl Segment {
|
||||
Segment::BnPairing => "SEGMENT_KERNEL_BN_PAIRING",
|
||||
Segment::AccessedAddresses => "SEGMENT_ACCESSED_ADDRESSES",
|
||||
Segment::AccessedStorageKeys => "SEGMENT_ACCESSED_STORAGE_KEYS",
|
||||
Segment::SelfDestructSet => "SEGMENT_SELFDESTRUCT_SET",
|
||||
Segment::SelfDestructList => "SEGMENT_SELFDESTRUCT_LIST",
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ impl Segment {
|
||||
Segment::BnPairing => 256,
|
||||
Segment::AccessedAddresses => 256,
|
||||
Segment::AccessedStorageKeys => 256,
|
||||
Segment::SelfDestructSet => 256,
|
||||
Segment::SelfDestructList => 256,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user