Skip to content

Commit

Permalink
Aligned documentation for redemption key with the code
Browse files Browse the repository at this point in the history
The code has changed and the redemption key is now built in
Redemption.getRedemptionKey function as
key = keccak256(scriptHash | walletPubKeyHash). This change was not
reflected in the documentation. Fixing it now.
  • Loading branch information
pdyraga committed May 26, 2022
1 parent 01b490c commit 73dee0b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions solidity/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ contract Bridge is
/// @notice Notifies that there is a pending redemption request associated
/// with the given wallet, that has timed out. The redemption
/// request is identified by the key built as
/// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
/// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
/// The results of calling this function:
/// - The pending redemptions value for the wallet will be decreased
/// by the requested amount (minus treasury fee),
Expand Down Expand Up @@ -1424,10 +1424,10 @@ contract Bridge is

/// @notice Collection of all pending redemption requests indexed by
/// redemption key built as
/// keccak256(walletPubKeyHash | redeemerOutputScript). The
/// walletPubKeyHash is the 20-byte wallet's public key hash
/// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
/// The walletPubKeyHash is the 20-byte wallet's public key hash
/// (computed using Bitcoin HASH160 over the compressed ECDSA
/// public key) and redeemerOutputScript is a Bitcoin script
/// public key) and `redeemerOutputScript` is a Bitcoin script
/// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
/// redeemed BTC as requested by the redeemer. Requests are added
/// to this mapping by the `requestRedemption` method (duplicates
Expand All @@ -1446,10 +1446,10 @@ contract Bridge is

/// @notice Collection of all timed out redemptions requests indexed by
/// redemption key built as
/// keccak256(walletPubKeyHash | redeemerOutputScript). The
/// walletPubKeyHash is the 20-byte wallet's public key hash
/// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
/// The walletPubKeyHash is the 20-byte wallet's public key hash
/// (computed using Bitcoin HASH160 over the compressed ECDSA
/// public key) and redeemerOutputScript is the Bitcoin script
/// public key) and `redeemerOutputScript` is the Bitcoin script
/// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
/// out request. Timed out requests are stored in this mapping to
/// avoid slashing the wallets multiple times for the same timeout.
Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/bridge/BridgeState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ library BridgeState {
mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
// Collection of all pending redemption requests indexed by
// redemption key built as
// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
// The `walletPubKeyHash` is the 20-byte wallet's public key hash
// (computed using Bitcoin HASH160 over the compressed ECDSA
// public key) and `redeemerOutputScript` is a Bitcoin script
Expand All @@ -245,8 +245,8 @@ library BridgeState {
mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
// Collection of all timed out redemptions requests indexed by
// redemption key built as
// `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
// `walletPubKeyHash` is the 20-byte wallet's public key hash
// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
// The `walletPubKeyHash` is the 20-byte wallet's public key hash
// (computed using Bitcoin HASH160 over the compressed ECDSA
// public key) and `redeemerOutputScript` is the Bitcoin script
// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
Expand Down
6 changes: 3 additions & 3 deletions solidity/contracts/bridge/Redemption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ library Redemption {
/// @notice Notifies that there is a pending redemption request associated
/// with the given wallet, that has timed out. The redemption
/// request is identified by the key built as
/// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
/// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
/// The results of calling this function:
/// - the pending redemptions value for the wallet will be decreased
/// by the requested amount (minus treasury fee),
Expand Down Expand Up @@ -1019,7 +1019,7 @@ library Redemption {
/// @notice Calculate redemption key without allocations.
/// @param walletPubKeyHash the pubkey hash of the wallet.
/// @param script the output script of the redemption.
/// @return The key = keccak256(keccak256(script), walletPubKeyHash).
/// @return The key = keccak256(keccak256(script) | walletPubKeyHash).
function getRedemptionKey(bytes20 walletPubKeyHash, bytes memory script)
internal
pure
Expand All @@ -1039,7 +1039,7 @@ library Redemption {
/// @notice Finish calculating redemption key without allocations.
/// @param walletPubKeyHash the pubkey hash of the wallet.
/// @param scriptHash the output script hash of the redemption.
/// @return The key = keccak256(scriptHash, walletPubKeyHash).
/// @return The key = keccak256(scriptHash | walletPubKeyHash).
function _getRedemptionKey(bytes20 walletPubKeyHash, bytes32 scriptHash)
internal
pure
Expand Down
2 changes: 1 addition & 1 deletion typescript/test/ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Ethereum", () => {
describe("pendingRedemptions", () => {
beforeEach(async () => {
// Set the mock to return a specific redemption data when called
// with the redemption key (built as keccak256(walletPubKeyHash | redeemerOutputScript))
// with the redemption key (built as keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash))
// that matches the wallet PKH and redeemer output script used during
// the test call.
await bridgeContract.mock.pendingRedemptions
Expand Down

0 comments on commit 73dee0b

Please sign in to comment.