-
Notifications
You must be signed in to change notification settings - Fork 227
[VM2] Account Contract support #5316
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
Merged
darthsiroftardis
merged 16 commits into
casper-network:feat-2.1
from
darthsiroftardis:ac-support
Sep 29, 2025
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
51421a8
Initial WIP
4b1716d
wip pt. 2
83ac5ba
Fix incorrect routing to vm1
0608608
Println cleanup
17f67c9
Harness test passes
b97ad6d
Rework upgrade logic
edccd09
Address lints
217a091
Merge remote-tracking branch 'refs/remotes/upstream/feat-2.1' into ac…
fd2bfb9
Add bytecode indirection for vm2 contracts
d2c1e6d
Remove prints and address PR feedback
acc600f
Get harness test passing
db2f2a3
Fix Upgrade logic for VM2
a0e32e3
run make lint
74eeb45
All vm2 tests passing
b6d3476
Address lint
766f7dc
Merge remote-tracking branch 'refs/remotes/upstream/feat-2.1' into ac…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,8 @@ const DEFAULT_WASM_ENTRY_POINT: &str = "call"; | |
|
|
||
| const DEFAULT_MINT_TRANSFER_GAS_COST: u64 = 1; // NOTE: Require gas while executing and set this to at least 100_000_000 (or use chainspec) | ||
|
|
||
| const NAME_FOR_V2_CONTRACT_MAIN_PURSE: &str = "__v2_main_purse"; | ||
darthsiroftardis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #[derive(Copy, Clone, Debug)] | ||
| pub enum ExecutorKind { | ||
| /// Ahead of time compiled Wasm. | ||
|
|
@@ -666,27 +668,112 @@ impl ExecutorV2 { | |
|
|
||
| (Bytes::from(wasm_bytes), entry_point.as_str()) | ||
| } | ||
| Some(StoredValue::Contract(_vm1_contract)) => { | ||
| let block_info = BlockInfo::new( | ||
| state_hash, | ||
| block_time, | ||
| parent_block_hash, | ||
| block_height, | ||
| self.execution_engine_v1.config().protocol_version(), | ||
| ); | ||
| Some(StoredValue::Contract(contract)) => { | ||
| let byte_code_addr = | ||
| ByteCodeAddr::V2CasperWasm(contract.contract_wasm_hash().value()); | ||
|
|
||
| let wasm_key = Key::ByteCode(byte_code_addr); | ||
|
|
||
| match tracking_copy.read(&wasm_key).map_err(|read_err| { | ||
| error!("Error when fetching wasm_bytes {wasm_key}. Details {read_err}"); | ||
| ExecuteError::InternalHost(InternalHostError::TrackingCopy) | ||
| })? { | ||
| Some(StoredValue::ByteCode(bytecode)) => { | ||
| if transferred_value != 0 { | ||
| // TODO: consult w/ Michal re: charge timing | ||
| let gas_usage = GasUsage::new(gas_limit, gas_limit); | ||
|
|
||
| let runtime_footprint = match tracking_copy | ||
| .runtime_footprint_by_entity_addr(entity_addr) | ||
| { | ||
| Ok(footprint) => footprint, | ||
| Err(_) => { | ||
| println!("1"); | ||
mpapierski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
darthsiroftardis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Err(ExecuteError::EntityNotFound(caller_key)); | ||
| } | ||
| }; | ||
|
|
||
| let main_purse = contract | ||
| .named_keys() | ||
| .get("__v2_main_purse") | ||
mpapierski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .ok_or(ExecuteError::MainPurseNotFound(vm1_key))? | ||
| .into_uref() | ||
| .ok_or(ExecuteError::InvalidKeyForPurse(vm1_key))?; | ||
|
|
||
| match system::transfer( | ||
| &mut tracking_copy, | ||
| runtime_footprint, | ||
| TransferArgs::new( | ||
| runtime_native_config.clone(), | ||
| transaction_hash, | ||
| Arc::clone(&address_generator), | ||
| initiator, | ||
| caller_key, | ||
| gas_usage.remaining_points().into(), | ||
| source_purse, | ||
| main_purse, | ||
| transferred_value.into(), | ||
| ), | ||
| ) { | ||
| Ok(()) => {} | ||
| Err(DispatchError::Internal(internal_error)) => { | ||
| error!( | ||
| ?internal_error, | ||
| "Internal error while transferring value to the contract's purse", | ||
| ); | ||
| return Err(ExecuteError::InternalHost(internal_error)); | ||
| } | ||
| Err(DispatchError::Call(error)) => { | ||
| return Ok(ExecuteResult { | ||
| host_error: Some(error), | ||
| output: None, | ||
| gas_usage: GasUsage::new( | ||
| gas_limit, | ||
| gas_limit - DEFAULT_MINT_TRANSFER_GAS_COST, | ||
| ), | ||
| effects: tracking_copy.effects(), | ||
| cache: tracking_copy.cache(), | ||
| messages: tracking_copy.messages(), | ||
| }); | ||
| } | ||
| Err(error) => { | ||
| error!( | ||
| ?error, | ||
| "Dispatch error while transferring value to the contract's purse", | ||
| ); | ||
|
|
||
| let entity_addr = EntityAddr::SmartContract(*smart_contract_addr); | ||
|
|
||
| return self.execute_vm1_wasm_byte_code( | ||
| initiator, | ||
| &entity_addr, | ||
| entry_point.clone(), | ||
| &input, | ||
| &mut tracking_copy, | ||
| block_info, | ||
| transaction_hash, | ||
| gas_limit, | ||
| ); | ||
| println!("{:?}", error); | ||
mpapierski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
darthsiroftardis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
darthsiroftardis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return Err(ExecuteError::InternalHost( | ||
| InternalHostError::DispatchSystemContract, | ||
| )); | ||
| } | ||
| } | ||
| } | ||
| (Bytes::from(bytecode.take_bytes()), entry_point.as_str()) | ||
| } | ||
| Some(_) | None => { | ||
| let block_info = BlockInfo::new( | ||
| state_hash, | ||
| block_time, | ||
| parent_block_hash, | ||
| block_height, | ||
| self.execution_engine_v1.config().protocol_version(), | ||
| ); | ||
|
|
||
| let entity_addr = EntityAddr::SmartContract(*smart_contract_addr); | ||
|
|
||
| return self.execute_vm1_wasm_byte_code( | ||
| initiator, | ||
| &entity_addr, | ||
| entry_point.clone(), | ||
| &input, | ||
| &mut tracking_copy, | ||
| block_info, | ||
| transaction_hash, | ||
| gas_limit, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| Some(stored_value) => { | ||
| todo!( | ||
|
|
@@ -720,7 +807,13 @@ impl ExecutorV2 { | |
| ExecutionKind::Stored { | ||
| address: smart_contract_addr, | ||
| .. | ||
| } => Key::SmartContract(*smart_contract_addr), | ||
| } => { | ||
| if initial_tracking_copy.enable_addressable_entity() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ummm I've kept it mirrored to the field name in the chainspec to avoid confusion |
||
| Key::AddressableEntity(EntityAddr::SmartContract(*smart_contract_addr)) | ||
| } else { | ||
| Key::Hash(*smart_contract_addr) | ||
| } | ||
| } | ||
| ExecutionKind::SessionBytes(_wasm_bytes) => Key::Account(initiator), | ||
| ExecutionKind::System(_) => { | ||
| error!("System executions are not called in this way. This should be unreachable."); | ||
|
|
@@ -898,6 +991,7 @@ impl ExecutorV2 { | |
| let entry_point = entry_point.clone(); | ||
| let args = bytesrepr::deserialize_from_slice(input) | ||
| .map_err(|err| ExecuteError::InternalHost(InternalHostError::Bytesrepr(err)))?; | ||
|
|
||
| let phase = Phase::Session; | ||
|
|
||
| let wasm_v1_result = { | ||
|
|
@@ -1208,6 +1302,20 @@ fn get_purse_for_entity<R: GlobalStateReader>( | |
|
|
||
| Ok((entity_addr, addressable_entity.main_purse())) | ||
| } | ||
| StoredValue::Contract(contract) => { | ||
| let uref = contract | ||
| .named_keys() | ||
| .get(NAME_FOR_V2_CONTRACT_MAIN_PURSE) | ||
| .ok_or(ExecuteError::MainPurseNotFound(entity_key))? | ||
| .into_uref() | ||
| .ok_or(ExecuteError::InvalidKeyForPurse(entity_key))?; | ||
|
|
||
| let hash_addr = entity_key | ||
| .into_hash_addr() | ||
| .ok_or(ExecuteError::EntityNotFound(entity_key))?; | ||
|
|
||
| Ok((EntityAddr::SmartContract(hash_addr), uref)) | ||
| } | ||
| other => Err(ExecuteError::InternalHost( | ||
| InternalHostError::UnexpectedStoredValueVariant { | ||
| expected: "AddressableEntity or Account".to_string(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.