mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
ringct: use dummy bulletproofs when in fake mode, for speed
This commit is contained in:
parent
1e74586ee9
commit
d6937e373b
@ -85,7 +85,7 @@ namespace hw {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
device() {}
|
device(): mode(NONE) {}
|
||||||
device(const device &hwdev) {}
|
device(const device &hwdev) {}
|
||||||
virtual ~device() {}
|
virtual ~device() {}
|
||||||
|
|
||||||
@ -115,7 +115,8 @@ namespace hw {
|
|||||||
virtual bool connect(void) = 0;
|
virtual bool connect(void) = 0;
|
||||||
virtual bool disconnect(void) = 0;
|
virtual bool disconnect(void) = 0;
|
||||||
|
|
||||||
virtual bool set_mode(device_mode mode) = 0;
|
virtual bool set_mode(device_mode mode) { this->mode = mode; return true; }
|
||||||
|
virtual device_mode get_mode() const { return mode; }
|
||||||
|
|
||||||
virtual device_type get_type() const = 0;
|
virtual device_type get_type() const = 0;
|
||||||
|
|
||||||
@ -202,6 +203,9 @@ namespace hw {
|
|||||||
virtual bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) = 0;
|
virtual bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) = 0;
|
||||||
|
|
||||||
virtual bool close_tx(void) = 0;
|
virtual bool close_tx(void) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
device_mode mode;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
struct reset_mode {
|
struct reset_mode {
|
||||||
|
@ -83,7 +83,7 @@ namespace hw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool device_default::set_mode(device_mode mode) {
|
bool device_default::set_mode(device_mode mode) {
|
||||||
return true;
|
return device::set_mode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
@ -396,7 +396,7 @@ namespace hw {
|
|||||||
CHECK_AND_ASSERT_THROW_MES(false, " device_ledger::set_mode(unsigned int mode): invalid mode: "<<mode);
|
CHECK_AND_ASSERT_THROW_MES(false, " device_ledger::set_mode(unsigned int mode): invalid mode: "<<mode);
|
||||||
}
|
}
|
||||||
MDEBUG("Switch to mode: " <<mode);
|
MDEBUG("Switch to mode: " <<mode);
|
||||||
return true;
|
return device::set_mode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,19 @@ using namespace std;
|
|||||||
|
|
||||||
#define CHECK_AND_ASSERT_MES_L1(expr, ret, message) {if(!(expr)) {MCERROR("verify", message); return ret;}}
|
#define CHECK_AND_ASSERT_MES_L1(expr, ret, message) {if(!(expr)) {MCERROR("verify", message); return ret;}}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
rct::Bulletproof make_dummy_bulletproof(size_t n_outs)
|
||||||
|
{
|
||||||
|
const rct::key I = rct::identity();
|
||||||
|
size_t nrl = 0;
|
||||||
|
while ((1u << nrl) < n_outs)
|
||||||
|
++nrl;
|
||||||
|
nrl += 6;
|
||||||
|
return rct::Bulletproof{rct::keyV(n_outs, I), I, I, I, I, I, I, rct::keyV(nrl, I), rct::keyV(nrl, I), I, I, I};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace rct {
|
namespace rct {
|
||||||
Bulletproof proveRangeBulletproof(key &C, key &mask, uint64_t amount)
|
Bulletproof proveRangeBulletproof(key &C, key &mask, uint64_t amount)
|
||||||
{
|
{
|
||||||
@ -762,10 +775,20 @@ namespace rct {
|
|||||||
if (range_proof_type == RangeProofPaddedBulletproof)
|
if (range_proof_type == RangeProofPaddedBulletproof)
|
||||||
{
|
{
|
||||||
rct::keyV C, masks;
|
rct::keyV C, masks;
|
||||||
rv.p.bulletproofs.push_back(proveRangeBulletproof(C, masks, outamounts));
|
if (hwdev.get_mode() == hw::device::TRANSACTION_CREATE_FAKE)
|
||||||
#ifdef DBG
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(verBulletproof(rv.p.bulletproofs.back()), "verBulletproof failed on newly created proof");
|
// use a fake bulletproof for speed
|
||||||
#endif
|
rv.p.bulletproofs.push_back(make_dummy_bulletproof(outamounts.size()));
|
||||||
|
C = rct::keyV(outamounts.size(), I);
|
||||||
|
masks = rct::keyV(outamounts.size(), I);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rv.p.bulletproofs.push_back(proveRangeBulletproof(C, masks, outamounts));
|
||||||
|
#ifdef DBG
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(verBulletproof(rv.p.bulletproofs.back()), "verBulletproof failed on newly created proof");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
for (i = 0; i < outamounts.size(); ++i)
|
for (i = 0; i < outamounts.size(); ++i)
|
||||||
{
|
{
|
||||||
rv.outPk[i].mask = rct::scalarmult8(C[i]);
|
rv.outPk[i].mask = rct::scalarmult8(C[i]);
|
||||||
@ -782,10 +805,20 @@ namespace rct {
|
|||||||
std::vector<uint64_t> batch_amounts(batch_size);
|
std::vector<uint64_t> batch_amounts(batch_size);
|
||||||
for (i = 0; i < batch_size; ++i)
|
for (i = 0; i < batch_size; ++i)
|
||||||
batch_amounts[i] = outamounts[i + amounts_proved];
|
batch_amounts[i] = outamounts[i + amounts_proved];
|
||||||
rv.p.bulletproofs.push_back(proveRangeBulletproof(C, masks, batch_amounts));
|
if (hwdev.get_mode() == hw::device::TRANSACTION_CREATE_FAKE)
|
||||||
#ifdef DBG
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(verBulletproof(rv.p.bulletproofs.back()), "verBulletproof failed on newly created proof");
|
// use a fake bulletproof for speed
|
||||||
#endif
|
rv.p.bulletproofs.push_back(make_dummy_bulletproof(batch_amounts.size()));
|
||||||
|
C = rct::keyV(batch_amounts.size(), I);
|
||||||
|
masks = rct::keyV(batch_amounts.size(), I);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rv.p.bulletproofs.push_back(proveRangeBulletproof(C, masks, batch_amounts));
|
||||||
|
#ifdef DBG
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(verBulletproof(rv.p.bulletproofs.back()), "verBulletproof failed on newly created proof");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
for (i = 0; i < batch_size; ++i)
|
for (i = 0; i < batch_size; ++i)
|
||||||
{
|
{
|
||||||
rv.outPk[i + amounts_proved].mask = rct::scalarmult8(C[i]);
|
rv.outPk[i + amounts_proved].mask = rct::scalarmult8(C[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user