Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

node: Cli: Adding Script System for neo-cli #901

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Sep 28, 2023

This amazing idea is from 17v.

By enabling developers to write and run script in the neo-cli, they are empowerd to directly interact with the leder and smart contract directly with C# code.

What's the benefits?

  • Typed variables.
  • Code recommendation.
  • Combined commands.
  • Loop
  • Event monitor.
  • And more.

Newly added commands:

  • script new [file] create a new script file from the template script
  • script run [file] [watch] run the script.

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 10, 2023

@shargon how do you think about this one, interact with the neo node via script

@shargon
Copy link
Member

shargon commented Oct 10, 2023

@shargon how do you think about this one, interact with the neo node via script

Is not the same as invokeScript in rpc? Or what kind of script it is?

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 10, 2023

@shargon it is C# script, where you can write c# code to construct transactions and interact with the neo blockchain, then run the script in the cli, it is painful to use cli since there is no type system right? now this is the solution, you can use this to conveniently do complex operations however you like. Airdrop, event monitoring, all can be done in script.

YOU have type system and code suggestions and auto completion~~like you write C# code....

take a look at the example here: neo-cli/template.cs

@shargon
Copy link
Member

shargon commented Oct 10, 2023

@shargon it is C# script, where you can write c# code to construct transactions and interact with the neo blockchain, then run the script in the cli, it is painful to use cli since there is no type system right? now this is the solution, you can use this to conveniently do complex operations however you like. Airdrop, event monitoring, all can be done in script.

take a look at the example here: neo-cli/template.cs

Can we avoid to use reflection in that script?

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 10, 2023

Can we avoid to use reflection in that script?

i am afrait this is how it works. You have security concerns?

@shargon
Copy link
Member

shargon commented Oct 11, 2023

Can we avoid to use reflection in that script?

i am afrait this is how it works. You have security concerns?

I would not like the user to be able to access to the Storage or internal methods with this script.

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 11, 2023

I would not like the user to be able to access to the Storage or internal methods with this script.

i dont quite understand the reason of your concern, both script and dll exists in the node without particular protection, if you are considering that attackers might use this script to attack the node, well, it can do it anyway since it has hacked into the node.

Your concern make sense only if we have strong protection on the executable binary or dll. otherwise a script or an attacker written C# project can basically do the same bad thing.

BTW, since reflection namespace is not refered, write reflection code in the script would be impossible hard.

Update:
YES, only public methods are accessible.

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 18, 2023

@shargon how do you think?

@Jim8y Jim8y requested a review from shargon October 18, 2023 10:31
@shargon
Copy link
Member

shargon commented Oct 18, 2023

I'm worried about people who make scripts to supposedly do something, and people who don't know how to program execute this code.

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 18, 2023

this can be disabled by default tough, only guys who need it and konws how to use it can able it.

@shargon
Copy link
Member

shargon commented Oct 19, 2023

this can be disabled by default tough, only guys who need it and konws how to use it can able it.

Then, It's better to do it as a module.

var verificationScript = Contract.CreateSignatureContract(keyPair.PublicKey).Script;
transaction.Witnesses = new Witness[] { new Witness { InvocationScript = invocationScript, VerificationScript = verificationScript } };
Console.WriteLine($"HASH: {transaction.Hash}");
Console.WriteLine($"{transaction.Verify(NeoSystem.Settings, snapshot, new(), new Transaction[] { })}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should be Debug.Assert?

Attributes = new TransactionAttribute[],
Script = sb.ToArray(),
Signers = new Signer[] { new Signer { Account = scriptHash, Scopes = WitnessScope.CalledByEntry } },
ValidUntilBlock = blockIndex + 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus NeoSystem.Settings.MaxValidUntilBlockIncrement?

@shargon shargon changed the title Cli: Adding Script System for neo-cli node: Cli: Adding Script System for neo-cli Dec 5, 2023
@shargon shargon added the node label Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants