diff --git a/Cargo.lock b/Cargo.lock index a9d388d1a5..503ffcbec7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,7 +974,7 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "bytecode-interpreter-crypto" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "curve25519-dalek-fiat", @@ -4356,7 +4356,7 @@ checksum = "1fafa6961cabd9c63bcd77a45d7e3b7f3b552b70417831fb0f56db717e72407e" [[package]] name = "move-abigen" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4373,7 +4373,7 @@ dependencies = [ [[package]] name = "move-binary-format" version = "0.0.3" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-core-types", @@ -4386,12 +4386,12 @@ dependencies = [ [[package]] name = "move-borrow-graph" version = "0.0.1" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" [[package]] name = "move-bytecode-source-map" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4406,7 +4406,7 @@ dependencies = [ [[package]] name = "move-bytecode-utils" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-binary-format", @@ -4418,7 +4418,7 @@ dependencies = [ [[package]] name = "move-bytecode-verifier" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "fail", @@ -4431,7 +4431,7 @@ dependencies = [ [[package]] name = "move-bytecode-viewer" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "clap 3.2.25", @@ -4448,7 +4448,7 @@ dependencies = [ [[package]] name = "move-cli" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4494,7 +4494,7 @@ dependencies = [ [[package]] name = "move-command-line-common" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "difference", @@ -4511,7 +4511,7 @@ dependencies = [ [[package]] name = "move-compiler" version = "0.0.1" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4540,7 +4540,7 @@ dependencies = [ [[package]] name = "move-core-types" version = "0.0.4" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "arbitrary", @@ -4562,7 +4562,7 @@ dependencies = [ [[package]] name = "move-coverage" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4582,7 +4582,7 @@ dependencies = [ [[package]] name = "move-disassembler" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "clap 3.2.25", @@ -4600,7 +4600,7 @@ dependencies = [ [[package]] name = "move-docgen" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "codespan", @@ -4618,7 +4618,7 @@ dependencies = [ [[package]] name = "move-errmapgen" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4632,7 +4632,7 @@ dependencies = [ [[package]] name = "move-ir-compiler" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4651,7 +4651,7 @@ dependencies = [ [[package]] name = "move-ir-to-bytecode" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "codespan-reporting", @@ -4670,7 +4670,7 @@ dependencies = [ [[package]] name = "move-ir-to-bytecode-syntax" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "hex", @@ -4683,7 +4683,7 @@ dependencies = [ [[package]] name = "move-ir-types" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "hex", @@ -4697,7 +4697,7 @@ dependencies = [ [[package]] name = "move-model" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "codespan", @@ -4723,7 +4723,7 @@ dependencies = [ [[package]] name = "move-package" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4759,7 +4759,7 @@ dependencies = [ [[package]] name = "move-prover" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "async-trait", @@ -4796,7 +4796,7 @@ dependencies = [ [[package]] name = "move-prover-boogie-backend" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "async-trait", @@ -4825,7 +4825,7 @@ dependencies = [ [[package]] name = "move-read-write-set-types" version = "0.0.3" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-binary-format", @@ -4836,7 +4836,7 @@ dependencies = [ [[package]] name = "move-resource-viewer" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4851,7 +4851,7 @@ dependencies = [ [[package]] name = "move-stackless-bytecode" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "codespan", "codespan-reporting", @@ -4878,7 +4878,7 @@ dependencies = [ [[package]] name = "move-stackless-bytecode-interpreter" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bytecode-interpreter-crypto", @@ -4896,7 +4896,7 @@ dependencies = [ [[package]] name = "move-stdlib" version = "0.1.1" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "hex", @@ -4919,7 +4919,7 @@ dependencies = [ [[package]] name = "move-symbol-pool" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "once_cell", "serde 1.0.188", @@ -4928,7 +4928,7 @@ dependencies = [ [[package]] name = "move-table-extension" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "bcs", @@ -4945,7 +4945,7 @@ dependencies = [ [[package]] name = "move-transactional-test-runner" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "clap 3.2.25", @@ -4977,7 +4977,7 @@ dependencies = [ [[package]] name = "move-unit-test" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "better_any", @@ -5008,7 +5008,7 @@ dependencies = [ [[package]] name = "move-vm-runtime" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "better_any", "fail", @@ -5025,7 +5025,7 @@ dependencies = [ [[package]] name = "move-vm-test-utils" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-binary-format", @@ -5039,7 +5039,7 @@ dependencies = [ [[package]] name = "move-vm-types" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "bcs", "move-binary-format", @@ -6707,7 +6707,7 @@ dependencies = [ [[package]] name = "read-write-set" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-binary-format", @@ -6722,7 +6722,7 @@ dependencies = [ [[package]] name = "read-write-set-dynamic" version = "0.1.0" -source = "git+https://github.com/rooch-network/move?rev=782ed81dbe10e406779ad4499259e2dbe9a04c6d#782ed81dbe10e406779ad4499259e2dbe9a04c6d" +source = "git+https://github.com/rooch-network/move?rev=e2caf0ac9c788e6e487a9d35d1530254c747650c#e2caf0ac9c788e6e487a9d35d1530254c747650c" dependencies = [ "anyhow", "move-binary-format", diff --git a/Cargo.toml b/Cargo.toml index 6d612f9fc5..67022cc8bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -205,39 +205,39 @@ anstream = { version = "0.3" } # Note: the BEGIN and END comments below are required for external tooling. Do not remove. # BEGIN MOVE DEPENDENCIES -move-abigen = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-binary-format = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-cli = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-compiler ={ git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-core-types = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d", features = ["address32"] } -move-coverage = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-disassembler = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-docgen = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-model = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-package = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-prover = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-stdlib = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d", features = ["address32", "testing"] } -move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-unit-test = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d", features = ["table-extension"] } -move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d", features = ["lazy_natives"] } -move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d", features = ["table-extension"] } -move-vm-types = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -read-write-set = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" } -move-ir-types = { git = "https://github.com/rooch-network/move", rev = "782ed81dbe10e406779ad4499259e2dbe9a04c6d" }# END MOVE DEPENDENCIES +move-abigen = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-binary-format = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-cli = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-compiler ={ git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-core-types = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c", features = ["address32"] } +move-coverage = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-disassembler = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-docgen = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-model = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-package = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-prover = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-stdlib = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c", features = ["address32", "testing"] } +move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-unit-test = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c", features = ["table-extension"] } +move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c", features = ["lazy_natives"] } +move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c", features = ["table-extension"] } +move-vm-types = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +read-write-set = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" } +move-ir-types = { git = "https://github.com/rooch-network/move", rev = "e2caf0ac9c788e6e487a9d35d1530254c747650c" }# END MOVE DEPENDENCIES # keep this for convenient debug Move in local repo # [patch.'https://github.com/rooch-network/move'] diff --git a/crates/rooch-framework/src/natives/gas_parameter/account.rs b/crates/rooch-framework/src/natives/gas_parameter/account.rs new file mode 100644 index 0000000000..92fae4a028 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/account.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::account::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "account", [ + [.create_signer.base, "create_signer.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/bcd.rs b/crates/rooch-framework/src/natives/gas_parameter/bcd.rs new file mode 100644 index 0000000000..95cab66169 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/bcd.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::bcs::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "bcd", [ + [.from_bytes.base, "from_bytes.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/decoding.rs b/crates/rooch-framework/src/natives/gas_parameter/decoding.rs new file mode 100644 index 0000000000..a972729f99 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/decoding.rs @@ -0,0 +1,10 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::decoding::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "decoding", [ + [.base58.base, "base58.base", (5 + 1) * MUL], + [.base58check.base, "base58check.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1.rs b/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1.rs new file mode 100644 index 0000000000..7dd8008280 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::ecdsa_k1::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "ecdsa_k1", [ + [.verify.base, "verify.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1_recoverable.rs b/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1_recoverable.rs new file mode 100644 index 0000000000..b16289907b --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/ecdsa_k1_recoverable.rs @@ -0,0 +1,11 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::ecdsa_k1_recoverable::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "ecdsa_k1_recoverable", [ + [.verify.base, "verify.base", (5 + 1) * MUL], + [.ecrecover.base, "ecrecover.base", (5 + 1) * MUL], + [.decompress_pubkey.base, "decompress_pubkey.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/ed25519.rs b/crates/rooch-framework/src/natives/gas_parameter/ed25519.rs new file mode 100644 index 0000000000..288ee03054 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/ed25519.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::ed25519::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "ed25519", [ + [.verify.base, "verify.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/encoding.rs b/crates/rooch-framework/src/natives/gas_parameter/encoding.rs new file mode 100644 index 0000000000..858054d192 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/encoding.rs @@ -0,0 +1,13 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::encoding::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "encoding", [ + [.base58.base, "base58.base", (5 + 1) * MUL], + [.base58check.base, "base58check.base", (5 + 1) * MUL], + [.bech32.base, "bech32.base", (5 + 1) * MUL], + [.p2pkh.base, "p2pkh.base", (5 + 1) * MUL], + [.p2sh.base, "p2sh.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/events.rs b/crates/rooch-framework/src/natives/gas_parameter/events.rs new file mode 100644 index 0000000000..c3e776ca60 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/events.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::event::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "events", [ + [.emit.base, "emit.base", (52 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/gas_member.rs b/crates/rooch-framework/src/natives/gas_parameter/gas_member.rs new file mode 100644 index 0000000000..f4d8989e56 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/gas_member.rs @@ -0,0 +1,26 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use std::collections::BTreeMap; + +/// A trait for converting from a map representation of the on-chain gas schedule. +pub trait FromOnChainGasSchedule: Sized { + /// Constructs a value of this type from a map representation of the on-chain gas schedule. + /// `None` should be returned when the gas schedule is missing some required entries. + /// Unused entries should be safely ignored. + fn from_on_chain_gas_schedule(gas_schedule: &BTreeMap) -> Option; +} + +/// A trait for converting to a list of entries of the on-chain gas schedule. +pub trait ToOnChainGasSchedule { + /// Converts `self` into a list of entries of the on-chain gas schedule. + /// Each entry is a key-value pair where the key is a string representing the name of the + /// parameter, where the value is the gas parameter itself. + fn to_on_chain_gas_schedule(&self) -> Vec<(String, u64)>; +} + +/// A trait for defining an initial value to be used in the genesis. +pub trait InitialGasSchedule: Sized { + /// Returns the initial value of this type, which is used in the genesis. + fn initial() -> Self; +} diff --git a/crates/rooch-framework/src/natives/gas_parameter/hash.rs b/crates/rooch-framework/src/natives/gas_parameter/hash.rs new file mode 100644 index 0000000000..2627c43e9c --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/hash.rs @@ -0,0 +1,11 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::hash::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "hash", [ + [.keccak256.base, "keccak256.base", (5 + 1) * MUL], + [.blake2b256.base, "blake2b256.base", (5 + 1) * MUL], + [.ripemd160.base, "ripemd160.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/mod.rs b/crates/rooch-framework/src/natives/gas_parameter/mod.rs new file mode 100644 index 0000000000..78cae4ea69 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/mod.rs @@ -0,0 +1,22 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 +mod account; +mod bcd; +mod decoding; +mod ecdsa_k1; +mod ecdsa_k1_recoverable; +mod ed25519; +mod encoding; +mod events; +pub mod gas_member; +mod hash; +mod move_module; +pub mod move_std; +pub mod native; +pub mod nursery; +mod rlp; +mod schnorr; +mod signer; +mod table_extension; +mod test_helper; +mod type_info; diff --git a/crates/rooch-framework/src/natives/gas_parameter/move_module.rs b/crates/rooch-framework/src/natives/gas_parameter/move_module.rs new file mode 100644 index 0000000000..314b866ce7 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/move_module.rs @@ -0,0 +1,16 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::move_module::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "move_module", [ + [.module_name_inner.base, "module_name_inner.base", (5 + 1) * MUL], + [.module_name_inner.per_byte_in_str, "module_name_inner.per_byte_in_str", (5 + 1) * MUL], + [.verify_modules_inner.base, "verify_modules_inner.base", (5 + 1) * MUL], + [.verify_modules_inner.per_byte, "verify_modules_inner.per_byte", (5 + 1) * MUL], + [.request_init_functions.base, "request_init_functions.base", (5 + 1) * MUL], + [.request_init_functions.per_byte, "request_init_functions.per_byte", (5 + 1) * MUL], + [.check_compatibililty_inner.base, "check_compatibililty_inner.base", (5 + 1) * MUL], + [.check_compatibililty_inner.per_byte, "check_compatibililty_inner.per_byte", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/move_std.rs b/crates/rooch-framework/src/natives/gas_parameter/move_std.rs new file mode 100644 index 0000000000..e08dbfd561 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/move_std.rs @@ -0,0 +1,32 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use move_stdlib::natives::GasParameters; + +// modify should with impl From for GasSchedule +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "move_stdlib", [ + [.bcs.to_bytes.per_byte_serialized, "bcs.to_bytes.per_byte_serialized", (181 + 1) * MUL], + [.bcs.to_bytes.failure, "bcs.to_bytes.failure", (181 + 1) * MUL], + [.bcs.to_bytes.legacy_min_output_size, "bcs.to_bytes.legacy_min_output_size", MUL], + + [.hash.sha2_256.per_byte, "hash.sha2_256.per_byte", (21 + 1) * MUL], + [.hash.sha2_256.legacy_min_input_len, "hash.sha2_256.legacy_min_input_len", MUL], + [.hash.sha3_256.per_byte, "hash.sha3_256.per_byte", (64 + 1) * MUL], + [.hash.sha3_256.legacy_min_input_len, "hash.sha3_256.legacy_min_input_len", MUL], + + [.signer.borrow_address.base, "signer.borrow_address.base", (353 + 1) * MUL], + + [.string.check_utf8.per_byte, optional "string.check_utf8.per_byte", (4 + 1) * MUL], + [.string.is_char_boundary.base, optional "string.is_char_boundary.base", (4 + 1) * MUL], + [.string.sub_string.per_byte, optional "string.sub_string.per_byte", (4 + 1) * MUL], + [.string.index_of.per_byte_searched, optional "string.index_of.per_byte_searched", (4 + 1) * MUL], + + [.vector.length.base, "vector.length.base", (98 + 1) * MUL], + [.vector.empty.base, "vector.empty.base", (84 + 1) * MUL], + [.vector.borrow.base, "vector.borrow.base", (1334 + 1) * MUL], + [.vector.push_back.legacy_per_abstract_memory_unit, "vector.push_back.legacy_per_abstract_memory_unit", (53 + 1) * MUL], + [.vector.pop_back.base, "vector.pop_back.base", (227 + 1) * MUL], + [.vector.destroy_empty.base, "vector.destroy_empty.base", (572 + 1) * MUL], + [.vector.swap.base, "vector.swap.base", (1436 + 1) * MUL], +], allow_unmapped = 2); diff --git a/crates/rooch-framework/src/natives/gas_parameter/native.rs b/crates/rooch-framework/src/natives/gas_parameter/native.rs new file mode 100644 index 0000000000..299efcdd78 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/native.rs @@ -0,0 +1,158 @@ +// Copyright (c) The Starcoin Core Contributors +// SPDX-License-Identifier: Apache-2.0 +pub const MUL: u64 = 1; + +macro_rules! expand_get_impl_for_native_gas_params { + ($params: ident $(.$field: ident)+, $map: ident, $prefix: literal, optional $key: literal) => { + if let Some(val) = $map.get(&format!("{}.{}", $prefix, $key)) { + $params $(.$field)+ = (*val).into(); + } + }; + ($params: ident $(.$field: ident)+, $map: ident, $prefix: literal, $key: literal) => { + $params $(.$field)+ = $map.get(&format!("{}.{}", $prefix, $key)).cloned()?.into(); + }; +} + +macro_rules! expand_get_for_native_gas_params { + (test_only $(.$field: ident)+, $(optional $($dummy: ident)?)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident, $gas_schedule: ident) => { + // TODO(Gas): this is a hack to work-around issue + // https://github.com/rust-lang/rust/issues/15701 + { + #[cfg(feature = "testing")] + fn assign(params: &mut $param_ty, gas_schedule: &std::collections::BTreeMap) -> Option<()> { + $crate::natives::gas_parameter::expand_get_impl_for_native_gas_params!(params $(.$field)+, gas_schedule, $package_name, $(optional $($dummy)?)? $key); + Some(()) + } + + #[cfg(not(feature = "testing"))] + fn assign(_params: &mut $param_ty, _gas_schedule: &std::collections::BTreeMap) -> Option<()> { + Some(()) + } + + assign(&mut $params, &$gas_schedule)?; + } + }; + ($(.$field: ident)+, $(optional $($dummy: ident)?)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident, $gas_schedule: ident) => { + $crate::natives::gas_parameter::native::expand_get_impl_for_native_gas_params!($params $(.$field)+, $gas_schedule, $package_name, $(optional $($dummy)?)? $key); + } +} + +macro_rules! expand_set_for_native_gas_params { + (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident) => { + { + #[cfg(feature = "testing")] + fn assign(params: &mut $param_ty) { + params $(.$field)+ = $initial_val.into(); + } + + #[cfg(not(feature = "testing"))] + fn assign(_params: &mut $param_ty) { + } + + assign(&mut $params); + } + }; + ($(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $param_ty: ty, $package_name: literal, $params: ident) => { + $params $(.$field)+ = $initial_val.into() + }; +} + +macro_rules! expand_kv_for_native_gas_params { + (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $self: ident) => { + #[cfg(feature = "testing")] + ($key, u64::from($self $(.$field)+)) + }; + ($(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr, $self: ident) => { + ($key, u64::from($self $(.$field)+)) + } +} + +#[cfg(test)] +macro_rules! extract_key_for_native_gas_params { + (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr) => { + #[cfg(feature = "testing")] + $key + }; + ($(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr) => { + $key + }; +} + +#[cfg(test)] +macro_rules! extract_path_for_native_gas_params { + (test_only $(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr) => { + #[cfg(feature = "testing")] + stringify!($($field).*) + }; + ($(.$field: ident)+, $(optional)? $key: literal, $initial_val: expr) => { + stringify!($($field).*) + }; +} + +macro_rules! define_gas_parameters_for_natives { + ($param_ty: ty, $package_name: literal, [$([$($t: tt)*]),* $(,)?] $(, allow_unmapped = $allow_unmapped: expr)?) => { + impl crate::natives::gas_parameter::gas_member::FromOnChainGasSchedule for $param_ty { + fn from_on_chain_gas_schedule(gas_schedule: &std::collections::BTreeMap) -> Option { + let mut params = <$param_ty>::zeros(); + + $( + crate::natives::gas_parameter::native::expand_get_for_native_gas_params!($($t)*, $param_ty, $package_name, params, gas_schedule); + )* + + Some(params) + } + } + + impl crate::natives::gas_parameter::gas_member::ToOnChainGasSchedule for $param_ty { + fn to_on_chain_gas_schedule(&self) -> Vec<(String, u64)> { + [$(crate::natives::gas_parameter::native::expand_kv_for_native_gas_params!($($t)*, self)),*] + .into_iter().map(|(key, val)| (format!("{}.{}", $package_name, key), val)).collect() + } + } + + impl crate::natives::gas_parameter::gas_member::InitialGasSchedule for $param_ty { + fn initial() -> Self { + let mut params = <$param_ty>::zeros(); + + $( + crate::natives::gas_parameter::native::expand_set_for_native_gas_params!($($t)*, $param_ty, $package_name, params); + )* + + params + } + } + + #[test] + fn keys_should_be_unique() { + let mut map = std::collections::BTreeMap::<&str, ()>::new(); + + for key in [$(crate::natives::gas_parameter::native::extract_key_for_native_gas_params!($($t)*)),*] { + if map.insert(key.clone(), ()).is_some() { + panic!("duplicated key {}", key); + } + } + } + + #[test] + fn paths_must_be_unique() { + let mut map = std::collections::BTreeMap::<&str, ()>::new(); + + for path in [$(crate::natives::gas_parameter::native::extract_path_for_native_gas_params!($($t)*)),*] { + if map.insert(path.clone(), ()).is_some() { + panic!("duplicated path {}", path); + } + } + } + }; +} + +#[cfg(test)] +pub(crate) use extract_key_for_native_gas_params; +#[cfg(test)] +pub(crate) use extract_path_for_native_gas_params; + +pub(crate) use define_gas_parameters_for_natives; +pub(crate) use expand_get_for_native_gas_params; +pub(crate) use expand_get_impl_for_native_gas_params; +pub(crate) use expand_kv_for_native_gas_params; +pub(crate) use expand_set_for_native_gas_params; diff --git a/crates/rooch-framework/src/natives/gas_parameter/nursery.rs b/crates/rooch-framework/src/natives/gas_parameter/nursery.rs new file mode 100644 index 0000000000..45dc063de6 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/nursery.rs @@ -0,0 +1,11 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use move_stdlib::natives::NurseryGasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(NurseryGasParameters, "nursery", [ + [.event.write_to_event_store.unit_cost, "event.write_to_event_store.unit_cost", (5 + 1) * MUL], + [.debug.print.base_cost, optional "debug.print.base_cost", MUL], + [.debug.print_stack_trace.base_cost, optional "debug.print_stack_trace.base_cost", MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/rlp.rs b/crates/rooch-framework/src/natives/gas_parameter/rlp.rs new file mode 100644 index 0000000000..43f8630b32 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/rlp.rs @@ -0,0 +1,10 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::rlp::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "rlp", [ + [.to_bytes.base, "to_bytes.base", (5 + 1) * MUL], + [.from_bytes.base, "from_bytes.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/schnorr.rs b/crates/rooch-framework/src/natives/gas_parameter/schnorr.rs new file mode 100644 index 0000000000..4e9dd5e997 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/schnorr.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use crate::natives::rooch_framework::crypto::schnorr::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "schnorr", [ + [.verify.base, "verify.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/signer.rs b/crates/rooch-framework/src/natives/gas_parameter/signer.rs new file mode 100644 index 0000000000..467d9672e6 --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/signer.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::signer::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "type_info", [ + [.module_signer.base, "module_signer.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/table_extension.rs b/crates/rooch-framework/src/natives/gas_parameter/table_extension.rs new file mode 100644 index 0000000000..0d570e01ea --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/table_extension.rs @@ -0,0 +1,21 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::raw_table::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "table_extension", [ + [.common.load_base, "common.load_base", (5 + 1) * MUL], + [.common.load_per_byte, "common.load_per_byte", (5 + 1) * MUL], + [.common.load_failure, "common.load_failure", (5 + 1) * MUL], + [.add_box.base, "add_box.base", (5 + 1) * MUL], + [.add_box.per_byte_serialized, "add_box.per_byte_serialized", (5 + 1) * MUL], + [.borrow_box.base, "borrow_box.base", (5 + 1) * MUL], + [.borrow_box.per_byte_serialized, "borrow_box.per_byte_serialized", (5 + 1) * MUL], + [.contains_box.base, "contains_box.base", (5 + 1) * MUL], + [.contains_box.per_byte_serialized, "contains_box.per_byte_serialized", (5 + 1) * MUL], + [.remove_box.base, "remove_box.base", (5 + 1) * MUL], + [.remove_box.per_byte_serialized, "remove_box.per_byte_serialized", (5 + 1) * MUL], + [.destroy_empty_box.base, "destroy_empty_box.base", (5 + 1) * MUL], + [.drop_unchecked_box.base, "drop_unchecked_box.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/test_helper.rs b/crates/rooch-framework/src/natives/gas_parameter/test_helper.rs new file mode 100644 index 0000000000..c4e311b3ee --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/test_helper.rs @@ -0,0 +1,9 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::test_helper::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "test_helper", [ + [.destroy.base, "destroy.base", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/gas_parameter/type_info.rs b/crates/rooch-framework/src/natives/gas_parameter/type_info.rs new file mode 100644 index 0000000000..12b8243a6e --- /dev/null +++ b/crates/rooch-framework/src/natives/gas_parameter/type_info.rs @@ -0,0 +1,10 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use crate::natives::gas_parameter::native::MUL; +use moveos_stdlib::natives::moveos_stdlib::type_info::GasParameters; + +crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "type_info", [ + [.type_of.base, "type_of.base", (5 + 1) * MUL], + [.type_of.per_byte_in_str, "type_of.per_byte_in_str", (5 + 1) * MUL], +]); diff --git a/crates/rooch-framework/src/natives/mod.rs b/crates/rooch-framework/src/natives/mod.rs index 7b145979c1..047d9f8621 100644 --- a/crates/rooch-framework/src/natives/mod.rs +++ b/crates/rooch-framework/src/natives/mod.rs @@ -1,12 +1,16 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 +use crate::natives::gas_parameter::gas_member::{FromOnChainGasSchedule, InitialGasSchedule}; use crate::ROOCH_FRAMEWORK_ADDRESS; use move_vm_runtime::native_functions::{make_table_from_iter, NativeFunctionTable}; +use moveos_stdlib::natives::GasParameters as MoveOSGasParameters; +use std::collections::BTreeMap; pub mod helpers { pub use moveos_stdlib::natives::helpers::*; } +pub mod gas_parameter; pub mod rooch_framework; #[derive(Debug, Clone)] @@ -22,6 +26,80 @@ pub struct GasParameters { decoding: rooch_framework::crypto::decoding::GasParameters, } +impl FromOnChainGasSchedule for GasParameters { + fn from_on_chain_gas_schedule(gas_schedule: &BTreeMap) -> Option { + Some(Self { + moveos_stdlib: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule) + .unwrap(), + account: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + hash: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + ed25519: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + ecdsa_k1: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + ecdsa_k1_recoverable: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule) + .unwrap(), + schnorr: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + encoding: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + decoding: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + }) + } +} + +impl InitialGasSchedule for GasParameters { + fn initial() -> Self { + Self { + moveos_stdlib: InitialGasSchedule::initial(), + account: InitialGasSchedule::initial(), + hash: InitialGasSchedule::initial(), + ed25519: InitialGasSchedule::initial(), + ecdsa_k1: InitialGasSchedule::initial(), + ecdsa_k1_recoverable: InitialGasSchedule::initial(), + schnorr: InitialGasSchedule::initial(), + encoding: InitialGasSchedule::initial(), + decoding: InitialGasSchedule::initial(), + } + } +} + +impl FromOnChainGasSchedule for MoveOSGasParameters { + fn from_on_chain_gas_schedule(gas_schedule: &BTreeMap) -> Option { + Some(Self { + move_stdlib: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + move_nursery: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + table_extension: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule) + .unwrap(), + type_info: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + rlp: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + bcd: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + events: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + test_helper: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + signer: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + move_module: FromOnChainGasSchedule::from_on_chain_gas_schedule(gas_schedule).unwrap(), + }) + } +} + +impl InitialGasSchedule for MoveOSGasParameters { + fn initial() -> Self { + Self { + move_stdlib: InitialGasSchedule::initial(), + move_nursery: InitialGasSchedule::initial(), + table_extension: InitialGasSchedule::initial(), + type_info: InitialGasSchedule::initial(), + rlp: InitialGasSchedule::initial(), + bcd: InitialGasSchedule::initial(), + events: InitialGasSchedule::initial(), + test_helper: InitialGasSchedule::initial(), + signer: InitialGasSchedule::initial(), + move_module: InitialGasSchedule::initial(), + } + } +} + +pub fn get_global_gas_parameter() { + let gas_parameter = GasParameters::initial(); + println!("global gas parameter {:?}", gas_parameter); +} + impl GasParameters { pub fn zeros() -> Self { Self { diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/decoding.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/decoding.rs index e2e71d83d2..189342de75 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/decoding.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/decoding.rs @@ -3,6 +3,7 @@ use crate::natives::helpers::{make_module_natives, make_native}; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -86,11 +87,13 @@ pub fn native_base58check( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1.rs index a602fee964..32cc3ebcef 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1.rs @@ -8,6 +8,7 @@ use fastcrypto::{ traits::ToFromBytes, }; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -69,11 +70,13 @@ pub fn native_verify( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs index 3206371318..7ea5bf6575 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/ecdsa_k1_recoverable.rs @@ -9,6 +9,7 @@ use fastcrypto::{ traits::{RecoverableSignature, ToFromBytes}, }; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -149,11 +150,13 @@ pub fn native_verify( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/ed25519.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/ed25519.rs index c4e6c02237..037a84e9a3 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/ed25519.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/ed25519.rs @@ -16,6 +16,7 @@ use move_vm_types::{ use crate::natives::helpers::{make_module_natives, make_native}; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; +use move_core_types::gas_algebra::InternalGas; use smallvec::smallvec; use std::collections::VecDeque; @@ -61,11 +62,13 @@ pub fn native_verify( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/encoding.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/encoding.rs index 89cc6693a4..980179f8b6 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/encoding.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/encoding.rs @@ -7,6 +7,7 @@ use bitcoin::{Address, PublicKey}; use bitcoin_bech32::{constants::Network as Bech32Network, u5, WitnessProgram}; use fastcrypto::{secp256k1::Secp256k1PublicKey, traits::ToFromBytes}; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -217,11 +218,13 @@ pub fn native_p2sh( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/hash.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/hash.rs index dd2cf76dc6..7b3e6b2b35 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/hash.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/hash.rs @@ -4,6 +4,7 @@ use crate::natives::helpers::{make_module_natives, make_native}; use fastcrypto::hash::{Blake2b256, HashFunction, Keccak256, Ripemd160}; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -83,11 +84,13 @@ pub fn native_ripemd160( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-framework/src/natives/rooch_framework/crypto/schnorr.rs b/crates/rooch-framework/src/natives/rooch_framework/crypto/schnorr.rs index f1670c5199..3f904750cf 100644 --- a/crates/rooch-framework/src/natives/rooch_framework/crypto/schnorr.rs +++ b/crates/rooch-framework/src/natives/rooch_framework/crypto/schnorr.rs @@ -8,6 +8,7 @@ use fastcrypto::{ traits::ToFromBytes, }; use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -70,11 +71,13 @@ pub fn native_verify( } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/crates/rooch-genesis/src/lib.rs b/crates/rooch-genesis/src/lib.rs index 7645fe41dc..4930fbda84 100644 --- a/crates/rooch-genesis/src/lib.rs +++ b/crates/rooch-genesis/src/lib.rs @@ -13,6 +13,7 @@ use moveos_types::h256; use moveos_types::h256::H256; use moveos_types::transaction::MoveAction; use once_cell::sync::Lazy; +use rooch_framework::natives::gas_parameter::gas_member::InitialGasSchedule; use rooch_types::chain_id::RoochChainID; use rooch_types::error::GenesisError; use rooch_types::framework::genesis; @@ -165,7 +166,7 @@ impl GenesisPackage { }) .collect(); //TODO put gas parameters into genesis package - let gas_parameters = rooch_framework::natives::GasParameters::zeros(); + let gas_parameters = rooch_framework::natives::GasParameters::initial(); let vm_config = MoveOSConfig { vm_config: VMConfig::default(), }; diff --git a/moveos/moveos-stdlib/src/natives/mod.rs b/moveos/moveos-stdlib/src/natives/mod.rs index e41d181ea1..ce31691036 100644 --- a/moveos/moveos-stdlib/src/natives/mod.rs +++ b/moveos/moveos-stdlib/src/natives/mod.rs @@ -11,16 +11,16 @@ pub mod moveos_stdlib; #[derive(Debug, Clone)] pub struct GasParameters { - move_stdlib: move_stdlib::natives::GasParameters, - move_nursery: move_stdlib::natives::NurseryGasParameters, - table_extension: raw_table::GasParameters, - type_info: moveos_stdlib::type_info::GasParameters, - rlp: moveos_stdlib::rlp::GasParameters, - bcd: moveos_stdlib::bcs::GasParameters, - events: moveos_stdlib::event::GasParameters, - test_helper: moveos_stdlib::test_helper::GasParameters, - signer: moveos_stdlib::signer::GasParameters, - move_module: moveos_stdlib::move_module::GasParameters, + pub move_stdlib: move_stdlib::natives::GasParameters, + pub move_nursery: move_stdlib::natives::NurseryGasParameters, + pub table_extension: raw_table::GasParameters, + pub type_info: moveos_stdlib::type_info::GasParameters, + pub rlp: moveos_stdlib::rlp::GasParameters, + pub bcd: moveos_stdlib::bcs::GasParameters, + pub events: moveos_stdlib::event::GasParameters, + pub test_helper: moveos_stdlib::test_helper::GasParameters, + pub signer: moveos_stdlib::signer::GasParameters, + pub move_module: moveos_stdlib::move_module::GasParameters, } impl GasParameters { diff --git a/moveos/moveos-stdlib/src/natives/moveos_stdlib/bcs.rs b/moveos/moveos-stdlib/src/natives/moveos_stdlib/bcs.rs index f18f67d4c0..1bbd7b3081 100644 --- a/moveos/moveos-stdlib/src/natives/moveos_stdlib/bcs.rs +++ b/moveos/moveos-stdlib/src/natives/moveos_stdlib/bcs.rs @@ -3,6 +3,7 @@ use crate::natives::helpers::{make_module_natives, make_native}; use move_binary_format::errors::{PartialVMError, PartialVMResult}; +use move_core_types::gas_algebra::InternalGas; use move_core_types::vm_status::StatusCode; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ @@ -12,11 +13,13 @@ use smallvec::smallvec; use std::collections::VecDeque; #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/moveos/moveos-stdlib/src/natives/moveos_stdlib/rlp.rs b/moveos/moveos-stdlib/src/natives/moveos_stdlib/rlp.rs index 102ed48271..71ce9df752 100644 --- a/moveos/moveos-stdlib/src/natives/moveos_stdlib/rlp.rs +++ b/moveos/moveos-stdlib/src/natives/moveos_stdlib/rlp.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use move_binary_format::errors::PartialVMResult; +use move_core_types::gas_algebra::InternalGas; use move_vm_runtime::native_functions::{NativeContext, NativeFunction}; use move_vm_types::{ loaded_data::runtime_types::Type, natives::function::NativeResult, values::Value, @@ -11,11 +12,13 @@ use std::{collections::VecDeque, sync::Arc}; use crate::natives::helpers::make_module_natives; #[derive(Debug, Clone)] -pub struct ToBytesGasParameters {} +pub struct ToBytesGasParameters { + pub base: InternalGas, +} impl ToBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } @@ -38,11 +41,13 @@ pub fn make_native_to_bytes(gas_params: ToBytesGasParameters) -> NativeFunction } #[derive(Debug, Clone)] -pub struct FromBytesGasParameters {} +pub struct FromBytesGasParameters { + pub base: InternalGas, +} impl FromBytesGasParameters { pub fn zeros() -> Self { - Self {} + Self { base: 0.into() } } } diff --git a/moveos/moveos-stdlib/src/natives/moveos_stdlib/signer.rs b/moveos/moveos-stdlib/src/natives/moveos_stdlib/signer.rs index 918448d332..b9688c130d 100644 --- a/moveos/moveos-stdlib/src/natives/moveos_stdlib/signer.rs +++ b/moveos/moveos-stdlib/src/natives/moveos_stdlib/signer.rs @@ -15,7 +15,7 @@ use crate::natives::helpers::make_module_natives; #[derive(Debug, Clone)] pub struct ModuleSignerGasParameters { - base: InternalGas, + pub base: InternalGas, } impl ModuleSignerGasParameters { @@ -63,7 +63,7 @@ pub fn make_native_module_signer(gas_params: ModuleSignerGasParameters) -> Nativ #[derive(Debug, Clone)] pub struct GasParameters { - module_signer: ModuleSignerGasParameters, + pub module_signer: ModuleSignerGasParameters, } impl GasParameters { diff --git a/moveos/moveos/src/gas/mod.rs b/moveos/moveos/src/gas/mod.rs index ed315cd79f..aa79bbe782 100644 --- a/moveos/moveos/src/gas/mod.rs +++ b/moveos/moveos/src/gas/mod.rs @@ -3,6 +3,7 @@ use move_vm_types::gas::{GasMeter, UnmeteredGasMeter}; +pub mod parameter; pub mod table; pub trait SwitchableGasMeter: GasMeter { diff --git a/moveos/moveos/src/gas/parameter.rs b/moveos/moveos/src/gas/parameter.rs new file mode 100644 index 0000000000..5aadb9eaea --- /dev/null +++ b/moveos/moveos/src/gas/parameter.rs @@ -0,0 +1,556 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use move_binary_format::file_format::{ + Bytecode, ConstantPoolIndex, FieldHandleIndex, FieldInstantiationIndex, FunctionHandleIndex, + FunctionInstantiationIndex, SignatureIndex, StructDefInstantiationIndex, StructDefinitionIndex, +}; +use move_binary_format::file_format_common::instruction_key; +use move_vm_test_utils::gas_schedule::GasCost; +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; + +#[allow(non_camel_case_types)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[repr(u8)] +pub enum N { + SHA2_256 = 0, + SHA3_256 = 1, + ED25519_VERIFY = 2, + ED25519_THRESHOLD_VERIFY = 3, + BCS_TO_BYTES = 4, + LENGTH = 5, + EMPTY = 6, + BORROW = 7, + BORROW_MUT = 8, + PUSH_BACK = 9, + POP_BACK = 10, + DESTROY_EMPTY = 11, + SWAP = 12, + ED25519_VALIDATE_KEY = 13, + SIGNER_BORROW = 14, + CREATE_SIGNER = 15, + DESTROY_SIGNER = 16, + EMIT_EVENT = 17, + BCS_TO_ADDRESS = 18, + TOKEN_NAME_OF = 19, + KECCAK_256 = 20, + RIPEMD160 = 21, + ECRECOVER = 22, + U256_FROM_BYTES = 23, + U256_ADD = 24, + U256_SUB = 25, + U256_MUL = 26, + U256_DIV = 27, + U256_REM = 28, + U256_POW = 29, + VEC_APPEND = 30, + VEC_REMOVE = 31, + VEC_REVERSE = 32, + TABLE_NEW = 33, + TABLE_INSERT = 34, + TABLE_BORROW = 35, + TABLE_REMOVE = 36, + TABLE_CONTAINS = 37, + TABLE_DESTROY = 38, + TABLE_DROP = 39, + STRING_CHECK_UT8 = 40, + STRING_SUB_STR = 41, + SRING_CHAR_BOUNDARY = 42, + STRING_INDEX_OF = 43, + FROMBCS_FROM_BYTES = 44, + SECP256K1_ECDSA_RECOVER_INTERNAL = 45, + VECTOR_SPAWN_FROM = 46, +} + +impl N { + //note: should change this value when add new native function. + pub const NUMBER_OF_NATIVE_FUNCTIONS: usize = 47; +} + +// TODO: Place the gas_schedule on the blockchain instead of hardcoding it in the code. +pub fn v5_native_table() -> Vec { + let mut raw_native_table = vec![ + (N::SHA2_256, GasCost::new(21, 1)), + (N::SHA3_256, GasCost::new(64, 1)), + (N::ED25519_VERIFY, GasCost::new(61, 1)), + (N::ED25519_THRESHOLD_VERIFY, GasCost::new(3351, 1)), + (N::BCS_TO_BYTES, GasCost::new(181, 1)), + (N::LENGTH, GasCost::new(98, 1)), + (N::EMPTY, GasCost::new(84, 1)), + (N::BORROW, GasCost::new(1334, 1)), + (N::BORROW_MUT, GasCost::new(1902, 1)), + (N::PUSH_BACK, GasCost::new(53, 1)), + (N::POP_BACK, GasCost::new(227, 1)), + (N::DESTROY_EMPTY, GasCost::new(572, 1)), + (N::SWAP, GasCost::new(1436, 1)), + (N::ED25519_VALIDATE_KEY, GasCost::new(26, 1)), + (N::SIGNER_BORROW, GasCost::new(353, 1)), + (N::CREATE_SIGNER, GasCost::new(24, 1)), + (N::DESTROY_SIGNER, GasCost::new(212, 1)), + (N::EMIT_EVENT, GasCost::new(52, 1)), + (N::BCS_TO_ADDRESS, GasCost::new(26, 1)), + (N::TOKEN_NAME_OF, GasCost::new(2002, 1)), + (N::KECCAK_256, GasCost::new(64, 1)), + (N::RIPEMD160, GasCost::new(64, 1)), + (N::ECRECOVER, GasCost::new(128, 1)), + (N::U256_FROM_BYTES, GasCost::new(2, 1)), + (N::U256_ADD, GasCost::new(4, 1)), + (N::U256_SUB, GasCost::new(4, 1)), + (N::U256_MUL, GasCost::new(4, 1)), + (N::U256_DIV, GasCost::new(10, 1)), + (N::U256_REM, GasCost::new(4, 1)), + (N::U256_POW, GasCost::new(8, 1)), + (N::VEC_APPEND, GasCost::new(40, 1)), + (N::VEC_REMOVE, GasCost::new(20, 1)), + (N::VEC_REVERSE, GasCost::new(10, 1)), + (N::TABLE_NEW, GasCost::new(4, 1)), + (N::TABLE_INSERT, GasCost::new(4, 1)), + (N::TABLE_BORROW, GasCost::new(10, 1)), + (N::TABLE_REMOVE, GasCost::new(8, 1)), + (N::TABLE_CONTAINS, GasCost::new(40, 1)), + (N::TABLE_DESTROY, GasCost::new(20, 1)), + (N::TABLE_DROP, GasCost::new(73, 1)), + (N::STRING_CHECK_UT8, GasCost::new(4, 1)), + (N::STRING_SUB_STR, GasCost::new(4, 1)), + (N::SRING_CHAR_BOUNDARY, GasCost::new(4, 1)), + (N::STRING_INDEX_OF, GasCost::new(4, 1)), + (N::FROMBCS_FROM_BYTES, GasCost::new(4, 1)), + (N::SECP256K1_ECDSA_RECOVER_INTERNAL, GasCost::new(4, 1)), + (N::VECTOR_SPAWN_FROM, GasCost::new(4, 1)), + ]; + raw_native_table.sort_by_key(|cost| cost.0 as u64); + raw_native_table + .into_iter() + .map(|(_, cost)| cost) + .collect::>() +} + +pub static G_LATEST_NATIVE_TABLE: Lazy> = Lazy::new(|| { + let native_table = v5_native_table(); + + debug_assert!( + native_table.len() == N::NUMBER_OF_NATIVE_FUNCTIONS, + "all native functions must be in the cost table" + ); + native_table +}); + +#[derive(Clone, Debug, Serialize, PartialEq, Eq, Deserialize)] +pub struct GasConstants { + /// The cost per-byte read from global storage. + pub global_memory_per_byte_cost: u64, + + /// The cost per-byte written to storage. + pub global_memory_per_byte_write_cost: u64, + + /// The flat minimum amount of gas required for any transaction. + /// Charged at the start of execution. + pub min_transaction_gas_units: u64, + + /// Any transaction over this size will be charged an additional amount per byte. + pub large_transaction_cutoff: u64, + + /// The units of gas that to be charged per byte over the `large_transaction_cutoff` in addition to + /// `min_transaction_gas_units` for transactions whose size exceeds `large_transaction_cutoff`. + pub intrinsic_gas_per_byte: u64, + + /// ~5 microseconds should equal one unit of computational gas. We bound the maximum + /// computational time of any given transaction at roughly 20 seconds. We want this number and + /// `MAX_PRICE_PER_GAS_UNIT` to always satisfy the inequality that + /// MAXIMUM_NUMBER_OF_GAS_UNITS * MAX_PRICE_PER_GAS_UNIT < min(u64::MAX, GasUnits::MAX) + /// NB: The bound is set quite high since custom scripts aren't allowed except from predefined + /// and vetted senders. + pub maximum_number_of_gas_units: u64, + + /// The minimum gas price that a transaction can be submitted with. + pub min_price_per_gas_unit: u64, + + /// The maximum gas unit price that a transaction can be submitted with. + pub max_price_per_gas_unit: u64, + + pub max_transaction_size_in_bytes: u64, + + pub gas_unit_scaling_factor: u64, + pub default_account_size: u64, +} + +/// Any transaction over this size will be charged `INTRINSIC_GAS_PER_BYTE` per byte +pub static G_LARGE_TRANSACTION_CUTOFF: u64 = 600; + +pub static G_MAX_TRANSACTION_SIZE_IN_BYTES_V1: u64 = 4096 * 10; +pub static G_MAX_TRANSACTION_SIZE_IN_BYTES_V3: u64 = 128 * 1024; +pub static G_DEFAULT_ACCOUNT_SIZE: u64 = 800; + +pub static G_GAS_CONSTANTS: Lazy = Lazy::new(|| { + GasConstants { + global_memory_per_byte_cost: 4, + global_memory_per_byte_write_cost: 9, + min_transaction_gas_units: 600, + large_transaction_cutoff: G_LARGE_TRANSACTION_CUTOFF, + intrinsic_gas_per_byte: 8, + maximum_number_of_gas_units: 40_000_000, //must less than base_block_gas_limit + min_price_per_gas_unit: 1, + max_price_per_gas_unit: 10_000, + max_transaction_size_in_bytes: G_MAX_TRANSACTION_SIZE_IN_BYTES_V3, + gas_unit_scaling_factor: 1, + default_account_size: G_DEFAULT_ACCOUNT_SIZE, + } +}); + +pub static G_LATEST_GAS_CONSTANTS: Lazy = Lazy::new(|| G_GAS_CONSTANTS.clone()); + +#[derive(Clone, Debug, Serialize, PartialEq, Eq, Deserialize)] +pub struct CostTable { + pub instruction_table: Vec, + pub native_table: Vec, + pub gas_constants: GasConstants, +} + +pub fn instruction_table() -> Vec { + use Bytecode::*; + let mut instrs = vec![ + (MoveTo(StructDefinitionIndex::new(0)), GasCost::new(13, 1)), + ( + MoveToGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(27, 1), + ), + ( + MoveFrom(StructDefinitionIndex::new(0)), + GasCost::new(459, 1), + ), + ( + MoveFromGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(13, 1), + ), + (BrTrue(0), GasCost::new(1, 1)), + (WriteRef, GasCost::new(1, 1)), + (Mul, GasCost::new(1, 1)), + (MoveLoc(0), GasCost::new(1, 1)), + (And, GasCost::new(1, 1)), + (Pop, GasCost::new(1, 1)), + (BitAnd, GasCost::new(2, 1)), + (ReadRef, GasCost::new(1, 1)), + (Sub, GasCost::new(1, 1)), + (MutBorrowField(FieldHandleIndex::new(0)), GasCost::new(1, 1)), + ( + MutBorrowFieldGeneric(FieldInstantiationIndex::new(0)), + GasCost::new(1, 1), + ), + (ImmBorrowField(FieldHandleIndex::new(0)), GasCost::new(1, 1)), + ( + ImmBorrowFieldGeneric(FieldInstantiationIndex::new(0)), + GasCost::new(1, 1), + ), + (Add, GasCost::new(1, 1)), + (CopyLoc(0), GasCost::new(1, 1)), + (StLoc(0), GasCost::new(1, 1)), + (Ret, GasCost::new(638, 1)), + (Lt, GasCost::new(1, 1)), + (LdU8(0), GasCost::new(1, 1)), + (LdU64(0), GasCost::new(1, 1)), + (LdU128(0), GasCost::new(1, 1)), + (CastU8, GasCost::new(2, 1)), + (CastU64, GasCost::new(1, 1)), + (CastU128, GasCost::new(1, 1)), + (Abort, GasCost::new(1, 1)), + (MutBorrowLoc(0), GasCost::new(2, 1)), + (ImmBorrowLoc(0), GasCost::new(1, 1)), + (LdConst(ConstantPoolIndex::new(0)), GasCost::new(1, 1)), + (Ge, GasCost::new(1, 1)), + (Xor, GasCost::new(1, 1)), + (Shl, GasCost::new(2, 1)), + (Shr, GasCost::new(1, 1)), + (Neq, GasCost::new(1, 1)), + (Not, GasCost::new(1, 1)), + (Call(FunctionHandleIndex::new(0)), GasCost::new(1132, 1)), + ( + CallGeneric(FunctionInstantiationIndex::new(0)), + GasCost::new(582, 1), + ), + (Le, GasCost::new(2, 1)), + (Branch(0), GasCost::new(1, 1)), + (Unpack(StructDefinitionIndex::new(0)), GasCost::new(2, 1)), + ( + UnpackGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(2, 1), + ), + (Or, GasCost::new(2, 1)), + (LdFalse, GasCost::new(1, 1)), + (LdTrue, GasCost::new(1, 1)), + (Mod, GasCost::new(1, 1)), + (BrFalse(0), GasCost::new(1, 1)), + (Exists(StructDefinitionIndex::new(0)), GasCost::new(41, 1)), + ( + ExistsGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(34, 1), + ), + (BitOr, GasCost::new(2, 1)), + (FreezeRef, GasCost::new(1, 1)), + ( + MutBorrowGlobal(StructDefinitionIndex::new(0)), + GasCost::new(21, 1), + ), + ( + MutBorrowGlobalGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(15, 1), + ), + ( + ImmBorrowGlobal(StructDefinitionIndex::new(0)), + GasCost::new(23, 1), + ), + ( + ImmBorrowGlobalGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(14, 1), + ), + (Div, GasCost::new(3, 1)), + (Eq, GasCost::new(1, 1)), + (Gt, GasCost::new(1, 1)), + (Pack(StructDefinitionIndex::new(0)), GasCost::new(2, 1)), + ( + PackGeneric(StructDefInstantiationIndex::new(0)), + GasCost::new(2, 1), + ), + (Nop, GasCost::new(1, 1)), + (VecPack(SignatureIndex::new(0), 0), GasCost::new(84, 1)), + (VecLen(SignatureIndex::new(0)), GasCost::new(98, 1)), + (VecImmBorrow(SignatureIndex::new(0)), GasCost::new(1334, 1)), + (VecMutBorrow(SignatureIndex::new(0)), GasCost::new(1902, 1)), + (VecPushBack(SignatureIndex::new(0)), GasCost::new(53, 1)), + (VecPopBack(SignatureIndex::new(0)), GasCost::new(227, 1)), + (VecUnpack(SignatureIndex::new(0), 0), GasCost::new(572, 1)), + (VecSwap(SignatureIndex::new(0)), GasCost::new(1436, 1)), + ]; + // Note that the DiemVM is expecting the table sorted by instruction order. + instrs.sort_by_key(|cost| instruction_key(&cost.0)); + instrs.into_iter().map(|(_, cost)| cost).collect::>() +} + +pub static G_LATEST_INSTRUCTION_TABLE: Lazy> = Lazy::new(instruction_table); + +pub fn latest_cost_table(gas_constants: GasConstants) -> CostTable { + CostTable { + instruction_table: G_LATEST_INSTRUCTION_TABLE.clone(), + native_table: G_LATEST_NATIVE_TABLE.clone(), + gas_constants, + } +} + +pub static G_LATEST_GAS_COST_TABLE: Lazy = + Lazy::new(|| latest_cost_table(G_LATEST_GAS_CONSTANTS.clone())); + +pub struct GasSchedule { + pub entries: Vec<(String, u64)>, +} + +impl GasSchedule { + pub fn to_btree_map(self) -> BTreeMap { + // TODO: what if the gas schedule contains duplicated entries? + self.entries.into_iter().collect() + } + + #[cfg(feature = "print_gas_info")] + pub fn info(&self, message: &str) { + let mut gas_info = String::from("GasSchedule info begin\n"); + gas_info.push_str(&format!("{}\n", message)); + self.entries.iter().for_each(|(key, value)| { + gas_info.push_str(&format!("key = {}, gas value = {}\n", key, value)); + }); + gas_info.push_str("GasSchedule info end\n"); + info!("{}", gas_info); + } + + /// check if there is any one of entry different from the other + /// if it is, return true otherwise false + pub fn is_different(&self, other: &GasSchedule) -> bool { + let diff_len = self.entries.len() != other.entries.len(); + if diff_len { + debug_assert!( + !diff_len, + "self.entries.len() = {} not the same as other.entries.len() = {}", + self.entries.len(), + other.entries.len() + ); + return true; + } + self.entries + .iter() + .enumerate() + .any(|(index, (key, value))| { + let tuple = &other.entries[index]; + let diff = &tuple.0 != key || &tuple.1 != value; + debug_assert!( + !diff, + "self.entries[{}] = {} not the same as other.entries[{}] = {}", + key, value, tuple.0, tuple.1 + ); + diff + }) + } +} + +static G_INSTR_STRS: Lazy> = Lazy::new(|| { + vec![ + "instr.pop", + "instr.ret", + "instr.br_true", + "instr.br_false", + "instr.branch", + "instr.ld_u64", + "instr.ld_const.per_byte", + "instr.ld_true", + "instr.ld_false", + "instr.copy_loc.per_abs_mem_unit", + "instr.move_loc.per_abs_mem_unit", + "instr.st_loc.per_abs_mem_unit", + "instr.mut_borrow_loc", + "instr.imm_borrow_loc", + "instr.mut_borrow_field", + "instr.imm_borrow_field", + "instr.call.per_arg", + "instr.pack.per_abs_mem_unit", + "instr.unpack.per_abs_mem_unit", + "instr.read_ref.per_abs_mem_unit", + "instr.write_ref.per_abs_mem_unit", + "instr.add", + "instr.sub", + "instr.mul", + "instr.mod", + "instr.div", + "instr.bit_or", + "instr.bit_and", + "instr.xor", + "instr.or", + "instr.and", + "instr.not", + "instr.eq.per_abs_mem_unit", + "instr.neq.per_abs_mem_unit", + "instr.lt", + "instr.gt", + "instr.le", + "instr.ge", + "instr.abort", + "instr.nop", + "instr.exists.per_abs_mem_unit", + "instr.mut_borrow_global.per_abs_mem_unit", + "instr.imm_borrow_global.per_abs_mem_unit", + "instr.move_from.per_abs_mem_unit", + "instr.move_to.per_abs_mem_unit", + "instr.freeze_ref", + "instr.shl", + "instr.shr", + "instr.ld_u8", + "instr.ld_u128", + "instr.cast_u8", + "instr.cast_u64", + "instr.cast_u128", + "instr.mut_borrow_field_generic.base", + "instr.imm_borrow_field_generic.base", + "instr.call_generic.per_arg", + "instr.pack_generic.per_abs_mem_unit", + "instr.unpack_generic.per_abs_mem_unit", + "instr.exists_generic.per_abs_mem_unit", + "instr.mut_borrow_global_generic.per_abs_mem_unit", + "instr.imm_borrow_global_generic.per_abs_mem_unit", + "instr.move_from_generic.per_abs_mem_unit", + "instr.move_to_generic.per_abs_mem_unit", + "instr.vec_pack.per_elem", + "instr.vec_len.base", + "instr.vec_imm_borrow.base", + "instr.vec_mut_borrow.base", + "instr.vec_push_back.per_abs_mem_unit", + "instr.vec_pop_back.base", + "instr.vec_unpack.per_expected_elem", + "instr.vec_swap.base", + ] +}); + +// TODO: Place the gas_schedule on the blockchain instead of hardcoding it in the code. +static G_NATIVE_STRS: Lazy> = Lazy::new(|| { + vec![ + "move_stdlib.hash.sha2_256.per_byte", + "move_stdlib.hash.sha3_256.per_byte", + // ED25519_THRESHOLD_VERIFY 3 this native funciton is deprecated, ignore, use "" + "", + "move_stdlib.bcs.to_bytes.per_byte_serialized", + "move_stdlib.vector.length.base", + "move_stdlib.vector.empty.base", + "move_stdlib.vector.borrow.base", + // Vector::borrow_mut is same Vector::borrow ignore "" + "", + "move_stdlib.vector.push_back.legacy_per_abstract_memory_unit", + "move_stdlib.vector.pop_back.base", + "move_stdlib.vector.destroy_empty.base", + "move_stdlib.vector.swap.base", + "move_stdlib.signer.borrow_address.base", + "nursery.event.write_to_event_store.unit_cost", + "move_stdlib.bcs.to_address.per_byte", + "move_stdlib.vector.append.legacy_per_abstract_memory_unit", + "move_stdlib.vector.remove.legacy_per_abstract_memory_unit", + "move_stdlib.vector.reverse.legacy_per_abstract_memory_unit", + "table.new_table_handle.base", + "table.add_box.per_byte_serialized", + "table.borrow_box.per_byte_serialized", + "table.remove_box.per_byte_serialized", + "table.contains_box.per_byte_serialized", + "table.destroy_empty_box.base", + "table.drop_unchecked_box.base", + "move_stdlib.string.check_utf8.per_byte", + "move_stdlib.string.sub_string.per_byte", + "move_stdlib.string.is_char_boundary.base", + "move_stdlib.string.index_of.per_byte_searched", + "move_stdlib.vector.spawn_from.legacy_per_abstract_memory_unit", + ] +}); + +impl From<&CostTable> for GasSchedule { + fn from(cost_table: &CostTable) -> Self { + let mut entries = vec![]; + + let instrs = cost_table.instruction_table.clone(); + for (idx, cost) in instrs.into_iter().enumerate() { + entries.push((G_INSTR_STRS[idx].to_string(), cost.total())); + } + entries.push(("instr.ld_u16".to_string(), 3)); + entries.push(("instr.ld_u32".to_string(), 2)); + entries.push(("instr.ld_u256".to_string(), 3)); + entries.push(("instr.cast_u16".to_string(), 3)); + entries.push(("instr.cast_u32".to_string(), 2)); + entries.push(("instr.cast_u256".to_string(), 3)); + + let natives = cost_table.native_table.clone(); + for (idx, cost) in natives.into_iter().enumerate() { + if G_NATIVE_STRS[idx].is_empty() { + continue; + } + let (a, b) = (G_NATIVE_STRS[idx].to_string(), cost.total()); + println!("idx {:}, native name {:?}, cost {:?}", idx, a, b); + entries.push((G_NATIVE_STRS[idx].to_string(), cost.total())); + } + + // native_table don't have these + entries.push(("nursery.debug.print.base_cost".to_string(), 1)); + entries.push(("nursery.debug.print_stack_trace.base_cost".to_string(), 1)); + + entries.push(( + "move_stdlib.hash.sha2_256.legacy_min_input_len".to_string(), + 1, + )); + entries.push(( + "move_stdlib.hash.sha3_256.legacy_min_input_len".to_string(), + 1, + )); + entries.push(("move_stdlib.bcs.to_bytes.failure".to_string(), 182)); + entries.push(( + "move_stdlib.bcs.to_bytes.legacy_min_output_size".to_string(), + 1, + )); + + Self { entries } + } +} + +pub fn get_global_gas_schedule() -> GasSchedule { + GasSchedule::from(&G_LATEST_GAS_COST_TABLE.clone()) +}