diff --git a/execution-core/CHANGELOG.md b/execution-core/CHANGELOG.md index 98f37f0d07..b0d7d6a0cf 100644 --- a/execution-core/CHANGELOG.md +++ b/execution-core/CHANGELOG.md @@ -81,8 +81,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 next_epoch, }` +### Added + +- Add `nonce` contract deploy transaction [#1884] + + [#1963]: https://github.com/dusk-network/rusk/issues/1963 [#1963]: https://github.com/dusk-network/rusk/issues/1856 +[#1884]: https://github.com/dusk-network/rusk/issues/1884 [#1882]: https://github.com/dusk-network/rusk/issues/1882 [#1723]: https://github.com/dusk-network/rusk/issues/1723 diff --git a/execution-core/src/transfer.rs b/execution-core/src/transfer.rs index db021f408c..5d904e0c8f 100644 --- a/execution-core/src/transfer.rs +++ b/execution-core/src/transfer.rs @@ -328,6 +328,8 @@ pub struct ContractDeploy { pub owner: Vec, /// Constructor arguments of the deployed contract. pub constructor_args: Option>, + /// Nonce for contract id uniqueness and vanity + pub nonce: u64, } /// All the data the transfer-contract needs to perform a contract-call. @@ -365,6 +367,8 @@ impl ContractDeploy { None => bytes.push(0), } + bytes.extend(self.nonce.to_bytes()); + bytes } @@ -385,10 +389,13 @@ impl ContractDeploy { _ => return Err(BytesError::InvalidData), }; + let nonce = u64::from_reader(&mut buf)?; + Ok(Self { bytecode, owner, constructor_args, + nonce, }) } } diff --git a/execution-core/src/transfer/transaction/moonlight.rs b/execution-core/src/transfer/transaction/moonlight.rs index dac7b49867..0a9e1bf7fc 100644 --- a/execution-core/src/transfer/transaction/moonlight.rs +++ b/execution-core/src/transfer/transaction/moonlight.rs @@ -91,6 +91,7 @@ impl Transaction { hash: deploy.bytecode.hash, bytes: Vec::new(), }, + nonce: deploy.nonce, })), }, *self.signature(), diff --git a/execution-core/src/transfer/transaction/phoenix.rs b/execution-core/src/transfer/transaction/phoenix.rs index 637f2565aa..4ea2b238e9 100644 --- a/execution-core/src/transfer/transaction/phoenix.rs +++ b/execution-core/src/transfer/transaction/phoenix.rs @@ -97,6 +97,7 @@ impl Transaction { hash: deploy.bytecode.hash, bytes: Vec::new(), }, + nonce: deploy.nonce, })), }, self.proof(), diff --git a/execution-core/tests/serialization.rs b/execution-core/tests/serialization.rs index a178f3050d..8bd6991274 100644 --- a/execution-core/tests/serialization.rs +++ b/execution-core/tests/serialization.rs @@ -165,10 +165,13 @@ fn phoenix_with_deploy() -> Result<(), Error> { let mut constructor_args = vec![0; 20]; rng.fill_bytes(&mut constructor_args); + let nonce = rng.next_u64(); + let deploy = ContractDeploy { bytecode, owner, constructor_args: Some(constructor_args), + nonce, }; let transaction = @@ -240,10 +243,13 @@ fn moonlight_with_deploy() -> Result<(), Error> { let mut constructor_args = vec![0; 20]; rng.fill_bytes(&mut constructor_args); + let nonce = rng.next_u64(); + let deploy = ContractDeploy { bytecode, owner, constructor_args: Some(constructor_args), + nonce, }; let transaction =