From e2c04d02049aae9e392556c737f962517cd02f8f Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Sun, 18 Feb 2024 19:43:41 +0000 Subject: [PATCH] Add kettle address to context --- core/types/suave_structs.go | 2 +- core/vm/contracts_suave.go | 10 +++- core/vm/contracts_suave_runtime_adapter.go | 47 ++++++++++++++++++- .../contracts_suave_runtime_adapter_test.go | 4 ++ core/vm/suave.go | 12 ++--- eth/api_backend.go | 7 ++- suave/artifacts/SuaveLib.json | 2 +- suave/artifacts/addresses.go | 6 ++- suave/gen/suave_spec.yaml | 16 ++++++- suave/sol/libraries/Suave.sol | 11 +++++ 10 files changed, 101 insertions(+), 16 deletions(-) diff --git a/core/types/suave_structs.go b/core/types/suave_structs.go index c5cf6fd0b..d1b660197 100755 --- a/core/types/suave_structs.go +++ b/core/types/suave_structs.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 4be6ae397b6e4062135b64450a7672345194a6ecb313af9f4ca418ff7ee17739 +// Hash: 2c490d7558a6560e2fbfd09d32a514f0c22e5a99b034c373899d114c6e49c663 package types import "github.com/ethereum/go-ethereum/common" diff --git a/core/vm/contracts_suave.go b/core/vm/contracts_suave.go index 8bad3c6cb..f09fe63a0 100644 --- a/core/vm/contracts_suave.go +++ b/core/vm/contracts_suave.go @@ -34,7 +34,7 @@ var ( /* General utility precompiles */ func (b *suaveRuntime) confidentialInputs() ([]byte, error) { - return b.suaveContext.ConfidentialInputs, nil + return b.contextGet("confidentialInputs") } /* Confidential store precompiles */ @@ -270,3 +270,11 @@ func (s *suaveRuntime) simulateTransaction(session string, txnBytes []byte) (typ } return *result, nil } + +func (s *suaveRuntime) contextGet(key string) ([]byte, error) { + val, ok := s.suaveContext.Context[key] + if !ok { + return nil, fmt.Errorf("value not found") + } + return val, nil +} diff --git a/core/vm/contracts_suave_runtime_adapter.go b/core/vm/contracts_suave_runtime_adapter.go index 007928da0..317d75f08 100644 --- a/core/vm/contracts_suave_runtime_adapter.go +++ b/core/vm/contracts_suave_runtime_adapter.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 4be6ae397b6e4062135b64450a7672345194a6ecb313af9f4ca418ff7ee17739 +// Hash: 2c490d7558a6560e2fbfd09d32a514f0c22e5a99b034c373899d114c6e49c663 package vm import ( @@ -21,6 +21,7 @@ type SuaveRuntime interface { confidentialInputs() ([]byte, error) confidentialRetrieve(dataId types.DataId, key string) ([]byte, error) confidentialStore(dataId types.DataId, key string, value []byte) error + contextGet(key string) ([]byte, error) doHTTPRequest(request types.HttpRequest) ([]byte, error) ethcall(contractAddr common.Address, input1 []byte) ([]byte, error) extractHint(bundleData []byte) ([]byte, error) @@ -42,6 +43,7 @@ var ( confidentialInputsAddr = common.HexToAddress("0x0000000000000000000000000000000042010001") confidentialRetrieveAddr = common.HexToAddress("0x0000000000000000000000000000000042020001") confidentialStoreAddr = common.HexToAddress("0x0000000000000000000000000000000042020000") + contextGetAddr = common.HexToAddress("0x0000000000000000000000000000000053300003") doHTTPRequestAddr = common.HexToAddress("0x0000000000000000000000000000000043200002") ethcallAddr = common.HexToAddress("0x0000000000000000000000000000000042100003") extractHintAddr = common.HexToAddress("0x0000000000000000000000000000000042100037") @@ -59,7 +61,7 @@ var ( ) var addrList = []common.Address{ - buildEthBlockAddr, confidentialInputsAddr, confidentialRetrieveAddr, confidentialStoreAddr, doHTTPRequestAddr, ethcallAddr, extractHintAddr, fetchDataRecordsAddr, fillMevShareBundleAddr, newBuilderAddr, newDataRecordAddr, privateKeyGenAddr, signEthTransactionAddr, signMessageAddr, simulateBundleAddr, simulateTransactionAddr, submitBundleJsonRPCAddr, submitEthBlockToRelayAddr, + buildEthBlockAddr, confidentialInputsAddr, confidentialRetrieveAddr, confidentialStoreAddr, contextGetAddr, doHTTPRequestAddr, ethcallAddr, extractHintAddr, fetchDataRecordsAddr, fillMevShareBundleAddr, newBuilderAddr, newDataRecordAddr, privateKeyGenAddr, signEthTransactionAddr, signMessageAddr, simulateBundleAddr, simulateTransactionAddr, submitBundleJsonRPCAddr, submitEthBlockToRelayAddr, } type SuaveRuntimeAdapter struct { @@ -80,6 +82,9 @@ func (b *SuaveRuntimeAdapter) run(addr common.Address, input []byte) ([]byte, er case confidentialStoreAddr: return b.confidentialStore(input) + case contextGetAddr: + return b.contextGet(input) + case doHTTPRequestAddr: return b.doHTTPRequest(input) @@ -287,6 +292,44 @@ func (b *SuaveRuntimeAdapter) confidentialStore(input []byte) (res []byte, err e } +func (b *SuaveRuntimeAdapter) contextGet(input []byte) (res []byte, err error) { + var ( + unpacked []interface{} + result []byte + ) + + _ = unpacked + _ = result + + unpacked, err = artifacts.SuaveAbi.Methods["contextGet"].Inputs.Unpack(input) + if err != nil { + err = errFailedToUnpackInput + return + } + + var ( + key string + ) + + key = unpacked[0].(string) + + var ( + value []byte + ) + + if value, err = b.impl.contextGet(key); err != nil { + return + } + + result, err = artifacts.SuaveAbi.Methods["contextGet"].Outputs.Pack(value) + if err != nil { + err = errFailedToPackOutput + return + } + return result, nil + +} + func (b *SuaveRuntimeAdapter) doHTTPRequest(input []byte) (res []byte, err error) { var ( unpacked []interface{} diff --git a/core/vm/contracts_suave_runtime_adapter_test.go b/core/vm/contracts_suave_runtime_adapter_test.go index e8d7b06d2..6da37f165 100644 --- a/core/vm/contracts_suave_runtime_adapter_test.go +++ b/core/vm/contracts_suave_runtime_adapter_test.go @@ -87,6 +87,10 @@ func (m *mockRuntime) privateKeyGen() (string, error) { return "", nil } +func (m *mockRuntime) contextGet(key string) ([]byte, error) { + return nil, nil +} + func TestRuntimeAdapter(t *testing.T) { adapter := &SuaveRuntimeAdapter{ impl: &mockRuntime{}, diff --git a/core/vm/suave.go b/core/vm/suave.go index 1ab5a224d..48987b5b5 100644 --- a/core/vm/suave.go +++ b/core/vm/suave.go @@ -27,9 +27,9 @@ type ConfidentialStore interface { type SuaveContext struct { // TODO: MEVM access to Backend should be restricted to only the necessary functions! - Backend *SuaveExecutionBackend - ConfidentialInputs []byte - CallerStack []*common.Address + Backend *SuaveExecutionBackend + Context map[string][]byte + CallerStack []*common.Address } type SuaveExecutionBackend struct { @@ -46,9 +46,9 @@ func NewRuntimeSuaveContext(evm *EVM, caller common.Address) *SuaveContext { } return &SuaveContext{ - Backend: evm.SuaveContext.Backend, - ConfidentialInputs: evm.SuaveContext.ConfidentialInputs, - CallerStack: append(evm.SuaveContext.CallerStack, &caller), + Backend: evm.SuaveContext.Backend, + Context: evm.SuaveContext.Context, + CallerStack: append(evm.SuaveContext.CallerStack, &caller), } } diff --git a/eth/api_backend.go b/eth/api_backend.go index d91caca2f..5325fc730 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -436,8 +436,11 @@ func (b *EthAPIBackend) StartMining() error { func (b *EthAPIBackend) SuaveContext(requestTx *types.Transaction, ccr *types.ConfidentialComputeRequest) vm.SuaveContext { storeTransaction := b.suaveEngine.NewTransactionalStore(requestTx) return vm.SuaveContext{ - ConfidentialInputs: ccr.ConfidentialInputs, - CallerStack: []*common.Address{}, + Context: map[string][]byte{ + "confidentialInputs": ccr.ConfidentialInputs, + "kettleAddress": ccr.KettleAddress.Bytes(), + }, + CallerStack: []*common.Address{}, Backend: &vm.SuaveExecutionBackend{ EthBundleSigningKey: b.suaveEthBundleSigningKey, EthBlockSigningKey: b.suaveEthBlockSigningKey, diff --git a/suave/artifacts/SuaveLib.json b/suave/artifacts/SuaveLib.json index aadd6e248..42aaac4b3 100644 --- a/suave/artifacts/SuaveLib.json +++ b/suave/artifacts/SuaveLib.json @@ -1 +1 @@ -[{"type":"error","name":"PeekerReverted","inputs":[{"name":"addr","type":"address"},{"name":"err","type":"bytes"}]},{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]},{"name":"extra","type":"bytes","internalType":"bytes"},{"name":"beaconRoot","type":"bytes32","internalType":"bytes32"},{"name":"fillPending","type":"bool","internalType":"bool"}]},{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"},{"name":"executionPayload","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"confindentialData","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialRetrieve","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStore","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"},{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"doHTTPRequest","inputs":[{"name":"request","type":"tuple","internalType":"struct Suave.HttpRequest","components":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"headers","type":"string[]","internalType":"string[]"},{"name":"body","type":"bytes","internalType":"bytes"},{"name":"withFlashbotsSignature","type":"bool","internalType":"bool"}]}],"outputs":[{"name":"httpResponse","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"callOutput","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"hints","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchDataRecords","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecords","type":"tuple[]","internalType":"struct Suave.DataRecord[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBuilder","outputs":[{"name":"sessionid","type":"string","internalType":"string"}]},{"type":"function","name":"newDataRecord","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"dataType","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecord","type":"tuple","internalType":"struct Suave.DataRecord","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"privateKeyGen","outputs":[{"name":"privateKey","type":"string","internalType":"string"}]},{"type":"function","name":"signEthTransaction","inputs":[{"name":"txn","type":"bytes","internalType":"bytes"},{"name":"chainId","type":"string","internalType":"string"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signedTxn","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"signMessage","inputs":[{"name":"digest","type":"bytes","internalType":"bytes"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signature","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"effectiveGasPrice","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"simulateTransaction","inputs":[{"name":"sessionid","type":"string","internalType":"string"},{"name":"txn","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"simulationResult","type":"tuple","internalType":"struct Suave.SimulateTransactionResult","components":[{"name":"egp","type":"uint64","internalType":"uint64"},{"name":"logs","type":"tuple[]","internalType":"struct Suave.SimulatedLog[]","components":[{"name":"data","type":"bytes","internalType":"bytes"},{"name":"addr","type":"address","internalType":"address"},{"name":"topics","type":"bytes32[]","internalType":"bytes32[]"}]},{"name":"success","type":"bool","internalType":"bool"},{"name":"error","type":"string","internalType":"string"}]}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"errorMessage","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file +[{"type":"error","name":"PeekerReverted","inputs":[{"name":"addr","type":"address"},{"name":"err","type":"bytes"}]},{"type":"function","name":"buildEthBlock","inputs":[{"name":"blockArgs","type":"tuple","internalType":"struct Suave.BuildBlockArgs","components":[{"name":"slot","type":"uint64","internalType":"uint64"},{"name":"proposerPubkey","type":"bytes","internalType":"bytes"},{"name":"parent","type":"bytes32","internalType":"bytes32"},{"name":"timestamp","type":"uint64","internalType":"uint64"},{"name":"feeRecipient","type":"address","internalType":"address"},{"name":"gasLimit","type":"uint64","internalType":"uint64"},{"name":"random","type":"bytes32","internalType":"bytes32"},{"name":"withdrawals","type":"tuple[]","internalType":"struct Suave.Withdrawal[]","components":[{"name":"index","type":"uint64","internalType":"uint64"},{"name":"validator","type":"uint64","internalType":"uint64"},{"name":"Address","type":"address","internalType":"address"},{"name":"amount","type":"uint64","internalType":"uint64"}]},{"name":"extra","type":"bytes","internalType":"bytes"},{"name":"beaconRoot","type":"bytes32","internalType":"bytes32"},{"name":"fillPending","type":"bool","internalType":"bool"}]},{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"},{"name":"executionPayload","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialInputs","outputs":[{"name":"confindentialData","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialRetrieve","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"confidentialStore","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"key","type":"string","internalType":"string"},{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"contextGet","inputs":[{"name":"key","type":"string","internalType":"string"}],"outputs":[{"name":"value","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"doHTTPRequest","inputs":[{"name":"request","type":"tuple","internalType":"struct Suave.HttpRequest","components":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"headers","type":"string[]","internalType":"string[]"},{"name":"body","type":"bytes","internalType":"bytes"},{"name":"withFlashbotsSignature","type":"bool","internalType":"bool"}]}],"outputs":[{"name":"httpResponse","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"ethcall","inputs":[{"name":"contractAddr","type":"address","internalType":"address"},{"name":"input1","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"callOutput","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"extractHint","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"hints","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"fetchDataRecords","inputs":[{"name":"cond","type":"uint64","internalType":"uint64"},{"name":"namespace","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecords","type":"tuple[]","internalType":"struct Suave.DataRecord[]","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"fillMevShareBundle","inputs":[{"name":"dataId","type":"bytes16","internalType":"struct Suave.DataId"}],"outputs":[{"name":"encodedBundle","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"newBuilder","outputs":[{"name":"sessionid","type":"string","internalType":"string"}]},{"type":"function","name":"newDataRecord","inputs":[{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"dataType","type":"string","internalType":"string"}],"outputs":[{"name":"dataRecord","type":"tuple","internalType":"struct Suave.DataRecord","components":[{"name":"id","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"salt","type":"bytes16","internalType":"struct Suave.DataId"},{"name":"decryptionCondition","type":"uint64","internalType":"uint64"},{"name":"allowedPeekers","type":"address[]","internalType":"address[]"},{"name":"allowedStores","type":"address[]","internalType":"address[]"},{"name":"version","type":"string","internalType":"string"}]}]},{"type":"function","name":"privateKeyGen","outputs":[{"name":"privateKey","type":"string","internalType":"string"}]},{"type":"function","name":"signEthTransaction","inputs":[{"name":"txn","type":"bytes","internalType":"bytes"},{"name":"chainId","type":"string","internalType":"string"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signedTxn","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"signMessage","inputs":[{"name":"digest","type":"bytes","internalType":"bytes"},{"name":"signingKey","type":"string","internalType":"string"}],"outputs":[{"name":"signature","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"simulateBundle","inputs":[{"name":"bundleData","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"effectiveGasPrice","type":"uint64","internalType":"uint64"}]},{"type":"function","name":"simulateTransaction","inputs":[{"name":"sessionid","type":"string","internalType":"string"},{"name":"txn","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"simulationResult","type":"tuple","internalType":"struct Suave.SimulateTransactionResult","components":[{"name":"egp","type":"uint64","internalType":"uint64"},{"name":"logs","type":"tuple[]","internalType":"struct Suave.SimulatedLog[]","components":[{"name":"data","type":"bytes","internalType":"bytes"},{"name":"addr","type":"address","internalType":"address"},{"name":"topics","type":"bytes32[]","internalType":"bytes32[]"}]},{"name":"success","type":"bool","internalType":"bool"},{"name":"error","type":"string","internalType":"string"}]}]},{"type":"function","name":"submitBundleJsonRPC","inputs":[{"name":"url","type":"string","internalType":"string"},{"name":"method","type":"string","internalType":"string"},{"name":"params","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"errorMessage","type":"bytes","internalType":"bytes"}]},{"type":"function","name":"submitEthBlockToRelay","inputs":[{"name":"relayUrl","type":"string","internalType":"string"},{"name":"builderBid","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"blockBid","type":"bytes","internalType":"bytes"}]}] \ No newline at end of file diff --git a/suave/artifacts/addresses.go b/suave/artifacts/addresses.go index c72bd4de5..961468abe 100644 --- a/suave/artifacts/addresses.go +++ b/suave/artifacts/addresses.go @@ -1,5 +1,5 @@ // Code generated by suave/gen. DO NOT EDIT. -// Hash: 4be6ae397b6e4062135b64450a7672345194a6ecb313af9f4ca418ff7ee17739 +// Hash: 2c490d7558a6560e2fbfd09d32a514f0c22e5a99b034c373899d114c6e49c663 package artifacts import ( @@ -12,6 +12,7 @@ var ( confidentialInputsAddr = common.HexToAddress("0x0000000000000000000000000000000042010001") confidentialRetrieveAddr = common.HexToAddress("0x0000000000000000000000000000000042020001") confidentialStoreAddr = common.HexToAddress("0x0000000000000000000000000000000042020000") + contextGetAddr = common.HexToAddress("0x0000000000000000000000000000000053300003") doHTTPRequestAddr = common.HexToAddress("0x0000000000000000000000000000000043200002") ethcallAddr = common.HexToAddress("0x0000000000000000000000000000000042100003") extractHintAddr = common.HexToAddress("0x0000000000000000000000000000000042100037") @@ -33,6 +34,7 @@ var SuaveMethods = map[string]common.Address{ "confidentialInputs": confidentialInputsAddr, "confidentialRetrieve": confidentialRetrieveAddr, "confidentialStore": confidentialStoreAddr, + "contextGet": contextGetAddr, "doHTTPRequest": doHTTPRequestAddr, "ethcall": ethcallAddr, "extractHint": extractHintAddr, @@ -59,6 +61,8 @@ func PrecompileAddressToName(addr common.Address) string { return "confidentialRetrieve" case confidentialStoreAddr: return "confidentialStore" + case contextGetAddr: + return "contextGet" case doHTTPRequestAddr: return "doHTTPRequest" case ethcallAddr: diff --git a/suave/gen/suave_spec.yaml b/suave/gen/suave_spec.yaml index a9deb74ad..506fc48ed 100644 --- a/suave/gen/suave_spec.yaml +++ b/suave/gen/suave_spec.yaml @@ -338,10 +338,22 @@ functions: type: SimulateTransactionResult description: "Result of the simulation" - name: privateKeyGen - address: '0x0000000000000000000000000000000053200003' + address: "0x0000000000000000000000000000000053200003" description: "Generates a private key in ECDA secp256k1 format" output: fields: - name: privateKey type: string - description: "Hex encoded string of the ECDSA private key. Exactly as a signMessage precompile wants." \ No newline at end of file + description: "Hex encoded string of the ECDSA private key. Exactly as a signMessage precompile wants." + - name: contextGet + address: "0x0000000000000000000000000000000053300003" + description: "Retrieves a value from the context" + input: + - name: key + type: string + description: "Key of the value to retrieve" + output: + fields: + - name: value + type: bytes + description: "Value of the key" diff --git a/suave/sol/libraries/Suave.sol b/suave/sol/libraries/Suave.sol index 7a4551b00..08c7ee51d 100644 --- a/suave/sol/libraries/Suave.sol +++ b/suave/sol/libraries/Suave.sol @@ -69,6 +69,8 @@ library Suave { address public constant CONFIDENTIAL_STORE = 0x0000000000000000000000000000000042020000; + address public constant CONTEXT_GET = 0x0000000000000000000000000000000053300003; + address public constant DO_HTTPREQUEST = 0x0000000000000000000000000000000043200002; address public constant ETHCALL = 0x0000000000000000000000000000000042100003; @@ -148,6 +150,15 @@ library Suave { } } + function contextGet(string memory key) internal returns (bytes memory) { + (bool success, bytes memory data) = CONTEXT_GET.call(abi.encode(key)); + if (!success) { + revert PeekerReverted(CONTEXT_GET, data); + } + + return abi.decode(data, (bytes)); + } + function doHTTPRequest(HttpRequest memory request) internal returns (bytes memory) { (bool success, bytes memory data) = DO_HTTPREQUEST.call(abi.encode(request)); if (!success) {