Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of EIP-1153: Transient Storage using Disk Persistence and Lifecycle Management #1588

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
801dc0c
initial implementation of EIP-1153: Transient Storage - TODOs remain …
snissn Nov 20, 2024
ef679de
fix transient state error message
snissn Nov 21, 2024
a98c058
remove pub visibility from transient_data_lifespan. TODO still is com…
snissn Nov 21, 2024
9f3e90d
further implementation of lifecycle management for transient data, TO…
snissn Nov 21, 2024
2ee1d9d
update evm contract State to use transient_data a composite of transi…
snissn Dec 2, 2024
31180a1
cargo fmt
snissn Dec 2, 2024
56d2458
update comments on tests
snissn Dec 2, 2024
312299f
add tstorage test contract files
snissn Dec 3, 2024
757131f
use a non optimized delete method to clear transient storage. TODO up…
snissn Dec 3, 2024
eb894ae
failing tests that need to be investigated
snissn Dec 3, 2024
3dfe377
add test confirming transient storage is cleared
snissn Dec 4, 2024
ab808a2
more test debugging
snissn Dec 4, 2024
20aefb5
cargo fmt
snissn Dec 4, 2024
99c1e6b
fix cargo check nit
snissn Dec 4, 2024
2b811de
simplify transient test
snissn Dec 7, 2024
89311f9
support nested and reentry in transient storage in integration tests
snissn Dec 7, 2024
af6bb99
progress on fixing removing tranisent storage lifespan from system, b…
snissn Dec 7, 2024
661755a
Merge branch 'master' into feat/transient_storage
snissn Dec 7, 2024
d93167b
use clear instead of loop and delete
snissn Dec 7, 2024
0ceb2d8
Merge branch 'master' into mikers/feat-tstore-reload-stuck2
snissn Dec 7, 2024
250d133
use kamt clear in reload
snissn Dec 7, 2024
3052b34
merge
snissn Dec 7, 2024
e614a36
unused var
snissn Dec 7, 2024
978b49d
remove Options from transient data in state and handle None better to…
snissn Dec 10, 2024
a47c21e
add current_transient_data_lifespan to state and refactor get_current…
snissn Dec 10, 2024
e26e519
fmt
snissn Dec 10, 2024
4feec0f
set in call to true because transient data calls message() which has …
snissn Dec 10, 2024
3d5deba
Update actors/evm/src/interpreter/system.rs
snissn Dec 10, 2024
22963df
Revert "Update actors/evm/src/interpreter/system.rs"
snissn Dec 10, 2024
41c41de
Revert "Revert "Update actors/evm/src/interpreter/system.rs""
snissn Dec 11, 2024
837a003
get get_current_transient_data_lifespan throw an error if it cannot f…
snissn Dec 11, 2024
3c6d9a7
change transient data origin from id to Address
snissn Dec 12, 2024
037939a
Revert "change transient data origin from id to Address"
snissn Dec 12, 2024
dddf19c
remove test: origin is always an ID address
snissn Dec 12, 2024
646ac96
Merge branch 'master' into feat/transient_storage
snissn Dec 12, 2024
074e16f
remove unused import
snissn Dec 12, 2024
7a99e10
Merge branch 'feat/transient_storage' of github.com:filecoin-project/…
snissn Dec 12, 2024
fb8025d
remove duplicate comment
snissn Dec 13, 2024
2c8febf
use self.current_transient_data_lifespan
snissn Dec 13, 2024
f1ac779
get_current_transient_data_lifespan does not need to be public
snissn Dec 13, 2024
7c6ba37
remove match from get_current_transient_data_lifespan and use an unwr…
snissn Dec 13, 2024
a005cf7
remove error case from new
snissn Dec 13, 2024
8eed0c9
remove allow non snake case from transient storage tests
snissn Dec 13, 2024
133f7b5
Update actors/evm/src/interpreter/system.rs
snissn Dec 13, 2024
1b57940
Update actors/evm/tests/basic.rs
snissn Dec 13, 2024
685fd63
Update actors/evm/tests/contracts/TransientStorageTest.sol
snissn Dec 13, 2024
ff09cfa
Update actors/evm/tests/contracts/TransientStorageTest.sol
snissn Dec 13, 2024
b96dbe5
Update actors/evm/tests/contracts/TransientStorageTest.sol
snissn Dec 13, 2024
b7ac7ba
remove now unused solidity test contracts that have previously been r…
snissn Dec 14, 2024
a43f34a
Merge branch 'feat/transient_storage' of github.com:filecoin-project/…
snissn Dec 14, 2024
260f401
forge fmt and solc recompile
snissn Dec 14, 2024
a2e4b37
add comments to transient storage test file with test information
snissn Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fvm_shared = "4.5.1"
fvm_ipld_encoding = "0.5.0"
fvm_ipld_blockstore = "0.3.0"
fvm_ipld_hamt = "0.10.2"
fvm_ipld_kamt = "0.4.2"
fvm_ipld_kamt = "0.4.3"
fvm_ipld_amt = { version = "0.7.3" }
fvm_ipld_bitfield = "0.7.0"

Expand Down
4 changes: 4 additions & 0 deletions actors/evm/src/interpreter/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub mod opcodes {
0x59: MSIZE,
0x5a: GAS,
0x5b: JUMPDEST,
0x5c: TLOAD,
0x5d: TSTORE,
0x5e: MCOPY,
0x5F: PUSH0,
0x60: PUSH1,
Expand Down Expand Up @@ -400,6 +402,8 @@ mod tests {
MSTORE8,
SLOAD,
SSTORE,
TLOAD,
TSTORE,
LOG0,
LOG1,
LOG2,
Expand Down
20 changes: 0 additions & 20 deletions actors/evm/src/interpreter/instructions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ mod tests {
use cid::multihash::Multihash;
use cid::Cid;
use fil_actors_evm_shared::uints::U256;
use fil_actors_runtime::EAM_ACTOR_ID;
use fvm_ipld_encoding::{DAG_CBOR, IPLD_RAW};
use fvm_shared::address::Address as FilAddress;

Expand Down Expand Up @@ -364,25 +363,6 @@ mod tests {
};
}

#[test]
fn test_origin_ethaddr() {
let addr_bytes = hex_literal::hex!("FEEDFACECAFEBEEF000000000000000000001234");
let eth_addr = EthAddress(addr_bytes);
let fil_addr = FilAddress::new_delegated(EAM_ACTOR_ID, &addr_bytes).unwrap();
evm_unit_test! {
(rt) {
rt.in_call.replace(true);
rt.set_origin(fil_addr);
}
(m) {
ORIGIN;
}
m.step().expect("execution step failed");
assert_eq!(m.state.stack.len(), 1);
assert_eq!(m.state.stack.pop().unwrap(), eth_addr.as_evm_word());
};
}

#[test]
fn test_caller() {
evm_unit_test! {
Expand Down
2 changes: 2 additions & 0 deletions actors/evm/src/interpreter/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def_stdproc! { MSTORE(a, b) => memory::mstore }
def_stdproc! { MSTORE8(a, b) => memory::mstore8 }
def_stdfun! { SLOAD(a) => storage::sload }
def_stdproc! { SSTORE(a, b) => storage::sstore }
def_stdfun! { TLOAD(a) => storage::tload }
def_stdproc! { TSTORE(a, b) => storage::tstore }
def_stdfun! { MSIZE() => memory::msize }
def_stdfun! { GAS() => context::gas }
def_stdlog! { LOG0(0, ()) }
Expand Down
71 changes: 71 additions & 0 deletions actors/evm/src/interpreter/instructions/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ pub fn sstore(
system.set_storage(key, value)
}

#[inline]
pub fn tload(
_state: &mut ExecutionState,
system: &mut System<impl Runtime>,
location: U256,
) -> Result<U256, ActorError> {
// get from storage and place on stack
system.get_transient_storage(location)
}

#[inline]
pub fn tstore(
_state: &mut ExecutionState,
system: &mut System<impl Runtime>,
key: U256,
value: U256,
) -> Result<(), ActorError> {
if system.readonly {
return Err(ActorError::read_only("store called while read-only".into()));
}

system.set_transient_storage(key, value)
}

#[cfg(test)]
mod tests {
use fil_actors_evm_shared::uints::U256;
Expand Down Expand Up @@ -82,4 +106,51 @@ mod tests {
assert_eq!(m.system.get_storage(U256::from(0)).unwrap(), U256::from(0x42));
};
}

#[test]
fn test_tload() {
// happy path
evm_unit_test! {
(m) {
TLOAD;
}
m.system.set_transient_storage(U256::from(0), U256::from(0x42)).unwrap();
m.state.stack.push(U256::from(0)).unwrap();
let result = m.step();
assert!(result.is_ok(), "execution step failed");
assert_eq!(m.state.stack.len(), 1);
assert_eq!(m.state.stack.pop().unwrap(), U256::from(0x42));
};
}

#[test]
fn test_tload_oob() {
// oob access -- unitialized is zero
evm_unit_test! {
(m) {
TLOAD;
}
m.state.stack.push(U256::from(1234)).unwrap();
let result = m.step();
assert!(result.is_ok(), "execution step failed");
assert_eq!(m.state.stack.len(), 1);
assert_eq!(m.state.stack.pop().unwrap(), U256::from(0));
};
}

#[test]
fn test_tstore() {
evm_unit_test! {
(m) {
TSTORE;
}

m.state.stack.push(U256::from(0x42)).unwrap();
m.state.stack.push(U256::from(0)).unwrap();
let result = m.step();
assert!(result.is_ok(), "execution step failed");
assert_eq!(m.state.stack.len(), 0);
assert_eq!(m.system.get_transient_storage(U256::from(0)).unwrap(), U256::from(0x42));
};
}
}
20 changes: 20 additions & 0 deletions actors/evm/src/interpreter/precompiles/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ mod tests {
#[test]
fn bn_recover() {
let rt = MockRuntime::default();
rt.in_call.replace(true);
Stebalien marked this conversation as resolved.
Show resolved Hide resolved

let mut system = System::create(&rt).unwrap();

let input = &hex!(
Expand Down Expand Up @@ -357,6 +359,8 @@ mod tests {
let input = "foo bar baz boxy".as_bytes();

let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let expected = hex!("ace8597929092c14bd028ede7b07727875788c7e130278b5afed41940d965aba");
Expand All @@ -370,6 +374,8 @@ mod tests {
let input = "foo bar baz boxy".as_bytes();

let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let expected = hex!("0000000000000000000000004cd7a0452bd3d682e4cbd5fa90f446d7285b156a");
Expand All @@ -389,6 +395,8 @@ mod tests {
);

let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let expected = hex!("08");
Expand Down Expand Up @@ -450,6 +458,8 @@ mod tests {
#[test]
fn bn_add() {
let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let input = hex::decode(
Expand Down Expand Up @@ -519,6 +529,8 @@ mod tests {
];

let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

for (f, name) in tests {
Expand Down Expand Up @@ -546,6 +558,8 @@ mod tests {
&[(blake2f, "fail-blake2f")];

let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

for (f, name) in failures {
Expand All @@ -561,6 +575,8 @@ mod tests {
#[test]
fn bn_mul() {
let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let input = hex::decode(
Expand Down Expand Up @@ -614,6 +630,8 @@ mod tests {
#[test]
fn bn_pair() {
let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

let input = hex::decode(
Expand Down Expand Up @@ -701,6 +719,8 @@ mod tests {
fn blake2() {
use super::blake2f;
let rt = MockRuntime::default();
rt.in_call.replace(true);

let mut system = System::create(&rt).unwrap();

// // helper to turn EIP test cases into something readable
Expand Down
Loading
Loading