Skip to content

Commit

Permalink
refactor: move location of libplanet library
Browse files Browse the repository at this point in the history
  • Loading branch information
sircoon4 committed Jul 18, 2024
1 parent 4a64d62 commit c546815
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
60 changes: 31 additions & 29 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/vm/libplanet"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/blake2b"
"github.com/ethereum/go-ethereum/crypto/bls12381"
"github.com/ethereum/go-ethereum/crypto/bn256"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/crypto/secp256r1"
"github.com/ethereum/go-ethereum/libplanet"
"github.com/ethereum/go-ethereum/params"
"golang.org/x/crypto/ripemd160"
)
Expand Down Expand Up @@ -203,34 +203,6 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uin
return output, suppliedGas, err
}

type libplanetVerifyProof struct{}

func (c *libplanetVerifyProof) RequiredGas(input []byte) uint64 {
return uint64(3000)
}

func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) {
proofMap := map[string]any{
"stateRootHash": nil, // sha256(bencoded) []byte
"proof": nil, // bencoded list [][]byte
"key": nil, // keyBytes []byte
"value": nil, // bencoded []byte
}
proofMap, err := libplanet.ParseMerkleTrieProofInput(input)
if err != nil {
return nil, err
}

stateRootHash := proofMap["stateRootHash"].([]byte)
proof := proofMap["proof"].([][]byte)
key := proofMap["key"].([]byte)
value := proofMap["value"].([]byte)

valid, _ := libplanet.ValidateProof(stateRootHash, proof, key, value)

return common.CopyBytes(libplanet.BoolAbi(valid)), nil
}

// ECRECOVER implemented as a native contract.
type ecrecover struct{}

Expand Down Expand Up @@ -1221,3 +1193,33 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) {
return nil, nil
}
}

// LibplanetVerifyProof implemented for verifying merkle trie proof
// from blockchain networks built by Libplanet.
type libplanetVerifyProof struct{}

func (c *libplanetVerifyProof) RequiredGas(input []byte) uint64 {
return params.LibplanetVerifyProofGas
}

func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) {
proofMap := map[string]any{
"stateRootHash": nil, // sha256(bencoded) []byte
"proof": nil, // bencoded list [][]byte
"key": nil, // keyBytes []byte
"value": nil, // bencoded []byte
}
proofMap, err := libplanet.ParseMerkleTrieProofInput(input)
if err != nil {
return nil, err
}

stateRootHash := proofMap["stateRootHash"].([]byte)
proof := proofMap["proof"].([][]byte)
key := proofMap["key"].([]byte)
value := proofMap["value"].([]byte)

valid, _ := libplanet.ValidateProof(stateRootHash, proof, key, value)

return common.CopyBytes(libplanet.BoolAbi(valid)), nil
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ const (
Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation

P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price
P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price
LibplanetVerifyProofGas uint64 = 3000 // Libplanet proof verifier gas price

// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
Expand Down

0 comments on commit c546815

Please sign in to comment.