Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate compilation of 'cashscript snippets' to CashASM #256

Open
mr-zwets opened this issue Jan 10, 2025 · 0 comments
Open

Investigate compilation of 'cashscript snippets' to CashASM #256

mr-zwets opened this issue Jan 10, 2025 · 0 comments

Comments

@mr-zwets
Copy link
Member

@jimtendo started a convestion on telegram (https://t.me/bch_compilers/7955) to ask

Might it be feasible in future to have some kind of compileScript function that allows CashScript to compile a short segment of CashScript into CashASM?
Something like:

// First arg is the script
// Second arg is the named values and their type
compileScript('a + b', {
 a: 'int',
 b: 'int',
})
// outputs:
// <a> <b> OP_ADD

Rosco replied (https://t.me/bch_compilers/8000) that we could try to support the following:

compileScript(`function x(int a, int b) { return a + b }`);

// or

const requireLockscriptP2PKH = compileScript(`
function checkLockingBytecode(bytes lockingBytecode) {
  require(lockingBytecode.length == 25);
  require(lockingBytecode.split(3)[0] == 0x76a914);
  require(lockingBytecode.split(23)[1] == 0x88ac);
}`);

That way we skip the contract overhead, but keep the function definition that has parameter data

Creating self-contained "functions" is something that is on the roadmap (although specifics are yet to be defined), but when we implement that, we could try to ensure that they could be compiled by themselves so they could be used for use cases like yours

adding a "target" for CashASM (besides "regular" hex bytecode / asm) should be doable as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant