-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speculatively implement P2S, OP_EVAL, and OP_POW
- Loading branch information
Showing
93 changed files
with
1,322 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@bitauth/libauth': minor | ||
--- | ||
|
||
Speculatively implement P2S, OP_EVAL, and OP_POW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/lib/vm/instruction-sets/bch/2026/bch-2026-descriptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { OpcodeDescriptionsBch2023 } from '../2023/bch-2023-descriptions.js'; | ||
|
||
/** | ||
* Descriptions for the opcodes added to the `BCH_2026_05` instruction set | ||
* beyond those present in `BCH_2025_05`. | ||
*/ | ||
export enum OpcodeDescriptionsBch2026Additions { | ||
OP_EVAL = 'Pop the top item from the stack as bytecode. Preserve the active bytecode at the top of the control stack, then evaluate the bytecode as if it were the active bytecode (without modifying the stack, alternate stack, or other evaluation context). When the evaluation is complete, restore the original bytecode and continue evaluation after the OP_EVAL instruction. If the bytecode is malformed, error.', | ||
OP_BEGIN = 'Push the current instruction pointer index to the control stack as an integer (to be read by OP_UNTIL).', | ||
OP_UNTIL = 'Pop the top item from the control stack (if the control value is not an integer, error). Add the difference between the control value and the current instruction pointer index to the repeated bytes counter, if the sum of the repeated bytes counter and the active bytecode length is greater than the maximum bytecode length, error. Pop the top item from the stack, if the value is not truthy, move the instruction pointer to the control value (and re-evaluate the OP_BEGIN).', | ||
} | ||
|
||
/** | ||
* Descriptions for the `BCH_SPEC` instruction set. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const OpcodeDescriptionsBch2026 = { | ||
...OpcodeDescriptionsBch2023, | ||
...OpcodeDescriptionsBch2026Additions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { | ||
AuthenticationInstructionMalformed, | ||
AuthenticationProgramStateBch2026, | ||
} from '../../../../lib.js'; | ||
import { | ||
applyError, | ||
authenticationInstructionsAreMalformed, | ||
decodeAuthenticationInstructions, | ||
disassembleAuthenticationInstructionMalformed, | ||
executionIsActive, | ||
pushToControlStack, | ||
useOneStackItem, | ||
} from '../../common/common.js'; | ||
|
||
import { AuthenticationErrorBch2026 } from './bch-2026-errors.js'; | ||
import { OpcodesBch2026 } from './bch-2026-opcodes.js'; | ||
|
||
export const opEval = <State extends AuthenticationProgramStateBch2026>( | ||
state: State, | ||
) => { | ||
if (executionIsActive(state)) { | ||
return useOneStackItem(state, (nextState, [item]) => { | ||
const newInstructions = decodeAuthenticationInstructions(item); | ||
|
||
if (authenticationInstructionsAreMalformed(newInstructions)) { | ||
return applyError( | ||
nextState, | ||
AuthenticationErrorBch2026.malformedEval, | ||
`Malformed instruction: ${disassembleAuthenticationInstructionMalformed( | ||
OpcodesBch2026, | ||
newInstructions[ | ||
newInstructions.length - 1 | ||
] as AuthenticationInstructionMalformed, | ||
)}.`, | ||
); | ||
} | ||
|
||
const manuallyAdvance = 1; | ||
const finalState = pushToControlStack(nextState, { | ||
instructions: nextState.instructions, | ||
ip: nextState.ip + manuallyAdvance, | ||
}); | ||
finalState.ip = 0 - manuallyAdvance; // eslint-disable-line functional/no-expression-statements, functional/immutable-data | ||
finalState.instructions = newInstructions; // eslint-disable-line functional/no-expression-statements, functional/immutable-data | ||
return finalState; | ||
}); | ||
} | ||
return state; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.