Author

Topic: FindAndDelete method in script.h (Read 1209 times)

legendary
Activity: 1232
Merit: 1076
June 26, 2012, 07:10:33 AM
#3
I'm not sure what you're asking. Yes it deletes code separators.

Check my code here (I think it is easier to understand):

https://gitorious.org/libbitcoin/libbitcoin/blobs/master/src/script.cpp

Search for bool script::op_checksigverify(...)

You see the look where I create the script_code object? It loops from the last codehash position until the end of all the operations, skipping the signature or any codeseparators. Everything else is pushed to the new script object which is then used for the check_signature function.

I would suggest not copying Bitcoin's representation of scripts and instead store the parse tree for scripts. It makes it much easier for the user from an API perspective. Just remember that coinbases are unparsable so you'll need either a special script type or opcode for a raw_script (which is uninterpretable).
legendary
Activity: 1190
Merit: 1004
June 23, 2012, 03:02:37 PM
#2
I have this for the signatures. Is it correct? It searches for push operations and then goes to the beginning of the data to check for a signature. If a signature is found then it is removed:

Code:
void CBSubScriptRemoveSignature(u_int8_t * subScript,u_int32_t * subScriptLen,CBScriptStackItem signature){
if (signature.data == NULL) return; // Signature zero
u_int8_t * ptr = subScript;
u_int8_t * end = subScript + *subScriptLen;
for (;ptr < end;) {
if (*ptr && *ptr < 78) { // Push
// Move to data for push and record movement to next operation. No checking of push data bounds since it should have already been done.
u_int32_t move;
if (*ptr < 75) {
move = *ptr;
ptr++;
}else if (*ptr == CB_SCRIPT_OP_PUSHDATA1){
move = ptr[1];
ptr += 2;
}else if (*ptr == CB_SCRIPT_OP_PUSHDATA2){
move = ptr[1];
move += ptr[2] << 8;
ptr += 3;
}else{ // PUSHDATA4
move = ptr[1];
move += ptr[2] << 8;
move += ptr[3] << 16;
move += ptr[4] << 24;
ptr += 5;
}
// Check within bounds
if (ptr + signature.length >= end)
break;
// Check signature
if (memcmp(ptr, signature.data, signature.length)) {
// Remove signature
memmove(ptr, ptr + signature.length, end - (ptr + signature.length));
end -= signature.length;
*subScriptLen -= signature.length; // Length adjustment.
}
// Move to next operation
ptr += move;
}else{
ptr++;
}
}
}
legendary
Activity: 1190
Merit: 1004
June 23, 2012, 12:10:13 PM
#1
Hello I'm looking here: https://github.com/bitcoin/bitcoin/blob/master/src/script.h#L482

This is used to remove OP_CODE_SEPARATOR codes and signatures. So from what I can tell the OP_CODE_SERPARATOR codes are just removed if they match the next operator in the loop. For signatures, how do they match? Do the signatures have to match the entire push operation? It seems like it may also match signatures if they come after each other in a push operation like:

OP_PUSHDATA1

So it would match if the signature repeats like that? Or would it only match the first one? Also it seems to me that data in front of the signature would cause the signature not to be removed. Any data after the signature is ignored. Is this right?

Signature not removed?:

OP_PUSHDATA1

Signature removed but not arbitrary data?:

OP_PUSHDATA1

Obviously this is important to make OP_CHECKSIG etc. to work.
Jump to: