Skip to content

Commit

Permalink
execution-core: added nonce to contract deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Jul 25, 2024
1 parent 15a769e commit e29955a
Show file tree
Hide file tree
Showing 5 changed files with 21 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` 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
7 changes: 7 additions & 0 deletions execution-core/src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ pub struct ContractDeploy {
pub owner: Vec<u8>,
/// Constructor arguments of the deployed contract.
pub constructor_args: Option<Vec<u8>>,
/// Nonce for contract id uniqueness and vanity
pub nonce: u64,
}

/// All the data the transfer-contract needs to perform a contract-call.
Expand Down Expand Up @@ -365,6 +367,8 @@ impl ContractDeploy {
None => bytes.push(0),
}

bytes.extend(self.nonce.to_bytes());

bytes
}

Expand All @@ -385,10 +389,13 @@ impl ContractDeploy {
_ => return Err(BytesError::InvalidData),
};

let nonce = u64::from_reader(&mut buf)?;

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

0 comments on commit e29955a

Please sign in to comment.