Skip to content

Instantly share code, notes, and snippets.

@cf
Created April 12, 2024 11:08
Show Gist options
  • Save cf/92193039511c7d9eef773ec6787345bd to your computer and use it in GitHub Desktop.
Save cf/92193039511c7d9eef773ec6787345bd to your computer and use it in GitHub Desktop.
/*
function ch(x: number, y: number, z: number) {
return z ^ (x & (y ^ z));
}
*/
b.OP_TUCK();
b.OP_NUMNOTEQUAL();//.tag("y ^ z");
b.OP_ROT();
b.OP_BOOLAND();//.tag("(x & (y ^ z))");
b.OP_NUMNOTEQUAL();//.tag("z ^ (x & (y ^ z))");
// perform sha256 gamma_0 operation on 32 bits
OP_7
OP_PICK
<19>
OP_PICK
OP_NUMNOTEQUAL
OP_4
OP_PICK
OP_NUMNOTEQUAL
OP_TOALTSTACK
OP_8
OP_PICK
<20>
OP_PICK
OP_NUMNOTEQUAL
OP_5
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_2
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_9
OP_PICK
<21>
OP_PICK
OP_NUMNOTEQUAL
OP_6
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_4
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_10
OP_PICK
<22>
OP_PICK
OP_NUMNOTEQUAL
OP_7
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_8
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_11
OP_PICK
<23>
OP_PICK
OP_NUMNOTEQUAL
OP_8
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_16
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_12
OP_PICK
<24>
OP_PICK
OP_NUMNOTEQUAL
OP_9
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_13
OP_PICK
<25>
OP_PICK
OP_NUMNOTEQUAL
OP_10
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<64>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_14
OP_PICK
<26>
OP_PICK
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<128>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_15
OP_PICK
<27>
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<256>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_16
OP_PICK
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_13
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<512>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<17>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_14
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1024>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<18>
OP_PICK
<30>
OP_PICK
OP_NUMNOTEQUAL
OP_15
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2048>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_PICK
<31>
OP_PICK
OP_NUMNOTEQUAL
OP_16
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4096>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_PICK
<32>
OP_PICK
OP_NUMNOTEQUAL
<17>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8192>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_PICK
OP_OVER
OP_NUMNOTEQUAL
<18>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16384>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_2
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32768>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_3
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<65536>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_4
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<131072>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_5
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<262144>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_6
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<524288>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_7
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1048576>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
OP_8
OP_ROLL
OP_NUMNOTEQUAL
<18>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2097152>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_PICK
OP_8
OP_ROLL
OP_NUMNOTEQUAL
<17>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4194304>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_PICK
OP_8
OP_ROLL
OP_NUMNOTEQUAL
OP_16
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8388608>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_PICK
OP_8
OP_ROLL
OP_NUMNOTEQUAL
OP_15
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16777216>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_7
OP_ROLL
OP_NUMNOTEQUAL
OP_13
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<33554432>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_6
OP_ROLL
OP_NUMNOTEQUAL
OP_11
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<67108864>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_5
OP_ROLL
OP_NUMNOTEQUAL
OP_9
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<134217728>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_4
OP_ROLL
OP_NUMNOTEQUAL
OP_7
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<268435456>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<536870912>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_ROT
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1073741824>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_SWAP
OP_NUMNOTEQUAL
OP_FROMALTSTACK
// perform sha256 gamma_1 operation on 32 bits
<17>
OP_PICK
<20>
OP_PICK
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_TOALTSTACK
<18>
OP_PICK
<21>
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_2
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_PICK
<22>
OP_PICK
OP_NUMNOTEQUAL
OP_13
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_4
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_PICK
<23>
OP_PICK
OP_NUMNOTEQUAL
OP_14
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_8
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_PICK
<24>
OP_PICK
OP_NUMNOTEQUAL
OP_15
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_16
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
<25>
OP_PICK
OP_NUMNOTEQUAL
OP_16
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<23>
OP_PICK
<26>
OP_PICK
OP_NUMNOTEQUAL
<17>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<64>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<24>
OP_PICK
<27>
OP_PICK
OP_NUMNOTEQUAL
<18>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<128>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<25>
OP_PICK
<28>
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<256>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<512>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1024>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2048>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4096>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
OP_OVER
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8192>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<26>
OP_PICK
OP_2
OP_PICK
OP_NUMNOTEQUAL
<20>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16384>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
<19>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32768>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
<18>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<65536>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
<17>
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<131072>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_16
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<262144>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_15
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<524288>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_14
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1048576>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_13
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2097152>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4194304>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8388608>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16777216>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<33554432>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<67108864>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<134217728>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<268435456>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<536870912>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_ROT
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1073741824>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_SWAP
OP_NUMNOTEQUAL
OP_FROMALTSTACK
/*
function maj(x: number, y: number, z: number) {
return (x & y) | (z & (x | y));
}
*/
b.OP_TOALTSTACK();
b.OP_2DUP();
b.OP_BOOLOR();//.tag("(x | y)");
b.OP_FROMALTSTACK();
b.OP_BOOLAND();//.tag("(z & (x | y))");
b.OP_TOALTSTACK();
b.OP_BOOLAND();//.tag("(x & y)");
b.OP_FROMALTSTACK();
b.OP_BOOLOR();//.tag("(x & y) | (z & (x | y))")
// start prep data
var numInputs = args[0];
var swapEndianResult = !!args[1];
var cfg = sch.getLimbsConfig([1,31]);
var K = [
0x428a2f98,
0x71374491,
0xb5c0fbcf,
0xe9b5dba5,
0x3956c25b,
0x59f111f1,
0x923f82a4,
0xab1c5ed5,
0xd807aa98,
0x12835b01,
0x243185be,
0x550c7dc3,
0x72be5d74,
0x80deb1fe,
0x9bdc06a7,
0xc19bf174,
0xe49b69c1,
0xefbe4786,
0x0fc19dc6,
0x240ca1cc,
0x2de92c6f,
0x4a7484aa,
0x5cb0a9dc,
0x76f988da,
0x983e5152,
0xa831c66d,
0xb00327c8,
0xbf597fc7,
0xc6e00bf3,
0xd5a79147,
0x06ca6351,
0x14292967,
0x27b70a85,
0x2e1b2138,
0x4d2c6dfc,
0x53380d13,
0x650a7354,
0x766a0abb,
0x81c2c92e,
0x92722c85,
0xa2bfe8a1,
0xa81a664b,
0xc24b8b70,
0xc76c51a3,
0xd192e819,
0xd6990624,
0xf40e3585,
0x106aa070,
0x19a4c116,
0x1e376c08,
0x2748774c,
0x34b0bcb5,
0x391c0cb3,
0x4ed8aa4a,
0x5b9cca4f,
0x682e6ff3,
0x748f82ee,
0x78a5636f,
0x84c87814,
0x8cc70208,
0x90befffa,
0xa4506ceb,
0xbef9a3f7,
0xc67178f2
];
function u32String(n){
return `0x${(n + 0x100000000).toString(16).substr(-8)}`;
}
function constantU32(x){
return b.constants(cfg.splitParts(x));
}
function setWorkingVarReplace(varName, newValue){
}
function getSha256StateVarName(name,high=0){
return `s256_internal_state_${name.toUpperCase()}_${high?"high":"low"}`;
}
function getSha256WorkingVarName(name,high=0){
return `s256_working_state_${name.toUpperCase()}_${high?"high":"low"}`;
}
function getSha256WorkingOldVarName(name,high=0){
return `s256_working_old_state_${name.toUpperCase()}_${high?"high":"low"}`;
}
function renameWorkingVar(oldName,newName){
b.replaceTag(getSha256WorkingVarName(oldName,1),getSha256WorkingVarName(newName,1));
b.replaceTag(getSha256WorkingVarName(oldName,0),getSha256WorkingVarName(newName,0));
}
var startStateInternal = {
A: 0x6a09e667,
B: 0xbb67ae85,
C: 0x3c6ef372,
D: 0xa54ff53a,
E: 0x510e527f,
F: 0x9b05688c,
G: 0x1f83d9ab,
H: 0x5be0cd19
};
function setupSha256StateVars(){
Object.keys(startStateInternal).forEach(k=>{
const limbs = cfg.splitParts(startStateInternal[k]);
b.constants(limbs).tag([getSha256WorkingVarName(k,0),getSha256WorkingVarName(k,1)]);
})
/*
private A = 0x6a09e667 | 0;
private B = 0xbb67ae85 | 0;
private C = 0x3c6ef372 | 0;
private D = 0xa54ff53a | 0;
private E = 0x510e527f | 0;
private F = 0x9b05688c | 0;
private G = 0x1f83d9ab | 0;
private H = 0x5be0cd19 | 0;*/
}
function setupInputState(){
const wBase = [
0x80000000,
];
for(let i=numInputs+1;i<15;i++){
wBase.push(0);
}
wBase.push(numInputs*32);
/*
//52 bytes = 13 uints
[
0xa4d314c6, 0x10e98abf, 0x5e1f9025, 0x219f938c,
0xf712e542, 0xa7c23385, 0x4936e423, 0xbc8a4001,
0x5dc0aeb0, 0xa56ca15c, 0x67091db9, 0x38c745c4,
0x3d803464, 0x80000000, 0x00000000, 0x000001a0
]
[
0xbc78fb7b, 0xfa4e576e, 0xa1c6cb8c, 0xc91cda35,
0xac546117, 0x80000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x000000a0
]
*/
const wBaseLimbs = wBase.map(x=>cfg.splitParts(x));
b.constants(wBaseLimbs.reduce((a,b)=>a.concat(b),[]));
return ()=>{
}
}
var checkResult = setupInputState();
// end prep data
// start op
var W_HI_PREFIX = `W_HI_`;
var W_LOW_PREFIX = `W_LOW31_`;
var startTags = sch.seq(16).reverse()
.map((i)=>[`${W_LOW_PREFIX}${i}`,`${W_HI_PREFIX}${i}`])
.reduce((a,b)=>a.concat(b),[]);
b.tag(startTags)
// start util funcs
function pickW(index){
b.pickTag(W_HI_PREFIX+index);
b.pickTag(W_LOW_PREFIX+index);
}
function rollW(index){
b.rollTag(W_HI_PREFIX+index);
b.rollTag(W_LOW_PREFIX+index);
}
function rollWorking(name){
b.rollTag(getSha256WorkingVarName(name,1));
b.rollTag(getSha256WorkingVarName(name,0));
}
function dropWorking(name){
b.rollTag(getSha256WorkingVarName(name,1));
b.rollTag(getSha256WorkingVarName(name,0));
b.OP_2DROP();
}
function pickWorking(name){
b.pickTag(getSha256WorkingVarName(name,1));
b.pickTag(getSha256WorkingVarName(name,0));
}
// end util funcs
setupSha256StateVars();
for(let i=16;i<64;i++){
//W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0;
pickW(i-2);
b.OP_SHA256_GAMMA_1();
pickW(i-15);
b.OP_SHA256_GAMMA_0();
b.OP_ADD_U32();
pickW(i-7);
pickW(i-16);
b.OP_ADD_U32();
b.OP_ADD_U32();
b.tag([`${W_LOW_PREFIX}${i}`,`${W_HI_PREFIX}${i}`]);
}
for(let i=0;i<64;i++){
/*
const T1 = (H + sigma1(E) + ch(E, F, G) + K[i] + W[i]) | 0;
const T2 = (sigma0(A) + maj(A, B, C)) | 0;
H = G;
G = F;
F = E;
E = (D + T1) | 0;
D = C;
C = B;
B = A;
A = (T1 + T2) | 0;
*/
rollWorking("H");
pickWorking("E");
b.OP_2DUP();
b.OP_SHA256_SIGMA_1();
b.OP_2ROT();
b.OP_ADD_U32();
b.OP_2SWAP();
pickWorking("F");
pickWorking("G");
b.OP_SHA256_CH();
b.OP_ADD_U32();
rollW(i);
b.OP_ADD_U32();
constantU32(K[i]);
b.OP_ADD_U32();
b.tag(["T1_lo","T1_hi"]);
b.OP_2DUP();
pickWorking("A");
b.OP_2DUP();
b.OP_SHA256_SIGMA_0();
b.OP_2SWAP();
pickWorking("B");
pickWorking("C");
b.OP_SHA256_MAJ();
b.OP_ADD_U32();
b.tag(["T2_lo","T2_hi"]);
b.OP_ADD_U32();
b.tag(["T2_plus_T1_lo","T2_plus_T1_hi"]);
b.OP_2SWAP();
rollWorking("D");
b.OP_ADD_U32();
b.tag(["D_plus_T1_lo","D_plus_T1_hi"])
renameWorkingVar("G","H");
renameWorkingVar("F","G");
renameWorkingVar("E","F");
b.tag([getSha256WorkingVarName("E",0),getSha256WorkingVarName("E",1)])
renameWorkingVar("C","D");
renameWorkingVar("B","C");
renameWorkingVar("A","B");
b.OP_2SWAP();
b.tag([getSha256WorkingVarName("A",0),getSha256WorkingVarName("A",1)])
}
Object.keys(startStateInternal).forEach(k=>{
rollWorking(k);
constantU32(startStateInternal[k]);
b.OP_ADD_U32();
// OPTIONAL: Swap Endianness
if(swapEndianResult){
b.OP_SWAP_ENDIANNESS_U32();
}
})
// perform sha256 sigma 0 on 32 bits (should already be pushed to the stack)
OP_2
OP_PICK
OP_14
OP_PICK
OP_NUMNOTEQUAL
<23>
OP_PICK
OP_NUMNOTEQUAL
OP_TOALTSTACK
OP_3
OP_PICK
OP_15
OP_PICK
OP_NUMNOTEQUAL
<24>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_2
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_4
OP_PICK
OP_16
OP_PICK
OP_NUMNOTEQUAL
<25>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_4
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_5
OP_PICK
<17>
OP_PICK
OP_NUMNOTEQUAL
<26>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_8
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_6
OP_PICK
<18>
OP_PICK
OP_NUMNOTEQUAL
<27>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_16
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_7
OP_PICK
<19>
OP_PICK
OP_NUMNOTEQUAL
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_8
OP_PICK
<20>
OP_PICK
OP_NUMNOTEQUAL
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<64>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_9
OP_PICK
<21>
OP_PICK
OP_NUMNOTEQUAL
<30>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<128>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_10
OP_PICK
<22>
OP_PICK
OP_NUMNOTEQUAL
<31>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<256>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_11
OP_PICK
<23>
OP_PICK
OP_NUMNOTEQUAL
<32>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<512>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_12
OP_PICK
<24>
OP_PICK
OP_NUMNOTEQUAL
OP_OVER
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1024>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_13
OP_PICK
<25>
OP_PICK
OP_NUMNOTEQUAL
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2048>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_14
OP_PICK
<26>
OP_PICK
OP_NUMNOTEQUAL
OP_3
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4096>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_15
OP_PICK
<27>
OP_PICK
OP_NUMNOTEQUAL
OP_4
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8192>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_16
OP_PICK
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_5
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16384>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<17>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_6
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32768>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<18>
OP_PICK
<30>
OP_PICK
OP_NUMNOTEQUAL
OP_7
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<65536>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_PICK
<31>
OP_PICK
OP_NUMNOTEQUAL
OP_8
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<131072>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_PICK
<32>
OP_PICK
OP_NUMNOTEQUAL
OP_9
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<262144>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_PICK
OP_OVER
OP_NUMNOTEQUAL
OP_10
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<524288>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_ROLL
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1048576>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2097152>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4194304>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_11
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8388608>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<18>
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_10
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16777216>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_16
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_9
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<33554432>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_14
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_8
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<67108864>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_12
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_7
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<134217728>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_10
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_6
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<268435456>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_8
OP_ROLL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_5
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<536870912>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_ROT
OP_NUMNOTEQUAL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1073741824>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_SWAP
OP_NUMNOTEQUAL
OP_SWAP
OP_NUMNOTEQUAL
OP_FROMALTSTACK
// perform sha256 sigma 1 on 32 bits (should already be pushed to the stack)
OP_6
OP_PICK
OP_12
OP_PICK
OP_NUMNOTEQUAL
<26>
OP_PICK
OP_NUMNOTEQUAL
OP_TOALTSTACK
OP_7
OP_PICK
OP_13
OP_PICK
OP_NUMNOTEQUAL
<27>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_2
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_8
OP_PICK
OP_14
OP_PICK
OP_NUMNOTEQUAL
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_4
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_9
OP_PICK
OP_15
OP_PICK
OP_NUMNOTEQUAL
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_8
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_10
OP_PICK
OP_16
OP_PICK
OP_NUMNOTEQUAL
<30>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
OP_16
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_11
OP_PICK
<17>
OP_PICK
OP_NUMNOTEQUAL
<31>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_12
OP_PICK
<18>
OP_PICK
OP_NUMNOTEQUAL
<32>
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<64>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_13
OP_PICK
<19>
OP_PICK
OP_NUMNOTEQUAL
OP_OVER
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<128>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_14
OP_PICK
<20>
OP_PICK
OP_NUMNOTEQUAL
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<256>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_15
OP_PICK
<21>
OP_PICK
OP_NUMNOTEQUAL
OP_3
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<512>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_16
OP_PICK
<22>
OP_PICK
OP_NUMNOTEQUAL
OP_4
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1024>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<17>
OP_PICK
<23>
OP_PICK
OP_NUMNOTEQUAL
OP_5
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2048>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<18>
OP_PICK
<24>
OP_PICK
OP_NUMNOTEQUAL
OP_6
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4096>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_PICK
<25>
OP_PICK
OP_NUMNOTEQUAL
OP_7
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8192>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_PICK
<26>
OP_PICK
OP_NUMNOTEQUAL
OP_8
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16384>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_PICK
<27>
OP_PICK
OP_NUMNOTEQUAL
OP_9
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<32768>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_PICK
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_10
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<65536>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<23>
OP_PICK
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_11
OP_PICK
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<131072>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<24>
OP_PICK
<30>
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<262144>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<24>
OP_ROLL
<29>
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<524288>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<23>
OP_ROLL
<28>
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1048576>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<22>
OP_ROLL
OP_OVER
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<2097152>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<21>
OP_ROLL
OP_2
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<4194304>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<20>
OP_ROLL
OP_3
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<8388608>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<19>
OP_ROLL
OP_4
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<16777216>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
<18>
OP_ROLL
OP_5
OP_PICK
OP_NUMNOTEQUAL
OP_12
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<33554432>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_5
OP_PICK
OP_NUMNOTEQUAL
OP_11
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<67108864>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_5
OP_ROLL
OP_NUMNOTEQUAL
OP_9
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<134217728>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_4
OP_ROLL
OP_NUMNOTEQUAL
OP_7
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<268435456>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_5
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<536870912>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_ROT
OP_NUMNOTEQUAL
OP_3
OP_ROLL
OP_NUMNOTEQUAL
OP_IF
OP_FROMALTSTACK
<1073741824>
OP_ADD
OP_TOALTSTACK
OP_ENDIF
OP_SWAP
OP_NUMNOTEQUAL
OP_SWAP
OP_NUMNOTEQUAL
OP_FROMALTSTACK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment