Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pset: add optional asset blinding factor to input and output #1329

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion doc/pset.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ The currently defined elements per-input proprietary types are as follows:
|
| 0
| 2
|-
| Asset Blinding Factor
| <tt>PSBT_ELEMENTS_IN_ASSET_BLINDING_FACTOR = 0x16</tt>
| None
| No key data
| <tt><256 bit uint></tt>
| The 32 byte asset blinding factor for the input being spent.
|
| 0
| 2
|}

The currently defined elements per-output proprietary types are as follows:
Expand Down Expand Up @@ -408,7 +418,8 @@ The currently defined elements per-output proprietary types are as follows:
| An explicit value rangeproof that proves that the value commitment in <tt>PSBT_ELEMENTS_OUT_VALUE_COMMITMENT</tt> matches the explicit value in <tt>PSBT_OUT_VALUE</tt>. If provided, <tt>PSBT_ELEMENTS_OUT_VALUE_COMMITMENT</tt> must be provided too.
|
| 0
| 2|-
| 2
|-
| Blind Asset Proof
| <tt>PSBT_ELEMENTS_OUT_BLIND_ASSET_PROOF = 0x0a</tt>
| None
Expand All @@ -418,6 +429,16 @@ The currently defined elements per-output proprietary types are as follows:
|
| 0
| 2
|-
| Asset Blinding Factor
| <tt>PSBT_ELEMENTS_OUT_ASSET_BLINDING_FACTOR = 0x0b</tt>
| None
| No key data
| <tt><256 bit uint></tt>
| The 32 byte asset blinding factor of this output.
|
| 0
| 2
|}

The PSET Magic Bytes are <tt>0x70736574</tt>
Expand Down
40 changes: 40 additions & 0 deletions src/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static constexpr uint8_t PSBT_ELEMENTS_IN_VALUE_PROOF = 0x12;
static constexpr uint8_t PSBT_ELEMENTS_IN_EXPLICIT_ASSET = 0x13;
static constexpr uint8_t PSBT_ELEMENTS_IN_ASSET_PROOF = 0x14;
static constexpr uint8_t PSBT_ELEMENTS_IN_BLINDED_ISSUANCE = 0x15;
static constexpr uint8_t PSBT_ELEMENTS_IN_ASSET_BLINDING_FACTOR = 0x16;

// Output types
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00;
Expand All @@ -104,6 +105,7 @@ static constexpr uint8_t PSBT_ELEMENTS_OUT_ECDH_PUBKEY = 0x07;
static constexpr uint8_t PSBT_ELEMENTS_OUT_BLINDER_INDEX = 0x08;
static constexpr uint8_t PSBT_ELEMENTS_OUT_BLIND_VALUE_PROOF = 0x09;
static constexpr uint8_t PSBT_ELEMENTS_OUT_BLIND_ASSET_PROOF = 0x0a;
static constexpr uint8_t PSBT_ELEMENTS_OUT_ASSET_BLINDING_FACTOR = 0x0b;

// Proprietary type identifier string
static const std::vector<unsigned char> PSBT_ELEMENTS_ID = {'p', 's', 'e', 't'};
Expand Down Expand Up @@ -280,6 +282,7 @@ struct PSBTInput
std::vector<unsigned char> m_value_proof;
uint256 m_explicit_asset;
std::vector<unsigned char> m_asset_proof;
std::optional<uint256> m_asset_blinding_factor{std::nullopt};

bool IsNull() const;
void FillSignatureData(SignatureData& sigdata) const;
Expand Down Expand Up @@ -543,6 +546,12 @@ struct PSBTInput
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_BLINDED_ISSUANCE));
SerializeToVector(s, *m_blinded_issuance);
}

// Asset blinding factor
if (m_asset_blinding_factor.has_value()) {
SerializeToVector(s, CompactSizeWriter(PSBT_IN_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_IN_ASSET_BLINDING_FACTOR));
SerializeToVector(s, m_asset_blinding_factor.value());
}
}

// Write proprietary things
Expand Down Expand Up @@ -1096,6 +1105,18 @@ struct PSBTInput
m_blinded_issuance = b;
break;
}
case PSBT_ELEMENTS_IN_ASSET_BLINDING_FACTOR:
{
if (m_asset_blinding_factor.has_value()) {
throw std::ios_base::failure("Duplicate Key, input asset blinding factor is already provided");
} else if (subkey_len != 1) {
throw std::ios_base::failure("Input asset blinding factor is more than one byte type");
}
uint256 u;
UnserializeFromVector(s, u);
m_asset_blinding_factor = u;
break;
}
default:
{
known = false;
Expand Down Expand Up @@ -1185,6 +1206,7 @@ struct PSBTOutput
std::optional<uint32_t> m_blinder_index{std::nullopt};
std::vector<unsigned char> m_blind_value_proof;
std::vector<unsigned char> m_blind_asset_proof;
std::optional<uint256> m_asset_blinding_factor{std::nullopt};

bool IsNull() const;
void FillSignatureData(SignatureData& sigdata) const;
Expand Down Expand Up @@ -1282,6 +1304,12 @@ struct PSBTOutput
SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_BLIND_ASSET_PROOF));
s << m_blind_asset_proof;
}

// Asset blinding factor
if (m_asset_blinding_factor.has_value()) {
SerializeToVector(s, CompactSizeWriter(PSBT_OUT_PROPRIETARY), PSBT_ELEMENTS_ID, CompactSizeWriter(PSBT_ELEMENTS_OUT_ASSET_BLINDING_FACTOR));
SerializeToVector(s, m_asset_blinding_factor.value());
}
}

// Write proprietary things
Expand Down Expand Up @@ -1488,6 +1516,18 @@ struct PSBTOutput
s >> m_blind_asset_proof;
break;
}
case PSBT_ELEMENTS_OUT_ASSET_BLINDING_FACTOR:
{
if (m_asset_blinding_factor.has_value()) {
throw std::ios_base::failure("Duplicate Key, output asset blinding factor is already provided");
} else if (subkey_len != 1) {
throw std::ios_base::failure("Output asset blinding factor is more than one byte type");
}
uint256 u;
UnserializeFromVector(s, u);
m_asset_blinding_factor = u;
break;
}
default:
{
known = false;
Expand Down
11 changes: 11 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,7 @@ static RPCHelpMan decodepsbt()
{RPCResult::Type::STR_HEX, "explicit_asset", /*optional=*/true, "The explicit asset for this input"},
{RPCResult::Type::STR_HEX, "asset_proof", /*optional=*/true, "The explicit asset proof for this input"},
{RPCResult::Type::BOOL, "blinded_issuance", /*optional=*/true, "Whether the issuance should be blinded prior to signing"},
{RPCResult::Type::STR_HEX, "asset_blinder", /*optional=*/true, "The asset blinding factor for this input"},
{RPCResult::Type::OBJ_DYN, "ripemd160_preimages", /*optional=*/ true, "",
{
{RPCResult::Type::STR, "hash", "The hash and preimage that corresponds to it."},
Expand Down Expand Up @@ -1342,6 +1343,7 @@ static RPCHelpMan decodepsbt()
{RPCResult::Type::STR_HEX, "blinding_pubkey", "The blinding pubkey for the output"},
{RPCResult::Type::STR_HEX, "blind_value_proof", "Explicit value rangeproof that proves the value commitment matches the value"},
{RPCResult::Type::STR_HEX, "blind_asset_proof", "Assert surjection proof that proves the assert commitment matches the asset"},
{RPCResult::Type::STR_HEX, "asset_blinder", /*optional=*/true, "The asset blinding factor for the output"},
{RPCResult::Type::STR, "status", "information about how the output has been blinded, if available"},
{RPCResult::Type::OBJ_DYN, "unknown", /*optional=*/true, "The unknown global fields",
{
Expand Down Expand Up @@ -1687,6 +1689,10 @@ static RPCHelpMan decodepsbt()
in.pushKV("blinded_issuance", *input.m_blinded_issuance);
}

if (input.m_asset_blinding_factor.has_value()) {
in.pushKV("asset_blinder", input.m_asset_blinding_factor.value().GetHex());
}

switch (VerifyBlindProofs(input)) {
case BlindProofResult::OK:
// all good
Expand Down Expand Up @@ -1864,6 +1870,11 @@ static RPCHelpMan decodepsbt()
out.pushKV("blind_asset_proof", HexStr(output.m_blind_asset_proof));
}

// Asset blinding factor
if (output.m_asset_blinding_factor.has_value()) {
out.pushKV("asset_blinder", output.m_asset_blinding_factor.value().GetHex());
}

switch (VerifyBlindProofs(output)) {
case BlindProofResult::OK:
// all good
Expand Down
Loading