Skip to content

Commit

Permalink
Nonce bug fix (stellar#685)
Browse files Browse the repository at this point in the history
* Nonce bug fix

* Update XDR rev
  • Loading branch information
dmkozh authored Feb 14, 2023
1 parent 90f361b commit bcec7e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ soroban-native-sdk-macros = { version = "0.0.13", path = "soroban-native-sdk-mac
[workspace.dependencies.stellar-xdr]
version = "0.0.13"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "bd9deaf09fe86bd287d21527651b240e90c320b5"
rev = "2ae9311ed1466270d8558f4c88c953644a48628e"
default-features = false

[workspace.dependencies.wasmi]
Expand Down
4 changes: 4 additions & 0 deletions soroban-env-host/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,10 @@ impl AuthorizationTracker {
host.with_ledger_info(|li| li.network_id.metered_clone(host.budget_ref()))?,
),
invocation: self.invocation_to_xdr(host.budget_ref())?,
nonce: self
.nonce
.clone()
.ok_or(host.err_general("unexpected missing nonce"))?,
});

host.metered_hash_xdr(&payload_preimage)
Expand Down
24 changes: 15 additions & 9 deletions soroban-env-host/src/native_contract/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,21 @@ pub(crate) fn authorize_single_invocation_with_nonce(
sub_invocations: Default::default(),
};

let signature_payload_preimage = HashIdPreimage::ContractAuth(HashIdPreimageContractAuth {
network_id: host
.with_ledger_info(|li: &LedgerInfo| Ok(li.network_id.clone()))
.unwrap()
.try_into()
.unwrap(),
invocation: root_invocation.clone(),
});
let signature_payload = host.metered_hash_xdr(&signature_payload_preimage).unwrap();
let signature_payload = if let Some(addr_with_nonce) = &address_with_nonce {
let signature_payload_preimage = HashIdPreimage::ContractAuth(HashIdPreimageContractAuth {
network_id: host
.with_ledger_info(|li: &LedgerInfo| Ok(li.network_id.clone()))
.unwrap()
.try_into()
.unwrap(),
invocation: root_invocation.clone(),
nonce: addr_with_nonce.nonce,
});
host.metered_hash_xdr(&signature_payload_preimage).unwrap()
} else {
[0; 32]
};

let signature_args = signer.sign(host, &signature_payload);
let auth_entry = ContractAuth {
address_with_nonce,
Expand Down

0 comments on commit bcec7e3

Please sign in to comment.