mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Security flaw. When we add transaction nodes to a synching tree,
we must make sure the hash of the data equals the tag!
This commit is contained in:
@@ -149,7 +149,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapN
|
|||||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item, TNType type, uint32 seq) :
|
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item, TNType type, uint32 seq) :
|
||||||
SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true)
|
SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true)
|
||||||
{
|
{
|
||||||
assert(item->peekData().size()>=32);
|
assert(item->peekData().size()>=12);
|
||||||
updateHash();
|
updateHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
|
|
||||||
int type=s.removeLastByte();
|
int type=s.removeLastByte();
|
||||||
int len=s.getLength();
|
int len=s.getLength();
|
||||||
if( (type<0) || (type>3) || (len<33) ) throw SHAMapException(InvalidNode);
|
if( (type<0) || (type>3) || (len<32) ) throw SHAMapException(InvalidNode);
|
||||||
|
|
||||||
if(type==0)
|
if(type==0)
|
||||||
{ // transaction
|
{ // transaction
|
||||||
@@ -213,13 +213,12 @@ void SHAMapTreeNode::addRaw(Serializer &s)
|
|||||||
if(mType==ACCOUNT_STATE)
|
if(mType==ACCOUNT_STATE)
|
||||||
{
|
{
|
||||||
mItem->addRaw(s);
|
mItem->addRaw(s);
|
||||||
assert(s.getLength()>20);
|
|
||||||
s.add160(mItem->getTag().to160());
|
s.add160(mItem->getTag().to160());
|
||||||
s.add1(1);
|
s.add1(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getBranchCount()<5)
|
if(getBranchCount()<12)
|
||||||
{ // compressed node
|
{ // compressed node
|
||||||
for(int i=0; i<16; i++)
|
for(int i=0; i<16; i++)
|
||||||
if(mHashes[i].isNonZero())
|
if(mHashes[i].isNonZero())
|
||||||
@@ -260,7 +259,9 @@ bool SHAMapTreeNode::updateHash()
|
|||||||
nh=s.getSHA512Half();
|
nh=s.getSHA512Half();
|
||||||
}
|
}
|
||||||
else if(mType==TRANSACTION)
|
else if(mType==TRANSACTION)
|
||||||
nh=mItem->getTag();
|
{
|
||||||
|
nh=Serializer::getSHA512Half(mItem->peekData());
|
||||||
|
}
|
||||||
else assert(false);
|
else assert(false);
|
||||||
|
|
||||||
if(nh==mHash) return false;
|
if(nh==mHash) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user