Skip to content

Commit

Permalink
execution-core: added nonce and metadata to contract deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Jul 24, 2024
1 parent aede7a0 commit 39fd77a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions execution-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions execution-core/src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ pub struct ContractDeploy {
pub owner: Vec<u8>,
/// Constructor arguments of the deployed contract.
pub constructor_args: Option<Vec<u8>>,
/// Nonce for contract id uniqueness
pub nonce: u64,
/// Metadata
pub metadata: Vec<u8>,
}

/// All the data the transfer-contract needs to perform a contract-call.
Expand Down Expand Up @@ -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
}

Expand All @@ -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,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions execution-core/src/transfer/transaction/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ impl Transaction {
hash: deploy.bytecode.hash,
bytes: Vec::new(),
},
nonce: deploy.nonce,
metadata: deploy.metadata.clone(),
})),
},
*self.signature(),
Expand Down
2 changes: 2 additions & 0 deletions execution-core/src/transfer/transaction/phoenix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ impl Transaction {
hash: deploy.bytecode.hash,
bytes: Vec::new(),
},
nonce: deploy.nonce,
metadata: deploy.metadata.clone(),
})),
},
self.proof(),
Expand Down
14 changes: 14 additions & 0 deletions execution-core/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 39fd77a

Please sign in to comment.