diff --git a/execution-core/CHANGELOG.md b/execution-core/CHANGELOG.md index 98f37f0d07..4b7d57447e 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` and `metadata` to 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..907d4aa638 100644 --- a/execution-core/src/transfer.rs +++ b/execution-core/src/transfer.rs @@ -328,6 +328,10 @@ pub struct ContractDeploy { pub owner: Vec, /// Constructor arguments of the deployed contract. pub constructor_args: Option>, + /// Nonce for contract id uniqueness + pub nonce: u64, + /// Metadata + pub metadata: Vec, } /// All the data the transfer-contract needs to perform a contract-call. @@ -365,6 +369,11 @@ impl ContractDeploy { None => bytes.push(0), } + bytes.extend(self.nonce.to_bytes()); + + bytes.extend((self.metadata.len() as u64).to_bytes()); + bytes.extend(&self.metadata); + bytes } @@ -385,10 +394,16 @@ impl ContractDeploy { _ => return Err(BytesError::InvalidData), }; + let nonce = u64::from_reader(&mut buf)?; + + let metadata = read_vec(&mut buf)?; + Ok(Self { bytecode, owner, constructor_args, + nonce, + metadata, }) } } diff --git a/execution-core/src/transfer/transaction/moonlight.rs b/execution-core/src/transfer/transaction/moonlight.rs index dac7b49867..73d0404473 100644 --- a/execution-core/src/transfer/transaction/moonlight.rs +++ b/execution-core/src/transfer/transaction/moonlight.rs @@ -91,6 +91,8 @@ impl Transaction { hash: deploy.bytecode.hash, bytes: Vec::new(), }, + nonce: deploy.nonce, + metadata: deploy.metadata.clone(), })), }, *self.signature(), diff --git a/execution-core/src/transfer/transaction/phoenix.rs b/execution-core/src/transfer/transaction/phoenix.rs index 637f2565aa..d132649e08 100644 --- a/execution-core/src/transfer/transaction/phoenix.rs +++ b/execution-core/src/transfer/transaction/phoenix.rs @@ -97,6 +97,8 @@ impl Transaction { hash: deploy.bytecode.hash, bytes: Vec::new(), }, + nonce: deploy.nonce, + metadata: deploy.metadata.clone(), })), }, self.proof(), diff --git a/execution-core/tests/serialization.rs b/execution-core/tests/serialization.rs index a178f3050d..66513ae4c3 100644 --- a/execution-core/tests/serialization.rs +++ b/execution-core/tests/serialization.rs @@ -165,10 +165,17 @@ 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 mut metadata = vec![0; 40]; + rng.fill_bytes(&mut metadata); + let deploy = ContractDeploy { bytecode, owner, constructor_args: Some(constructor_args), + nonce, + metadata, }; let transaction = @@ -240,10 +247,17 @@ 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 mut metadata = vec![0; 40]; + rng.fill_bytes(&mut metadata); + let deploy = ContractDeploy { bytecode, owner, constructor_args: Some(constructor_args), + nonce, + metadata, }; let transaction =