From 2c06c858dc66b42741dd51e190e34030d9c31a92 Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Wed, 24 Jul 2024 12:59:13 +0200 Subject: [PATCH] rusk: passing nonce and metadata for contract id generation --- rusk/CHANGELOG.md | 2 ++ rusk/src/lib/chain/rusk.rs | 10 +++++++--- rusk/tests/services/contract_deployment.rs | 13 ++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/rusk/CHANGELOG.md b/rusk/CHANGELOG.md index f5f6568727..5fe72d941d 100644 --- a/rusk/CHANGELOG.md +++ b/rusk/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add support for nonce and metadata in contract deployment [#1884] - Add execution of contract deployment [#1882] - Add first version of RUES, allowing websocket clients to subscribe for events emitted by block transitions [#931] @@ -210,6 +211,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add linking between Rusk and Protobuff structs - Add build system that generates keys for circuits and caches them. +[#1884]: https://github.com/dusk-network/rusk/issues/1884 [#1882]: https://github.com/dusk-network/rusk/issues/1882 [#1675]: https://github.com/dusk-network/rusk/issues/1675 [#1640]: https://github.com/dusk-network/rusk/issues/1640 diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 0ae63b1e9a..01b8980d8d 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -34,8 +34,8 @@ use node_data::ledger::{Slash, SpentTransaction, Transaction}; use rusk_abi::dusk::Dusk; use rusk_abi::ContractError::{OutOfGas, Panic}; use rusk_abi::{ - CallReceipt, ContractError, Error as PiecrustError, Event, Session, - STAKE_CONTRACT, TRANSFER_CONTRACT, VM, + gen_contract_id, CallReceipt, ContractError, Error as PiecrustError, Event, + Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM, }; use rusk_profile::to_rusk_state_id_path; use tokio::sync::broadcast; @@ -540,7 +540,11 @@ fn contract_deploy( receipt.data = Err(Panic("failed bytecode hash check".into())) } else { let result = session.deploy_raw( - None, + Some(gen_contract_id( + &deploy.bytecode.bytes, + deploy.nonce, + &deploy.metadata, + )), deploy.bytecode.bytes.as_slice(), deploy.constructor_args.clone(), deploy.owner.clone(), diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index e0d3c8db3f..e1f2d47c65 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -14,7 +14,7 @@ use rand::prelude::*; use rand::rngs::StdRng; use rusk::{Result, Rusk}; use rusk_abi::Error::ContractDoesNotExist; -use rusk_abi::{ContractData, ContractId}; +use rusk_abi::{gen_contract_id, ContractData, ContractId}; use rusk_recovery_tools::state; use tempfile::tempdir; use test_wallet::{self as wallet, Wallet}; @@ -78,7 +78,12 @@ fn initial_state>(dir: P, deploy_bob: bool) -> Result { bob_bytecode, ContractData::builder() .owner(OWNER) - .constructor_arg(&BOB_INIT_VALUE), + .constructor_arg(&BOB_INIT_VALUE) + .contract_id(gen_contract_id( + &bob_bytecode, + 0u64, + vec![], + )), POINT_LIMIT, ) .expect("Deploying the alice contract should succeed"); @@ -122,6 +127,8 @@ fn make_and_execute_transaction_deploy( }, owner: OWNER.to_vec(), constructor_args, + nonce: 0, + metadata: vec![], }), SENDER_INDEX, gas_limit, @@ -192,7 +199,7 @@ impl Fixture { "../../../target/dusk/wasm32-unknown-unknown/release/bob.wasm" ) .to_vec(); - let contract_id = bytecode_hash(bob_bytecode.as_slice()); + let contract_id = gen_contract_id(&bob_bytecode, 0u64, vec![]); let path = tmp.into_path(); Self {